MessageHandler.c 761 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919
  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. int syncDateTimeRTC(uint8_t *data)
  633. {
  634. struct ParsingResult
  635. {
  636. int result;
  637. int scanedElement;
  638. int year;
  639. int month;
  640. int mday;
  641. int hour;
  642. int min;
  643. int sec;
  644. int tz_hour;
  645. int tz_min;
  646. float minSec;
  647. }result;
  648. struct tm tmOrg;
  649. struct tm *tmTarget;
  650. struct timeb tbTarget;
  651. char buf[128];
  652. memset(&result, 0x00, sizeof(struct ParsingResult));
  653. result.result = PASS;
  654. if(strstr((char*)data, ".") != NULL)
  655. {
  656. // Original data with mini second
  657. if(strstr((char*)data, "Z") != NULL)
  658. {
  659. // Original data with Z
  660. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  661. &result.year,
  662. &result.month,
  663. &result.mday,
  664. &result.hour,
  665. &result.min,
  666. &result.sec,
  667. &result.minSec);
  668. }
  669. else
  670. {
  671. // Original data without Z
  672. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  673. &result.year,
  674. &result.month,
  675. &result.mday,
  676. &result.hour,
  677. &result.min,
  678. &result.sec,
  679. &result.minSec,
  680. &result.tz_hour,
  681. &result.tz_min);
  682. }
  683. }
  684. else
  685. {
  686. // Original data without mini second
  687. if(strstr((char*)data, "Z") != NULL)
  688. {
  689. // Original data with Z
  690. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  691. &result.year,
  692. &result.month,
  693. &result.mday,
  694. &result.hour,
  695. &result.min,
  696. &result.sec);
  697. }
  698. else
  699. {
  700. // Original data without Z
  701. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  702. &result.year,
  703. &result.month,
  704. &result.mday,
  705. &result.hour,
  706. &result.min,
  707. &result.sec,
  708. &result.tz_hour,
  709. &result.tz_min);
  710. }
  711. }
  712. tmOrg.tm_year = result.year - 1900;
  713. tmOrg.tm_mon = result.month - 1;
  714. tmOrg.tm_mday = result.mday;
  715. tmOrg.tm_hour = result.hour;
  716. tmOrg.tm_min = result.min;
  717. tmOrg.tm_sec = result.sec;
  718. tmOrg.tm_gmtoff = 0;
  719. tbTarget.time = mktime(&tmOrg);
  720. tbTarget.timezone = 0;
  721. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  722. tmTarget = gmtime(&tbTarget.time);
  723. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  724. //DEBUG_INFO(" org date time: %s\n", data);
  725. //DEBUG_INFO("parse date time: %s\n", buf);
  726. system(buf);
  727. system("/sbin/hwclock -w --systohc");
  728. if(result.scanedElement < 6)
  729. result.result = FAIL;
  730. return result.result;
  731. }
  732. //==========================================
  733. // GetCompositeSchedule logic related function
  734. //==========================================
  735. int DiffTimebSec(struct timeb ST, struct timeb ET)
  736. {
  737. //return milli-second
  738. unsigned int StartTime,StopTime;
  739. StartTime=(unsigned int)ST.time;
  740. StopTime=(unsigned int)ET.time;
  741. return (StopTime-StartTime);
  742. }
  743. int DiffTimebWithNowSec(struct timeb ST)
  744. {
  745. //return milli-second
  746. struct timeb ET;
  747. unsigned int StartTime,StopTime;
  748. ftime(&ET);
  749. StartTime=(unsigned int)ST.time;
  750. StopTime=(unsigned int)ET.time;
  751. return (StopTime-StartTime);
  752. }
  753. int getStartStop(uint8_t *start, uint8_t *stop)
  754. {
  755. int result = -1;
  756. struct tm tmStart;
  757. struct timeb tbStart;
  758. struct tm tmStop;
  759. struct timeb tbStop;
  760. 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) &&
  761. (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))
  762. {
  763. //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);
  764. //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);
  765. tmStart.tm_year -= 1900;
  766. tmStart.tm_mon -= 1;
  767. tbStart.time = mktime(&tmStart);
  768. tbStart.millitm = 0;
  769. tmStop.tm_year -= 1900;
  770. tmStop.tm_mon -= 1;
  771. tbStop.time = mktime(&tmStop);
  772. tbStop.millitm = 0;
  773. result = DiffTimebSec(tbStart, tbStop);
  774. //DEBUG_INFO("getStartStop(): %d\n", result);
  775. }
  776. else
  777. {
  778. DEBUG_WARN("Start or stop date parsing error.\r\n");
  779. }
  780. return result;
  781. }
  782. int isOvertNow(uint8_t *start)
  783. {
  784. int result = NO;
  785. struct tm tmStart;
  786. struct timeb tbStart;
  787. 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))
  788. {
  789. //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);
  790. tmStart.tm_year -= 1900;
  791. tmStart.tm_mon -= 1;
  792. tbStart.time = mktime(&tmStart);
  793. tbStart.millitm = 0;
  794. if(DiffTimebWithNowSec(tbStart) <= 0)
  795. result = NO;
  796. else
  797. result = YES;
  798. }
  799. else
  800. {
  801. DEBUG_WARN("Start date parsing error.\n");
  802. }
  803. return result;
  804. }
  805. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  806. {
  807. int result = -1;
  808. struct tm tmStart;
  809. struct timeb tbStart;
  810. struct tm tmStop;
  811. struct timeb tbStop;
  812. 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) &&
  813. (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))
  814. {
  815. tmStart.tm_year -= 1900;
  816. tmStart.tm_mon -= 1;
  817. tbStart.time = mktime(&tmStart);
  818. tbStart.millitm = 0;
  819. tmStop.tm_year -= 1900;
  820. tmStop.tm_mon -= 1;
  821. tbStop.time = mktime(&tmStop);
  822. tbStop.millitm = 0;
  823. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  824. }
  825. return result;
  826. }
  827. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  828. {
  829. FILE *fp;
  830. char profileFileName[128];
  831. char *line = NULL;
  832. size_t len = 0;
  833. time_t CurrentTime;
  834. struct tm *tmComposite;
  835. struct StructChargingProfile maxProfile;
  836. struct StructChargingProfile defaultTxProfile;
  837. struct StructChargingProfile txProfile;
  838. struct StructChargingSchedulePeriod tmpPeriod;
  839. uint8_t limitMax=0;
  840. uint8_t limitDef=0;
  841. uint8_t limitTx=0;
  842. int compositePeriodIdx = 0;
  843. CurrentTime = time(NULL);
  844. tmComposite=localtime(&CurrentTime);
  845. 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);
  846. if(isUnitA)
  847. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  848. else
  849. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  850. compositeProfile->ChargingSchedule.Duration = durationReq;
  851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  852. {
  853. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  854. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  855. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  856. }
  857. compositeProfile->ChargingProfileId = 0;
  858. compositeProfile->StackLevel = 99 ;
  859. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  860. maxProfile.ChargingProfileId = -1;
  861. defaultTxProfile.ChargingProfileId = -1;
  862. txProfile.ChargingProfileId = -1;
  863. maxProfile.ChargingSchedule.Duration = -1;
  864. defaultTxProfile.ChargingSchedule.Duration = -1;
  865. txProfile.ChargingSchedule.Duration = -1;
  866. system("yes|rm /tmp/*.json");
  867. system("cp /Storage/OCPP/*.json /tmp");
  868. /*
  869. * Search valid charging profile
  870. */
  871. //DEBUG_INFO("====================================\n");
  872. // Search tx profile
  873. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  874. if((access(profileFileName, F_OK))!=-1)
  875. {
  876. fp = fopen(profileFileName, "r");
  877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  878. {
  879. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  880. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  881. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  882. }
  883. txProfile.ChargingProfileId = -1;
  884. txProfile.StackLevel = -1;
  885. while(getline(&line, &len, fp) != -1)
  886. {
  887. json_object *obj = NULL;
  888. obj = json_tokener_parse(line);
  889. if(is_error(obj))
  890. {
  891. DEBUG_ERROR("Parse txProfile from file error.\n");
  892. }
  893. else
  894. {
  895. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  896. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  897. )
  898. {
  899. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  900. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  901. )
  902. {
  903. struct tm tmFrom, tmTo;
  904. struct timeb tbFrom, tbTo;
  905. 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) &&
  906. (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))
  907. {
  908. tmFrom.tm_year -= 1900;
  909. tmFrom.tm_mon -= 1;
  910. tbFrom.time = mktime(&tmFrom);
  911. tmTo.tm_year -= 1900;
  912. tmTo.tm_mon -= 1;
  913. tbTo.time = mktime(&tmTo);
  914. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  915. {
  916. if(txProfile.ChargingProfileId == -1)
  917. DEBUG_INFO("TxProfile found.\n");
  918. else
  919. DEBUG_INFO("TxProfile updated.\n");
  920. // Required item
  921. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  922. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  923. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  924. if(isUnitA)
  925. {
  926. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  927. 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++)
  928. {
  929. 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"));
  930. 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?
  931. 3:
  932. 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")));
  933. 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")));
  934. }
  935. }
  936. else
  937. {
  938. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  939. 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++)
  940. {
  941. 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"));
  942. 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?
  943. 3:
  944. 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")));
  945. 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));
  946. }
  947. }
  948. // Optional item
  949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  950. {
  951. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  952. }
  953. else
  954. {
  955. sprintf((char*)txProfile.ValidFrom, " ");
  956. }
  957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  958. {
  959. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  960. }
  961. else
  962. {
  963. sprintf((char*)txProfile.ValidTo, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  966. {
  967. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  968. }
  969. else
  970. {
  971. sprintf((char*)txProfile.RecurrencyKind, " ");
  972. }
  973. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  974. {
  975. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  976. }
  977. else
  978. {
  979. txProfile.TransactionId = -1;
  980. }
  981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  982. {
  983. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  984. }
  985. else
  986. {
  987. txProfile.ChargingSchedule.Duration = 86400;
  988. }
  989. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  990. {
  991. 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")));
  992. }
  993. else
  994. {
  995. 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));
  996. }
  997. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  998. {
  999. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1000. }
  1001. else
  1002. {
  1003. txProfile.ChargingSchedule.MinChargingRate = -1;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. else
  1009. {
  1010. if(txProfile.ChargingProfileId == -1)
  1011. DEBUG_INFO("TxProfile found.\n");
  1012. else
  1013. DEBUG_INFO("TxProfile updated.\n");
  1014. // Required item
  1015. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1016. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1017. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1018. if(isUnitA)
  1019. {
  1020. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1021. 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++)
  1022. {
  1023. 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"));
  1024. 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?
  1025. 3:
  1026. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1027. 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")));
  1028. }
  1029. }
  1030. else
  1031. {
  1032. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1033. 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++)
  1034. {
  1035. 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"));
  1036. 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?
  1037. 3:
  1038. 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")));
  1039. 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));
  1040. }
  1041. }
  1042. // Optional item
  1043. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1044. {
  1045. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1046. }
  1047. else
  1048. {
  1049. sprintf((char*)txProfile.ValidFrom, " ");
  1050. }
  1051. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1052. {
  1053. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1054. }
  1055. else
  1056. {
  1057. sprintf((char*)txProfile.ValidTo, " ");
  1058. }
  1059. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1060. {
  1061. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1062. }
  1063. else
  1064. {
  1065. sprintf((char*)txProfile.RecurrencyKind, " ");
  1066. }
  1067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1068. {
  1069. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1070. }
  1071. else
  1072. {
  1073. txProfile.TransactionId = -1;
  1074. }
  1075. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1076. {
  1077. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1078. }
  1079. else
  1080. {
  1081. txProfile.ChargingSchedule.Duration = 86400;
  1082. }
  1083. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1084. {
  1085. 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")));
  1086. }
  1087. else
  1088. {
  1089. 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));
  1090. }
  1091. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1092. {
  1093. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1094. }
  1095. else
  1096. {
  1097. txProfile.ChargingSchedule.MinChargingRate = -1;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. json_object_put(obj);
  1103. }
  1104. fclose(fp);
  1105. /*
  1106. if(txProfile.ChargingProfileId != -1)
  1107. {
  1108. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1109. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1110. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1111. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1112. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1113. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1114. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1115. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1116. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1117. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1118. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1119. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1120. {
  1121. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1122. {
  1123. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1124. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1125. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1126. }
  1127. }
  1128. }
  1129. else
  1130. DEBUG_INFO("TxProfile not found.\n");*/
  1131. }
  1132. // Search default tx profile
  1133. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1134. if((access(profileFileName, F_OK))==-1)
  1135. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1136. if((access(profileFileName, F_OK))!=-1)
  1137. {
  1138. fp = fopen(profileFileName, "r");
  1139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1140. {
  1141. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1142. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1143. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1144. }
  1145. defaultTxProfile.ChargingProfileId = -1;
  1146. defaultTxProfile.StackLevel = -1;
  1147. while(getline(&line, &len, fp) != -1)
  1148. {
  1149. json_object *obj = NULL;
  1150. obj = json_tokener_parse(line);
  1151. if(is_error(obj))
  1152. {
  1153. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1154. }
  1155. else
  1156. {
  1157. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1158. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1159. )
  1160. {
  1161. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1162. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1163. )
  1164. {
  1165. struct tm tmFrom, tmTo;
  1166. struct timeb tbFrom, tbTo;
  1167. 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) &&
  1168. (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))
  1169. {
  1170. tmFrom.tm_year -= 1900;
  1171. tmFrom.tm_mon -= 1;
  1172. tbFrom.time = mktime(&tmFrom);
  1173. tmTo.tm_year -= 1900;
  1174. tmTo.tm_mon -= 1;
  1175. tbTo.time = mktime(&tmTo);
  1176. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1177. {
  1178. if(defaultTxProfile.ChargingProfileId == -1)
  1179. DEBUG_INFO("TxDefaultProfile found.\n");
  1180. else
  1181. DEBUG_INFO("TxDefaultProfile updated.\n");
  1182. // Required item
  1183. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1184. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1185. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1186. if(isUnitA)
  1187. {
  1188. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1189. 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++)
  1190. {
  1191. 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"));
  1192. 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?
  1193. 3:
  1194. 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")));
  1195. 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")));
  1196. }
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1201. 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++)
  1202. {
  1203. 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"));
  1204. 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?
  1205. 3:
  1206. 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")));
  1207. 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));
  1208. }
  1209. }
  1210. // Optional item
  1211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1212. {
  1213. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1214. }
  1215. else
  1216. {
  1217. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1218. }
  1219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1220. {
  1221. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1222. }
  1223. else
  1224. {
  1225. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1226. }
  1227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1228. {
  1229. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1230. }
  1231. else
  1232. {
  1233. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1234. }
  1235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1236. {
  1237. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1238. }
  1239. else
  1240. {
  1241. defaultTxProfile.TransactionId = -1;
  1242. }
  1243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1244. {
  1245. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1246. }
  1247. else
  1248. {
  1249. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1250. }
  1251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1252. {
  1253. 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")));
  1254. }
  1255. else
  1256. {
  1257. 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));
  1258. }
  1259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1260. {
  1261. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1262. }
  1263. else
  1264. {
  1265. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1266. }
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(defaultTxProfile.ChargingProfileId == -1)
  1273. DEBUG_INFO("TxDefaultProfile found.\n");
  1274. else
  1275. DEBUG_INFO("TxDefaultProfile updated.\n");
  1276. // Required item
  1277. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1278. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1279. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1280. if(isUnitA)
  1281. {
  1282. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1283. 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++)
  1284. {
  1285. 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"));
  1286. 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?
  1287. 3:
  1288. 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")));
  1289. 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")));
  1290. }
  1291. }
  1292. else
  1293. {
  1294. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1295. 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++)
  1296. {
  1297. 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"));
  1298. 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?
  1299. 3:
  1300. 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")));
  1301. 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));
  1302. }
  1303. }
  1304. // Optional item
  1305. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1306. {
  1307. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1308. }
  1309. else
  1310. {
  1311. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1312. }
  1313. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1314. {
  1315. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1316. }
  1317. else
  1318. {
  1319. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1320. }
  1321. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1322. {
  1323. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1324. }
  1325. else
  1326. {
  1327. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1328. }
  1329. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1330. {
  1331. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1332. }
  1333. else
  1334. {
  1335. defaultTxProfile.TransactionId = -1;
  1336. }
  1337. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1340. }
  1341. else
  1342. {
  1343. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1344. }
  1345. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1346. {
  1347. 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")));
  1348. }
  1349. else
  1350. {
  1351. 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));
  1352. }
  1353. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1354. {
  1355. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1356. }
  1357. else
  1358. {
  1359. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1360. }
  1361. }
  1362. }
  1363. }
  1364. json_object_put(obj);
  1365. }
  1366. fclose(fp);
  1367. /*
  1368. if(defaultTxProfile.ChargingProfileId != -1)
  1369. {
  1370. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1371. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1372. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1373. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1374. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1375. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1376. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1377. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1378. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1379. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1380. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1384. {
  1385. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1386. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1387. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1388. }
  1389. }
  1390. }
  1391. else
  1392. DEBUG_INFO("TxDefaultProfile not found.\n");
  1393. DEBUG_INFO("------------------------------------\n");*/
  1394. }
  1395. // Search max profile
  1396. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1397. if((access(profileFileName, F_OK))!=-1)
  1398. {
  1399. fp = fopen(profileFileName, "r");
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1403. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1404. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1405. }
  1406. maxProfile.ChargingProfileId = -1;
  1407. maxProfile.StackLevel = -1;
  1408. while(getline(&line, &len, fp) != -1)
  1409. {
  1410. json_object *obj = NULL;
  1411. obj = json_tokener_parse(line);
  1412. if(is_error(obj))
  1413. {
  1414. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1415. }
  1416. else
  1417. {
  1418. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1419. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1420. )
  1421. {
  1422. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1423. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1424. )
  1425. {
  1426. struct tm tmFrom, tmTo;
  1427. struct timeb tbFrom, tbTo;
  1428. 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) &&
  1429. (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))
  1430. {
  1431. tmFrom.tm_year -= 1900;
  1432. tmFrom.tm_mon -= 1;
  1433. tbFrom.time = mktime(&tmFrom);
  1434. tmTo.tm_year -= 1900;
  1435. tmTo.tm_mon -= 1;
  1436. tbTo.time = mktime(&tmTo);
  1437. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1438. {
  1439. if(maxProfile.ChargingProfileId == -1)
  1440. DEBUG_INFO("MaxProfile found.\n");
  1441. else
  1442. DEBUG_INFO("MaxProfile updated.\n");
  1443. // Required item
  1444. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1445. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1446. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1447. if(isUnitA)
  1448. {
  1449. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1450. 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++)
  1451. {
  1452. 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"));
  1453. 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?
  1454. 3:
  1455. 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")));
  1456. 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")));
  1457. }
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1462. 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++)
  1463. {
  1464. 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"));
  1465. 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?
  1466. 3:
  1467. 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")));
  1468. 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));
  1469. }
  1470. }
  1471. // Optional item
  1472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1473. {
  1474. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1475. }
  1476. else
  1477. {
  1478. sprintf((char*)maxProfile.ValidFrom, " ");
  1479. }
  1480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1481. {
  1482. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1483. }
  1484. else
  1485. {
  1486. sprintf((char*)maxProfile.ValidTo, " ");
  1487. }
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1489. {
  1490. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1497. {
  1498. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1499. }
  1500. else
  1501. {
  1502. maxProfile.TransactionId = -1;
  1503. }
  1504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1505. {
  1506. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1507. }
  1508. else
  1509. {
  1510. maxProfile.ChargingSchedule.Duration = 86400;
  1511. }
  1512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1513. {
  1514. 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")));
  1515. }
  1516. else
  1517. {
  1518. 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));
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1521. {
  1522. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1523. }
  1524. else
  1525. {
  1526. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. else
  1532. {
  1533. if(maxProfile.ChargingProfileId == -1)
  1534. DEBUG_INFO("MaxProfile found.\n");
  1535. else
  1536. DEBUG_INFO("MaxProfile updated.\n");
  1537. // Required item
  1538. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1539. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1540. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1541. if(isUnitA)
  1542. {
  1543. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1544. 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++)
  1545. {
  1546. 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"));
  1547. 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?
  1548. 3:
  1549. 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")));
  1550. 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")));
  1551. }
  1552. }
  1553. else
  1554. {
  1555. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1556. 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++)
  1557. {
  1558. 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"));
  1559. 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?
  1560. 3:
  1561. 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")));
  1562. 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));
  1563. }
  1564. }
  1565. // Optional item
  1566. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1567. {
  1568. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)maxProfile.ValidFrom, " ");
  1573. }
  1574. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1575. {
  1576. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1577. }
  1578. else
  1579. {
  1580. sprintf((char*)maxProfile.ValidTo, " ");
  1581. }
  1582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1583. {
  1584. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1585. }
  1586. else
  1587. {
  1588. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1589. }
  1590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1591. {
  1592. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1593. }
  1594. else
  1595. {
  1596. maxProfile.TransactionId = -1;
  1597. }
  1598. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1599. {
  1600. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1601. }
  1602. else
  1603. {
  1604. maxProfile.ChargingSchedule.Duration = 86400;
  1605. }
  1606. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1607. {
  1608. 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")));
  1609. }
  1610. else
  1611. {
  1612. 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));
  1613. }
  1614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1615. {
  1616. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1617. }
  1618. else
  1619. {
  1620. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1621. }
  1622. }
  1623. }
  1624. }
  1625. json_object_put(obj);
  1626. }
  1627. fclose(fp);
  1628. /*
  1629. if(maxProfile.ChargingProfileId !=-1)
  1630. {
  1631. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1632. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1633. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1634. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1635. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1636. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1637. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1638. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1639. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1640. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1641. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1645. {
  1646. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1647. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1648. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1649. }
  1650. }
  1651. }
  1652. else
  1653. DEBUG_INFO("MaxProfile not found.\n");
  1654. DEBUG_INFO("------------------------------------\n");*/
  1655. }
  1656. /*
  1657. * Align found profile start schedule & periods
  1658. */
  1659. //DEBUG_INFO("====================================\n");
  1660. /*
  1661. // For local test usage, force modify found profile start schedule info
  1662. 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);
  1663. 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);
  1664. 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);
  1665. */
  1666. if(txProfile.ChargingProfileId != -1)
  1667. {
  1668. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1669. {
  1670. if(txProfile.ChargingSchedule.Duration != -1)
  1671. {
  1672. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1673. 0:
  1674. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1675. }
  1676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1677. {
  1678. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1679. {
  1680. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1681. 0:
  1682. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1683. if(idxPeriod > 0)
  1684. {
  1685. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1686. {
  1687. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1694. {
  1695. if(txProfile.ChargingSchedule.Duration != -1)
  1696. {
  1697. 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?
  1698. 0:
  1699. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1700. }
  1701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1702. {
  1703. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1704. {
  1705. 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?
  1706. 0:
  1707. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1708. if(idxPeriod > 0)
  1709. {
  1710. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1711. {
  1712. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1713. }
  1714. }
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1721. {
  1722. if(txProfile.ChargingSchedule.Duration != -1)
  1723. {
  1724. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1725. 0:
  1726. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1727. }
  1728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1729. {
  1730. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1731. {
  1732. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1733. 0:
  1734. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1735. if(idxPeriod > 0)
  1736. {
  1737. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1738. {
  1739. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if(txProfile.ChargingSchedule.Duration != -1)
  1748. {
  1749. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1750. 0:
  1751. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1752. }
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1756. {
  1757. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1758. 0:
  1759. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1760. if(idxPeriod > 0)
  1761. {
  1762. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1763. {
  1764. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. /*
  1772. DEBUG_INFO("txProfile after align.\n");
  1773. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1774. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1775. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1776. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1777. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1778. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1779. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1780. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1781. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1782. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1783. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1784. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1785. {
  1786. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1787. {
  1788. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1789. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1790. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1791. }
  1792. }*/
  1793. }
  1794. if(defaultTxProfile.ChargingProfileId != -1)
  1795. {
  1796. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1797. {
  1798. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1799. {
  1800. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1801. 0:
  1802. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1803. }
  1804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1805. {
  1806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1807. {
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1809. 0:
  1810. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1811. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1812. {
  1813. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1814. }
  1815. if(idxPeriod > 0)
  1816. {
  1817. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1818. {
  1819. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1826. {
  1827. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1828. {
  1829. 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?
  1830. 0:
  1831. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1832. }
  1833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1834. {
  1835. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1836. {
  1837. 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?
  1838. 0:
  1839. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1840. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1841. {
  1842. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1843. }
  1844. if(idxPeriod > 0)
  1845. {
  1846. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1847. {
  1848. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. else
  1855. {
  1856. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1857. {
  1858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1859. {
  1860. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1861. 0:
  1862. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1863. }
  1864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1865. {
  1866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1867. {
  1868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1869. 0:
  1870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1871. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1874. }
  1875. if(idxPeriod > 0)
  1876. {
  1877. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. else
  1886. {
  1887. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1888. {
  1889. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1890. 0:
  1891. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1892. }
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1896. {
  1897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1898. 0:
  1899. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1903. }
  1904. if(idxPeriod > 0)
  1905. {
  1906. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1907. {
  1908. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1909. }
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. /*
  1916. DEBUG_INFO("defaultTxProfile after align.\n");
  1917. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1918. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1919. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1920. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1921. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1922. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1923. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1924. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1925. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1926. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1927. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1929. {
  1930. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1931. {
  1932. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1933. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1934. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1935. }
  1936. }
  1937. DEBUG_INFO("------------------------------------\n");*/
  1938. }
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1942. {
  1943. if(maxProfile.ChargingSchedule.Duration != -1)
  1944. {
  1945. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1946. 0:
  1947. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1948. }
  1949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1950. {
  1951. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1952. {
  1953. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1954. 0:
  1955. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1956. if(idxPeriod > 0)
  1957. {
  1958. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1959. {
  1960. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1967. {
  1968. if(maxProfile.ChargingSchedule.Duration != -1)
  1969. {
  1970. 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?
  1971. 0:
  1972. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1973. }
  1974. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1975. {
  1976. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1977. {
  1978. 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?
  1979. 0:
  1980. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1981. if(idxPeriod > 0)
  1982. {
  1983. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1984. {
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. else
  1992. {
  1993. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1994. {
  1995. if(maxProfile.ChargingSchedule.Duration != -1)
  1996. {
  1997. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1998. 0:
  1999. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2000. }
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2004. {
  2005. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2006. 0:
  2007. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2008. if(idxPeriod > 0)
  2009. {
  2010. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2011. {
  2012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. else
  2019. {
  2020. if(maxProfile.ChargingSchedule.Duration != -1)
  2021. {
  2022. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2023. 0:
  2024. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2025. }
  2026. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2027. {
  2028. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2029. {
  2030. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2031. 0:
  2032. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2033. if(idxPeriod > 0)
  2034. {
  2035. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2036. {
  2037. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. /*
  2045. DEBUG_INFO("MaxProfile after align.\n");
  2046. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2047. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2048. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2049. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2050. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2051. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2052. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2053. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2054. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2055. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2056. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2057. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2058. {
  2059. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2060. {
  2061. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2062. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2063. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2064. }
  2065. }
  2066. DEBUG_INFO("------------------------------------\n");*/
  2067. }
  2068. /*
  2069. * Merge to conposite schedule
  2070. */
  2071. //DEBUG_INFO("====================================\n");
  2072. // Find each profile period quantity
  2073. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2074. {
  2075. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2076. limitMax = idx+1;
  2077. }
  2078. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2079. {
  2080. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2081. limitDef = idx+1;
  2082. }
  2083. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2084. {
  2085. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2086. limitTx = idx+1;
  2087. }
  2088. // TxProfile found, composite schedule based on it
  2089. if(txProfile.ChargingProfileId != -1)
  2090. {
  2091. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2092. {
  2093. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2094. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2095. (txProfile.ChargingSchedule.Duration > 0))
  2096. {
  2097. if(maxProfile.ChargingProfileId != -1)
  2098. {
  2099. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2100. {
  2101. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2102. {
  2103. if((maxProfile.ChargingSchedule.Duration > 0))
  2104. {
  2105. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2106. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2107. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2108. }
  2109. else
  2110. {
  2111. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2112. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2113. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2114. }
  2115. }
  2116. if(idxMaxPeriod == (limitMax-1))
  2117. {
  2118. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2119. {
  2120. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2121. {
  2122. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2123. compositePeriodIdx++;
  2124. }
  2125. else
  2126. {
  2127. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. else
  2134. {
  2135. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2136. {
  2137. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2138. compositePeriodIdx++;
  2139. }
  2140. else
  2141. {
  2142. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2143. }
  2144. }
  2145. }
  2146. if(idxTxPeriod == (limitTx-1))
  2147. {
  2148. if(defaultTxProfile.ChargingProfileId != -1)
  2149. {
  2150. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2151. {
  2152. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2153. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2154. (defaultTxProfile.ChargingSchedule.Duration>0))
  2155. {
  2156. if(maxProfile.ChargingProfileId != -1)
  2157. {
  2158. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2159. {
  2160. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2161. {
  2162. if((maxProfile.ChargingSchedule.Duration > 0))
  2163. {
  2164. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2165. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2166. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2167. }
  2168. else
  2169. {
  2170. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2171. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2172. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2173. }
  2174. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2175. {
  2176. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2177. {
  2178. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2179. compositePeriodIdx++;
  2180. }
  2181. else
  2182. {
  2183. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2184. }
  2185. }
  2186. break;
  2187. }
  2188. }
  2189. }
  2190. else
  2191. {
  2192. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2193. {
  2194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2195. compositePeriodIdx++;
  2196. }
  2197. else
  2198. {
  2199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2209. else if(defaultTxProfile.ChargingProfileId != -1)
  2210. {
  2211. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2212. {
  2213. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2214. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2215. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2216. {
  2217. if(maxProfile.ChargingProfileId != -1)
  2218. {
  2219. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2220. {
  2221. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2222. {
  2223. if((maxProfile.ChargingSchedule.Duration > 0))
  2224. {
  2225. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2226. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2227. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2228. }
  2229. else
  2230. {
  2231. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2232. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2233. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2234. }
  2235. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2236. {
  2237. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2238. {
  2239. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2240. compositePeriodIdx++;
  2241. }
  2242. else
  2243. {
  2244. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2245. }
  2246. }
  2247. break;
  2248. }
  2249. }
  2250. }
  2251. else
  2252. {
  2253. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2254. {
  2255. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2256. compositePeriodIdx++;
  2257. }
  2258. else
  2259. {
  2260. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. // Fill other period by MaxProfile
  2267. if(maxProfile.ChargingProfileId != -1)
  2268. {
  2269. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2270. {
  2271. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2272. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2273. (maxProfile.ChargingSchedule.Duration > 0))
  2274. {
  2275. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2276. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2277. {
  2278. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2279. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2280. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2281. }
  2282. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2283. {
  2284. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2285. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2286. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2287. }
  2288. if(tmpPeriod.Limit != -1)
  2289. {
  2290. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2291. {
  2292. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2293. {
  2294. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2295. compositePeriodIdx++;
  2296. }
  2297. else
  2298. {
  2299. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2307. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2308. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2309. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2313. {
  2314. compositeProfile->ChargingProfileId = 1;
  2315. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2316. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2317. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2318. }
  2319. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2320. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2321. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2322. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2323. }
  2324. if(line)
  2325. free(line);
  2326. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2327. }
  2328. //==========================================
  2329. // Init all share memory
  2330. //==========================================
  2331. int InitShareMemory()
  2332. {
  2333. int result = PASS;
  2334. int MeterSMId;
  2335. //creat ShmSysConfigAndInfo
  2336. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2337. {
  2338. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2339. result = FAIL;
  2340. }
  2341. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2342. {
  2343. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2344. result = FAIL;
  2345. }
  2346. else
  2347. {}
  2348. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2349. {
  2350. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2351. result = FAIL;
  2352. }
  2353. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2354. {
  2355. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2356. result = FAIL;
  2357. }
  2358. else
  2359. {}
  2360. //creat ShmPsuData
  2361. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2362. {
  2363. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2364. result = FAIL;
  2365. }
  2366. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2367. {
  2368. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2369. result = FAIL;
  2370. }
  2371. else
  2372. {}
  2373. //creat ShmOCPP16Data
  2374. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2375. {
  2376. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2377. result = FAIL;
  2378. }
  2379. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2380. {
  2381. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2382. result = FAIL;
  2383. }
  2384. else
  2385. {}
  2386. /****************************** For Initial Settings************************************************/
  2387. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2388. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2389. // allocate Configuration memory address
  2390. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2391. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2392. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2393. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2394. //offline MeterValue Interval
  2395. TempMeterValueInterval = 0;
  2396. return result;
  2397. }
  2398. int ProcessShareMemory()
  2399. {
  2400. if(InitShareMemory() == FAIL)
  2401. {
  2402. DEBUG_ERROR("InitShareMemory NG\n");
  2403. if(ShmStatusCodeData!=NULL)
  2404. {
  2405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2406. }
  2407. sleep(5);
  2408. return FAIL;
  2409. }
  2410. return PASS;
  2411. }
  2412. void CheckSystemValue(void)
  2413. {
  2414. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2415. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2416. char filenmae[100]={0};
  2417. char str[100]={0};
  2418. int tempIndex = 0;
  2419. //===============================
  2420. // send Heartbeat
  2421. //===============================
  2422. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2423. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2424. {
  2425. clientTime.Heartbeat=time((time_t*)NULL);
  2426. if(server_sign == TRUE)
  2427. {
  2428. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2429. }
  2430. else
  2431. {
  2432. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2433. }
  2434. }
  2435. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2436. {
  2437. //parameter for test
  2438. sendHeartbeatRequest(0);
  2439. //==============================================
  2440. // Reset Waiting Time
  2441. //==============================================
  2442. HeartBeatWithNOResponse += 1;
  2443. }
  2444. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2445. {
  2446. //==========================================
  2447. // csu trigger DataTransferReq
  2448. //==========================================
  2449. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2450. {
  2451. sendDataTransferRequest(gun_index);
  2452. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2453. }
  2454. //===============================
  2455. // CSU Trigger Reset Conf
  2456. //===============================
  2457. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2458. {
  2459. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2460. }
  2461. //===============================
  2462. // CSU Trigger Authorize Request
  2463. //===============================
  2464. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2465. {
  2466. sendAuthorizeRequest(0);
  2467. authorizeRetryTimes = authorizeRetryTimes + 1;
  2468. if(authorizeRetryTimes < 3)
  2469. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2470. }
  2471. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2472. {
  2473. authorizeRetryTimes = 0;
  2474. SetOcppConnStatus(FALSE);
  2475. server_sign = FALSE;
  2476. }
  2477. 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))
  2478. {
  2479. sendAuthorizeRequest(0);
  2480. }
  2481. //==============================================
  2482. // CSU Trigger Smart Charging Profilw
  2483. //==============================================
  2484. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2485. {
  2486. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2487. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2488. }
  2489. //==============================================
  2490. // Charger start transaction
  2491. //==============================================
  2492. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2493. {
  2494. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2495. sendStartTransactionRequest(gun_index);
  2496. clientTime.StartTransaction = time((time_t*)NULL);
  2497. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2498. storeTempStopTransaction(gun_index);
  2499. }
  2500. //==============================================
  2501. // Charger stop transaction
  2502. //==============================================
  2503. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2504. {
  2505. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2506. sendStopTransactionRequest(gun_index);
  2507. clientTime.StopTransaction = time((time_t*)NULL);
  2508. }
  2509. //==============================================
  2510. // Charger status report
  2511. //==============================================
  2512. //--- Check Mode Change ---//
  2513. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2514. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  2525. {
  2526. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2527. {
  2528. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2529. {
  2530. // Sent unplug message for California pricing logic
  2531. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2541. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2542. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2543. statusModeChage[gun_index] = TRUE;
  2544. }
  2545. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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.ChademoChargingData[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_CCS)
  2565. {
  2566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2567. {
  2568. tempIndex = ((gun_index==2) ? 1: 0);
  2569. }
  2570. else
  2571. {
  2572. tempIndex = gun_index;
  2573. }
  2574. for (int index = 0; index < CCS_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2577. {
  2578. 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]*/ )
  2579. {
  2580. // Sent unplug message for California pricing logic
  2581. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2582. {
  2583. uint8_t ts[20];
  2584. getNowDatetime(ts);
  2585. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2586. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2587. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2588. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2589. }
  2590. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2591. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2592. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2593. statusModeChage[gun_index] = TRUE;
  2594. }
  2595. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2596. {
  2597. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2598. if((access(filenmae,F_OK))!=-1)
  2599. {
  2600. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2601. sprintf(str,"rm -f %s",filenmae);
  2602. system(str);
  2603. }
  2604. }
  2605. #if 1 // for TempStopTransaction
  2606. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2607. {
  2608. checkTempStopTransaction(gun_index);
  2609. }
  2610. #endif
  2611. }
  2612. }
  2613. }
  2614. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2615. {
  2616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2617. {
  2618. tempIndex = ((gun_index==2) ? 1: 0);
  2619. }
  2620. else
  2621. {
  2622. tempIndex = gun_index;
  2623. }
  2624. for (int index = 0; index < GB_QUANTITY; index++)
  2625. {
  2626. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2627. {
  2628. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2629. {
  2630. // Sent unplug message for California pricing logic
  2631. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2632. {
  2633. uint8_t ts[20];
  2634. getNowDatetime(ts);
  2635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2636. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2637. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2638. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2639. }
  2640. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2641. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2642. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2643. statusModeChage[gun_index] = TRUE;
  2644. }
  2645. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2646. {
  2647. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2648. if((access(filenmae,F_OK))!=-1)
  2649. {
  2650. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2651. sprintf(str,"rm -f %s",filenmae);
  2652. system(str);
  2653. }
  2654. }
  2655. #if 1 // for TempStopTransaction
  2656. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2657. {
  2658. checkTempStopTransaction(gun_index);
  2659. }
  2660. #endif
  2661. }
  2662. }
  2663. }
  2664. else if(gunType[gun_index] == GUN_TYPE_DO)
  2665. {
  2666. tempIndex = gun_index;
  2667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2668. {
  2669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2670. {
  2671. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2672. {
  2673. // Sent unplug message for California pricing logic
  2674. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2675. {
  2676. uint8_t ts[20];
  2677. getNowDatetime(ts);
  2678. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2679. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2680. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2681. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2682. }
  2683. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2684. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2685. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2686. statusModeChage[gun_index] = TRUE;
  2687. }
  2688. 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
  2689. {
  2690. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2691. if((access(filenmae,F_OK))!=-1)
  2692. {
  2693. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2694. sprintf(str,"rm -f %s",filenmae);
  2695. system(str);
  2696. }
  2697. }
  2698. #if 1 // for TempStopTransaction
  2699. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2700. {
  2701. checkTempStopTransaction(gun_index);
  2702. }
  2703. #endif
  2704. }
  2705. }
  2706. }
  2707. else
  2708. {
  2709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2710. {
  2711. tempIndex = 2;
  2712. }
  2713. else
  2714. {
  2715. tempIndex = gun_index;
  2716. }
  2717. for (int index = 0; index < AC_QUANTITY; index++)
  2718. {
  2719. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2720. {
  2721. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2722. {
  2723. // Sent unplug message for California pricing logic
  2724. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2725. {
  2726. uint8_t ts[20];
  2727. getNowDatetime(ts);
  2728. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2729. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2730. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2731. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2732. }
  2733. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2734. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2735. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2736. statusModeChage[gun_index] = TRUE;
  2737. }
  2738. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2739. {
  2740. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2741. if((access(filenmae,F_OK))!=-1)
  2742. {
  2743. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2744. sprintf(str,"rm -f %s",filenmae);
  2745. system(str);
  2746. }
  2747. }
  2748. #if 1 // for TempStopTransaction
  2749. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2750. {
  2751. checkTempStopTransaction(gun_index);
  2752. }
  2753. #endif
  2754. }
  2755. }// END
  2756. }
  2757. if(isWebsocketSendable && (server_sign == TRUE) &&
  2758. (
  2759. (statusModeChage[gun_index] == TRUE) ||
  2760. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2761. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2762. )
  2763. )
  2764. {
  2765. if(SystemInitial > 0)
  2766. SystemInitial -= 1;
  2767. sendStatusNotificationRequest(gun_index);
  2768. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2769. statusModeChage[gun_index] = FALSE;
  2770. }
  2771. //==============================================
  2772. // Meter report
  2773. //==============================================
  2774. // Trigger MeterValue
  2775. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2776. {
  2777. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2778. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2779. }
  2780. // ClockAlign MeterValue
  2781. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2782. {
  2783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2784. {
  2785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2786. {
  2787. tempIndex = ((gun_index==2) ? 1: 0);
  2788. }
  2789. else
  2790. {
  2791. tempIndex = gun_index;
  2792. }
  2793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2794. {
  2795. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2796. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2797. {
  2798. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2799. {
  2800. reqClockAlignMeter[gun_index] = 1;
  2801. }
  2802. }
  2803. }// End for CHAdeMO
  2804. }
  2805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2806. {
  2807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2808. {
  2809. tempIndex = ((gun_index==2) ? 1: 0);
  2810. }
  2811. else
  2812. {
  2813. tempIndex = gun_index;
  2814. }
  2815. for (int index = 0; index < CCS_QUANTITY; index++)
  2816. {
  2817. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2818. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2819. {
  2820. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2821. {
  2822. reqClockAlignMeter[gun_index] = 1;
  2823. }
  2824. }
  2825. } // End for CCS
  2826. }
  2827. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2828. {
  2829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2830. {
  2831. tempIndex = ((gun_index==2) ? 1: 0);
  2832. }
  2833. else
  2834. {
  2835. tempIndex = gun_index;
  2836. }
  2837. for (int index = 0; index < GB_QUANTITY; index++)
  2838. {
  2839. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2840. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2841. {
  2842. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2843. {
  2844. reqClockAlignMeter[gun_index] = 1;
  2845. }
  2846. }
  2847. }// End for GB
  2848. }
  2849. else if(gunType[gun_index] == GUN_TYPE_DO)
  2850. {
  2851. tempIndex = gun_index;
  2852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2853. {
  2854. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2855. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2856. {
  2857. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2858. {
  2859. reqClockAlignMeter[gun_index] = 1;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. else
  2865. {
  2866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2867. {
  2868. tempIndex = 2;
  2869. }
  2870. else
  2871. {
  2872. tempIndex = gun_index;
  2873. }
  2874. for (int index = 0; index < AC_QUANTITY; index++)
  2875. {
  2876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2877. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2878. {
  2879. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2880. {
  2881. reqClockAlignMeter[gun_index] = 1;
  2882. }
  2883. }
  2884. }//End for AC
  2885. }
  2886. if(reqClockAlignMeter[gun_index] == 1)
  2887. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2888. }
  2889. // Sample period MeterValue
  2890. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2891. {
  2892. //check Transaction active
  2893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2894. {
  2895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2896. {
  2897. tempIndex = ((gun_index==2) ? 1: 0);
  2898. }
  2899. else
  2900. {
  2901. tempIndex = gun_index;
  2902. }
  2903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2904. {
  2905. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2906. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2907. {
  2908. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2909. {
  2910. reqSampleMeter[gun_index] = 1;
  2911. }
  2912. }
  2913. }// End for CHAdeMO
  2914. }
  2915. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2916. {
  2917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2918. {
  2919. tempIndex = ((gun_index==2) ? 1: 0);
  2920. }
  2921. else
  2922. {
  2923. tempIndex = gun_index;
  2924. }
  2925. for (int index = 0; index < CCS_QUANTITY; index++)
  2926. {
  2927. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2928. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2929. {
  2930. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2931. {
  2932. reqSampleMeter[gun_index] = 1;
  2933. }
  2934. }
  2935. } // End for CCS
  2936. }
  2937. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2938. {
  2939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2940. {
  2941. tempIndex = ((gun_index==2) ? 1: 0);
  2942. }
  2943. else
  2944. {
  2945. tempIndex = gun_index;
  2946. }
  2947. for (int index = 0; index < GB_QUANTITY; index++)
  2948. {
  2949. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2950. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2951. {
  2952. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2953. {
  2954. reqSampleMeter[gun_index] = 1;
  2955. }
  2956. }
  2957. }// End for GB
  2958. }
  2959. else if(gunType[gun_index] == GUN_TYPE_DO)
  2960. {
  2961. tempIndex = gun_index;
  2962. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2963. {
  2964. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2965. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2966. {
  2967. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2968. {
  2969. reqSampleMeter[gun_index] = 1;
  2970. }
  2971. }
  2972. }
  2973. }
  2974. else
  2975. {
  2976. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2977. {
  2978. tempIndex = 2;
  2979. }
  2980. else
  2981. {
  2982. tempIndex = gun_index;
  2983. }
  2984. for (int index = 0; index < AC_QUANTITY; index++)
  2985. {
  2986. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2987. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2988. {
  2989. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2990. {
  2991. reqSampleMeter[gun_index] = 1;
  2992. }
  2993. }
  2994. }//End for AC
  2995. }
  2996. if(reqSampleMeter[gun_index] == 1)
  2997. {
  2998. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2999. storeTempStopTransaction(gun_index);
  3000. }
  3001. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3002. }
  3003. //==============================================
  3004. // Check Connector reserved
  3005. //==============================================
  3006. //===============================
  3007. // Check if Reserve is expired
  3008. //===============================
  3009. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3010. {
  3011. double diff_t;
  3012. struct tm tp;
  3013. // current time
  3014. time_t t = time(NULL);
  3015. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3016. tp.tm_isdst = -1;
  3017. time_t utc = mktime(&tp);
  3018. diff_t = difftime(utc, t);
  3019. if(diff_t <= 0)
  3020. {
  3021. DEBUG_INFO("reserve expired.\n");
  3022. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3023. }
  3024. }//END OF Check if Reserve is expired
  3025. //==========================================
  3026. // csu trigger FirmwareStatusNotificationReq
  3027. //==========================================
  3028. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3029. {
  3030. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3031. }
  3032. //==========================================
  3033. // csu trigger DiagnosticsStatusNotificationReq
  3034. //==========================================
  3035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3036. {
  3037. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3038. }
  3039. //==========================================
  3040. // csu trigger CancelReservationConf
  3041. //==========================================
  3042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3043. {
  3044. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3045. }
  3046. //==========================================
  3047. // csu trigger ChangeAvailabilityConf
  3048. //==========================================
  3049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3050. {
  3051. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3052. }
  3053. //==========================================
  3054. // csu trigger UnlockConnectorConf
  3055. //==========================================
  3056. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3057. {
  3058. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3059. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3060. }
  3061. //==========================================
  3062. // csu trigger ReserveNowConf
  3063. //==========================================
  3064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3065. {
  3066. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3067. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3068. }
  3069. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/cert.csr",F_OK) != -1))
  3070. {
  3071. sendSignCertificateRequest();
  3072. }
  3073. }
  3074. }
  3075. //==========================================
  3076. // send request routine
  3077. //==========================================
  3078. int sendAuthorizeRequest(int gun_index)
  3079. {
  3080. mtrace();
  3081. int result = FAIL;
  3082. char message[100]={0};
  3083. char guid[37];
  3084. char tempdata[65]={0};
  3085. DEBUG_INFO("sendAuthorizeRequest...\n");
  3086. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3087. //Local Authorize
  3088. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3089. {
  3090. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3091. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3092. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3093. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3094. result = PASS;
  3095. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3096. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3097. authorizeRetryTimes = 0;
  3098. return result;
  3099. }
  3100. 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))||
  3101. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3102. {
  3103. // Query from cache
  3104. DEBUG_INFO("Authorize from cache.\n");
  3105. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3106. // Query from list
  3107. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3108. {
  3109. DEBUG_INFO("Authorize from list.\n");
  3110. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3111. }
  3112. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3113. {
  3114. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3115. {
  3116. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3117. }
  3118. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3119. {
  3120. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3121. }
  3122. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3123. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3124. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3125. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3126. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3127. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3128. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3129. authorizeRetryTimes = 0;
  3130. return result;
  3131. }
  3132. else
  3133. {
  3134. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3135. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3136. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3137. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3138. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3139. else
  3140. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3141. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3142. result = PASS;
  3143. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3144. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3145. authorizeRetryTimes = 0;
  3146. return result;
  3147. }
  3148. }
  3149. //initialize struct Authorize
  3150. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3151. //get data from shared memory
  3152. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3153. random_uuid(guid);
  3154. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3155. LWS_Send(message);
  3156. sprintf(tempdata, "Authorize,%d", gun_index);
  3157. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3158. {
  3159. result = PASS;
  3160. DEBUG_INFO("Authorize mapItem pass\n");
  3161. }
  3162. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3163. return result;
  3164. }
  3165. int sendBootNotificationRequest(void)
  3166. {
  3167. mtrace();
  3168. int result = FAIL;
  3169. char message[500]={0}, payload[700]={0};
  3170. char guid[37]={0};
  3171. char tempdata[65]={0};
  3172. // Fill BootNotification fields
  3173. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3174. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3175. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3176. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3177. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3178. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3179. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3180. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3181. ShmOCPP16Data->ChargeBoxId
  3182. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3183. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3184. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3185. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3186. ,ShmOCPP16Data->BootNotification.CpIccid
  3187. ,ShmOCPP16Data->BootNotification.CpImsi);
  3188. random_uuid(guid);
  3189. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3190. LWS_Send(message);
  3191. sprintf(tempdata, "BootNotification,0");
  3192. 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*/)
  3193. {
  3194. result = PASS;
  3195. }
  3196. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3197. strcpy(queuedata,message);
  3198. return result;
  3199. }
  3200. int sendDataTransferRequest(int gun_index)
  3201. {
  3202. mtrace();
  3203. char message[1000]={0};
  3204. char guid[37]={0};
  3205. char tempdata[65]={0};
  3206. int result = FAIL;
  3207. random_uuid(guid);
  3208. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3209. MESSAGE_TYPE_CALL,
  3210. guid,
  3211. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3212. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3213. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3214. LWS_Send(message);
  3215. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3216. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3217. {
  3218. result = PASS;
  3219. DEBUG_INFO("DataTransfer mapItem pass\n");
  3220. }
  3221. return result;
  3222. }
  3223. int sendDiagnosticsStatusNotificationRequest(char *status)
  3224. {
  3225. mtrace();
  3226. int result = FAIL;
  3227. char message[110]={0};
  3228. char guid[37]={0};
  3229. char tempdata[65]={0};
  3230. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3231. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3232. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3233. random_uuid(guid);
  3234. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3235. LWS_SendNow(message);
  3236. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3237. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3238. {
  3239. result = PASS;
  3240. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3241. }
  3242. //#ifdef SystemLogMessage
  3243. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3244. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3245. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3246. //#endif
  3247. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3248. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3249. //record status
  3250. if(strcmp(status,"Idle")==0)
  3251. {
  3252. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3253. }
  3254. else if(strcmp(status,"Uploaded")==0)
  3255. {
  3256. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3257. }
  3258. else if(strcmp(status,"UploadFailed")==0)
  3259. {
  3260. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3261. }
  3262. else if(strcmp(status,"Uploading")==0)
  3263. {
  3264. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3265. }
  3266. return result;
  3267. }
  3268. int sendFirmwareStatusNotificationRequest(char *status)
  3269. {
  3270. mtrace();
  3271. int result = FAIL;
  3272. char message[110]={0};
  3273. char guid[37]={0};
  3274. char tempdata[65]={0};
  3275. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3276. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3277. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3278. random_uuid(guid);
  3279. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3280. LWS_SendNow(message);
  3281. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3282. 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*/)
  3283. {
  3284. result = PASS;
  3285. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3286. }
  3287. //#ifdef SystemLogMessage
  3288. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3289. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3290. //#endif
  3291. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3292. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3293. //record status
  3294. if(strcmp(status,"Downloaded")==0)
  3295. {
  3296. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3297. }
  3298. else if(strcmp(status,"DownloadFailed")==0)
  3299. {
  3300. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3301. }
  3302. else if(strcmp(status,"Downloading")==0)
  3303. {
  3304. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3305. }
  3306. else if(strcmp(status,"Idle")==0)
  3307. {
  3308. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3309. }
  3310. else if(strcmp(status,"InstallationFailed")==0)
  3311. {
  3312. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3313. }
  3314. else if(strcmp(status,"Installing")==0)
  3315. {
  3316. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3317. }
  3318. else if(strcmp(status,"Installed")==0)
  3319. {
  3320. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3321. }
  3322. return result;
  3323. }
  3324. int sendHeartbeatRequest(int gun_index)
  3325. {
  3326. mtrace();
  3327. int result = FAIL;
  3328. char message[80]={0};
  3329. char guid[37]={0};
  3330. char tempdata[65]={0};
  3331. random_uuid(guid);
  3332. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3333. , MESSAGE_TYPE_CALL
  3334. , guid );
  3335. LWS_Send(message);
  3336. sprintf(tempdata, "Heartbeat,%d", 0);
  3337. 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*/)
  3338. {
  3339. result = PASS;
  3340. }
  3341. return result;
  3342. }
  3343. int sendStartTransactionRequest(int gun_index)
  3344. {
  3345. mtrace();
  3346. int result = FAIL;
  3347. char message[250]={0};
  3348. char guid[37]={0};
  3349. struct timeval tmnow;
  3350. struct tm *tm;
  3351. char buf[28];//, usec_buf[6];
  3352. char tempdata[65]={0};
  3353. int tempIndex = 0;
  3354. DEBUG_INFO("sendStartTransactionRequest...\n");
  3355. gettimeofday(&tmnow, NULL);
  3356. time_t t;
  3357. t = time(NULL);
  3358. /*UTC time and date*/
  3359. tm = gmtime(&t);
  3360. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3361. #if 0 // remove temporally
  3362. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3363. strcat(buf,".");
  3364. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3365. strcat(buf,usec_buf);
  3366. #endif
  3367. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3368. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3369. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3370. // clear StartTransaction Response
  3371. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3372. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3373. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3374. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3375. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3376. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3378. {
  3379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3380. {
  3381. tempIndex = ((gun_index==2) ? 1: 0);
  3382. }
  3383. else
  3384. {
  3385. tempIndex = gun_index;
  3386. }
  3387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3388. {
  3389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3390. {
  3391. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3392. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3393. }
  3394. }
  3395. }
  3396. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3397. {
  3398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3399. {
  3400. tempIndex = ((gun_index==2) ? 1: 0);
  3401. }
  3402. else
  3403. {
  3404. tempIndex = gun_index;
  3405. }
  3406. for (int index = 0; index < CCS_QUANTITY; index++)
  3407. {
  3408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3409. {
  3410. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3411. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3412. }
  3413. }
  3414. }
  3415. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3416. {
  3417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3418. {
  3419. tempIndex = ((gun_index==2) ? 1: 0);
  3420. }
  3421. else
  3422. {
  3423. tempIndex = gun_index;
  3424. }
  3425. for (int index = 0; index < GB_QUANTITY; index++)
  3426. {
  3427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3428. {
  3429. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3430. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3431. }
  3432. }
  3433. }
  3434. else if(gunType[gun_index] == GUN_TYPE_DO)
  3435. {
  3436. tempIndex = gun_index;
  3437. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3438. {
  3439. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3440. {
  3441. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3442. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3443. }
  3444. }
  3445. }
  3446. else
  3447. {
  3448. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3449. {
  3450. tempIndex = 2;
  3451. }
  3452. else
  3453. {
  3454. tempIndex = gun_index;
  3455. }
  3456. for (int index = 0; index < AC_QUANTITY; index++)
  3457. {
  3458. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3459. {
  3460. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3461. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3462. }
  3463. }
  3464. }
  3465. random_uuid(guid);
  3466. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3467. {
  3468. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3469. , gun_index +1
  3470. , MESSAGE_TYPE_CALL
  3471. , guid
  3472. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3473. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3474. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3475. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3476. }
  3477. else
  3478. {
  3479. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3480. , gun_index +1
  3481. , MESSAGE_TYPE_CALL
  3482. , guid
  3483. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3484. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3485. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3486. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3487. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3488. }
  3489. #if 1
  3490. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3491. 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*/)
  3492. {
  3493. result = PASS;
  3494. }
  3495. #endif
  3496. strcpy(queuedata, message);
  3497. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3498. OCPP_insert_transaction_msg(YES, queuedata);
  3499. return result;
  3500. }
  3501. int sendStatusNotificationRequest(int gun_index)
  3502. {
  3503. mtrace();
  3504. int result = FAIL;
  3505. char message[600]={0};
  3506. char guid[37];
  3507. int currentStatus = 0;
  3508. struct timeval tmnow;
  3509. struct tm *tm;
  3510. char buf[28];//, usec_buf[6];
  3511. char tempdata[65]={0};
  3512. int tempIndex = 0;
  3513. uint8_t isStateChanged = TRUE;
  3514. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3515. gettimeofday(&tmnow, NULL);
  3516. time_t t;
  3517. t = time(NULL);
  3518. /*UTC time and date*/
  3519. tm = gmtime(&t);
  3520. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3521. #if 0 // remove temporally
  3522. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3523. strcat(buf,".");
  3524. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3525. strcat(buf,usec_buf);
  3526. #endif
  3527. printf("%s",buf);
  3528. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3529. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3530. // it's option
  3531. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3532. /*
  3533. enum _SYSTEM_STATUS
  3534. {
  3535. S_BOOTING = 0,
  3536. S_IDLE, = 1
  3537. S_AUTHORIZING, =2
  3538. S_REASSIGN_CHECK, =3
  3539. S_REASSIGN, =4
  3540. S_PRECHARGE, =5
  3541. S_PREPARING_FOR_EV, =6
  3542. S_PREPARING_FOR_EVSE, =7
  3543. S_CHARGING, =8
  3544. S_TERMINATING, =9
  3545. S_COMPLETE, =10
  3546. S_ALARM, =11
  3547. S_FAULT =12
  3548. }
  3549. */
  3550. //check Transaction active
  3551. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3552. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3553. {
  3554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3555. {
  3556. tempIndex = ((gun_index==2) ? 1: 0);
  3557. }
  3558. else
  3559. {
  3560. tempIndex = gun_index;
  3561. }
  3562. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3563. {
  3564. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3565. {
  3566. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3567. {
  3568. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3569. {
  3570. currentStatus = Preparing; //OCPP Status: Preparing
  3571. }
  3572. else
  3573. {
  3574. currentStatus = Available; //OCPP Status: Available
  3575. }
  3576. }
  3577. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3578. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3579. ) //S_PRECHARGE
  3580. {
  3581. currentStatus = Preparing; //OCPP Status: Preparing
  3582. }
  3583. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3584. {
  3585. currentStatus = Charging; //OCPP Status: Charging
  3586. }
  3587. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3588. {
  3589. currentStatus = Finishing; //OCPP Status: Finishing
  3590. }
  3591. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3592. {
  3593. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3594. }
  3595. 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
  3596. {
  3597. currentStatus = Unavailable; //OCPP Status: Unavailable
  3598. }
  3599. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3600. {
  3601. currentStatus = Faulted; //OCPP Status: Faulted
  3602. }
  3603. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3604. {
  3605. currentStatus = Reserved; //OCPP Status: Reserved
  3606. }
  3607. } //end of the same index
  3608. }//end of for CHAdeMO_QUANTITY
  3609. }
  3610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3611. {
  3612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3613. {
  3614. tempIndex = ((gun_index==2) ? 1: 0);
  3615. }
  3616. else
  3617. {
  3618. tempIndex = gun_index;
  3619. }
  3620. for (int index = 0; index < CCS_QUANTITY; index++)
  3621. {
  3622. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3623. {
  3624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3625. {
  3626. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3627. {
  3628. currentStatus = Preparing; //OCPP Status: Preparing
  3629. }
  3630. else
  3631. {
  3632. currentStatus = Available; //OCPP Status: Available
  3633. }
  3634. }
  3635. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3636. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3637. ) //S_PRECHARGE
  3638. {
  3639. currentStatus = Preparing; //OCPP Status: Preparing
  3640. }
  3641. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3642. {
  3643. currentStatus = Charging; //OCPP Status: Charging
  3644. }
  3645. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3646. {
  3647. currentStatus = Finishing; //OCPP Status: Finishing
  3648. }
  3649. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3650. {
  3651. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3652. }
  3653. 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
  3654. {
  3655. currentStatus = Unavailable; //OCPP Status : Unavailable
  3656. }
  3657. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3658. {
  3659. currentStatus = Faulted; //OCPP Status: Faulted
  3660. }
  3661. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3662. {
  3663. currentStatus = Reserved; //OCPP Status: Reserved
  3664. }
  3665. } //end of the same index
  3666. } // end of for CCS_QUANTITY
  3667. }
  3668. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3669. {
  3670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3671. {
  3672. tempIndex = ((gun_index==2) ? 1: 0);
  3673. }
  3674. else
  3675. {
  3676. tempIndex = gun_index;
  3677. }
  3678. for (int index = 0; index < GB_QUANTITY; index++)
  3679. {
  3680. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3681. {
  3682. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3683. {
  3684. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3685. {
  3686. currentStatus = Preparing; //OCPP Status: Preparing
  3687. }
  3688. else
  3689. {
  3690. currentStatus = Available; //OCPP Status: Available
  3691. }
  3692. }
  3693. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3694. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3695. ) //S_PRECHARGE
  3696. {
  3697. currentStatus = Preparing; //OCPP Status: Preparing
  3698. }
  3699. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3700. {
  3701. currentStatus = Charging; //OCPP Status: Charging
  3702. }
  3703. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3704. {
  3705. currentStatus = Finishing; //OCPP Status: Finishing
  3706. }
  3707. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3708. {
  3709. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3710. }
  3711. 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
  3712. {
  3713. currentStatus = Unavailable; //OCPP Status: Unavailable
  3714. }
  3715. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3716. {
  3717. currentStatus = Faulted; //OCPP Status: Faulted
  3718. }
  3719. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3720. {
  3721. currentStatus = Reserved; //OCPP Status: Reserved
  3722. }
  3723. } //end of the same index
  3724. } // end of for GB_QUANTITY
  3725. }
  3726. else if(gunType[gun_index] == GUN_TYPE_DO)
  3727. {
  3728. tempIndex = gun_index;
  3729. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3730. {
  3731. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3732. {
  3733. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3734. {
  3735. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3736. {
  3737. currentStatus = Preparing; //OCPP Status: Preparing
  3738. }
  3739. else
  3740. {
  3741. currentStatus = Available; //OCPP Status: Available
  3742. }
  3743. }
  3744. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3745. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3746. ) //S_PRECHARGE
  3747. {
  3748. currentStatus = Preparing; //OCPP Status: Preparing
  3749. }
  3750. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3751. {
  3752. currentStatus = Charging; //OCPP Status: Charging
  3753. }
  3754. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3755. {
  3756. currentStatus = Finishing; //OCPP Status: Finishing
  3757. }
  3758. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3759. {
  3760. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3761. }
  3762. 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
  3763. {
  3764. currentStatus = Unavailable; //OCPP Status: Unavailable
  3765. }
  3766. 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
  3767. {
  3768. currentStatus = Faulted; //OCPP Status: Faulted
  3769. }
  3770. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3771. {
  3772. currentStatus = Reserved; //OCPP Status: Reserved
  3773. }
  3774. } //end of the same index
  3775. }
  3776. }
  3777. else
  3778. {
  3779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3780. {
  3781. tempIndex = 2;
  3782. }
  3783. else
  3784. {
  3785. tempIndex = gun_index;
  3786. }
  3787. for (int index = 0; index < AC_QUANTITY; index++)
  3788. {
  3789. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3790. {
  3791. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3792. {
  3793. 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))
  3794. {
  3795. currentStatus = Preparing; //OCPP Status: Preparing
  3796. }
  3797. else
  3798. {
  3799. currentStatus = Available; //OCPP Status: Available
  3800. }
  3801. }
  3802. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3803. {
  3804. currentStatus = Preparing; //OCPP Status: Preparing
  3805. }
  3806. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3807. {
  3808. currentStatus = Charging; //OCPP Status: Charging
  3809. }
  3810. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3811. {
  3812. currentStatus = Finishing; //OCPP Status: Finishing
  3813. }
  3814. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3815. {
  3816. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3817. }
  3818. 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
  3819. {
  3820. currentStatus = Unavailable; //OCPP Status: Unavailable
  3821. }
  3822. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3823. {
  3824. currentStatus = Faulted; //OCPP Status: Faulted
  3825. }
  3826. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3827. {
  3828. currentStatus = Reserved; //OCPP Status: Reserved
  3829. }
  3830. }//end of the same index
  3831. }//end of for AC_QUANTITY
  3832. }
  3833. //it's option
  3834. if(strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL)
  3835. {
  3836. isStateChanged = FALSE;
  3837. }
  3838. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3839. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3840. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3841. random_uuid(guid);
  3842. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3843. , MESSAGE_TYPE_CALL
  3844. , guid
  3845. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3846. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3847. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3848. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3849. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3850. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3851. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3852. if((server_sign == TRUE) && isStateChanged)
  3853. {
  3854. LWS_Send(message);
  3855. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3856. 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*/)
  3857. {
  3858. //DEBUG_ERROR("statusNotification mapitem pass");
  3859. result = PASS;
  3860. }
  3861. }
  3862. else
  3863. {
  3864. result = PASS;
  3865. }
  3866. return result;
  3867. }
  3868. int sendStopTransactionRequest(int gun_index)
  3869. {
  3870. mtrace();
  3871. int result = FAIL;
  3872. //char message[1500]={0};
  3873. char guid[37]={0};
  3874. char tempdata[65]={0};
  3875. int tempIndex = 0;
  3876. char TempStopTransaction[256];
  3877. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3878. //int idx_sample=0;
  3879. DEBUG_INFO("sendStopTransactionRequest \n");
  3880. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3881. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3882. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3883. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3884. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3885. {
  3886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3887. {
  3888. tempIndex = ((gun_index==2) ? 1: 0);
  3889. }
  3890. else
  3891. {
  3892. tempIndex = gun_index;
  3893. }
  3894. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3895. {
  3896. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3897. {
  3898. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3899. }
  3900. }// END OF CHAdeMO_QUANTITY
  3901. }
  3902. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3903. {
  3904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3905. {
  3906. tempIndex = ((gun_index==2) ? 1: 0);
  3907. }
  3908. else
  3909. {
  3910. tempIndex = gun_index;
  3911. }
  3912. for (int index = 0; index < CCS_QUANTITY; index++)
  3913. {
  3914. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3915. {
  3916. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3917. }
  3918. }// END OF CCS_QUANTITY
  3919. }
  3920. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3921. {
  3922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3923. {
  3924. tempIndex = ((gun_index==2) ? 1: 0);
  3925. }
  3926. else
  3927. {
  3928. tempIndex = gun_index;
  3929. }
  3930. for (int index = 0; index < GB_QUANTITY; index++)
  3931. {
  3932. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3933. {
  3934. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3935. }
  3936. }// END OF GB_QUANTITY
  3937. }
  3938. else if(gunType[gun_index] == GUN_TYPE_DO)
  3939. {
  3940. tempIndex = gun_index;
  3941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3942. {
  3943. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3944. {
  3945. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3946. }
  3947. }// END OF GB_QUANTITY
  3948. }
  3949. else
  3950. {
  3951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3952. {
  3953. tempIndex = 2;
  3954. }
  3955. else
  3956. {
  3957. tempIndex = gun_index;
  3958. }
  3959. for (int index = 0; index < AC_QUANTITY; index++)
  3960. {
  3961. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3962. {
  3963. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3964. }
  3965. }// END OF AC_QUANTITY
  3966. }
  3967. //====================================== Stop Transaction Time =====================================================
  3968. struct timeval tmnow;
  3969. struct tm *tm;
  3970. char buf[28];//, usec_buf[6];
  3971. gettimeofday(&tmnow, NULL);
  3972. time_t t;
  3973. t = time(NULL);
  3974. /*UTC time and date*/
  3975. tm = gmtime(&t);
  3976. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3978. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3979. random_uuid(guid);
  3980. /***********************************transactionData******************************************************/
  3981. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3983. //=================================
  3984. // Transaction_Begin
  3985. //=================================
  3986. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3987. {
  3988. //============================================ Energy.Active.Import.Interval ================================
  3989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3992. 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*/]);
  3993. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3994. 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))
  3995. {
  3996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3997. }
  3998. else
  3999. {
  4000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4001. }
  4002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4004. }
  4005. //=================================
  4006. // Transaction_End
  4007. //=================================
  4008. // ================================= Current.Import L1 ===============================================
  4009. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4010. {
  4011. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4012. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4013. {
  4014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4015. {
  4016. tempIndex = ((gun_index==2) ? 1: 0);
  4017. }
  4018. else
  4019. {
  4020. tempIndex = gun_index;
  4021. }
  4022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4023. {
  4024. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4025. {
  4026. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4027. }
  4028. }// End of for CHAdeMO_QUANTITY
  4029. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4030. }
  4031. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4032. {
  4033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4034. {
  4035. tempIndex = ((gun_index==2) ? 1: 0);
  4036. }
  4037. else
  4038. {
  4039. tempIndex = gun_index;
  4040. }
  4041. for (int index = 0; index < CCS_QUANTITY; index++)
  4042. {
  4043. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4044. {
  4045. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4046. }
  4047. }// End of for CCS_QUANTITY
  4048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4049. }
  4050. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4051. {
  4052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4053. {
  4054. tempIndex = ((gun_index==2) ? 1: 0);
  4055. }
  4056. else
  4057. {
  4058. tempIndex = gun_index;
  4059. }
  4060. for (int index = 0; index < GB_QUANTITY; index++)
  4061. {
  4062. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4063. {
  4064. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4065. }
  4066. }// End of for GB_QUANTITY
  4067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4068. }
  4069. else if(gunType[gun_index] == GUN_TYPE_DO)
  4070. {
  4071. tempIndex = gun_index;
  4072. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4073. {
  4074. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4075. {
  4076. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4077. }
  4078. }
  4079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4080. }
  4081. else
  4082. {
  4083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4084. {
  4085. tempIndex = 2;
  4086. }
  4087. else
  4088. {
  4089. tempIndex = gun_index;
  4090. }
  4091. for (int index = 0; index < AC_QUANTITY; index++)
  4092. {
  4093. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4094. {
  4095. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4096. }
  4097. }// End of for AC_QUANTITY
  4098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4099. }
  4100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4105. }
  4106. // ================================= Energy.Active.Import.Interval ==============================================
  4107. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4108. {
  4109. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4110. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4111. {
  4112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4113. {
  4114. tempIndex = ((gun_index==2) ? 1: 0);
  4115. }
  4116. else
  4117. {
  4118. tempIndex = gun_index;
  4119. }
  4120. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4121. {
  4122. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4123. {
  4124. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4125. }
  4126. }// END OF CHAdeMO_QUANTITY
  4127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4128. }
  4129. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4130. {
  4131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4132. {
  4133. tempIndex = ((gun_index==2) ? 1: 0);
  4134. }
  4135. else
  4136. {
  4137. tempIndex = gun_index;
  4138. }
  4139. for (int index = 0; index < CCS_QUANTITY; index++)
  4140. {
  4141. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4142. {
  4143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4144. }
  4145. }// END OF CCS_QUANTITY
  4146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4147. }
  4148. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4149. {
  4150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4151. {
  4152. tempIndex = ((gun_index==2) ? 1: 0);
  4153. }
  4154. else
  4155. {
  4156. tempIndex = gun_index;
  4157. }
  4158. for (int index = 0; index < GB_QUANTITY; index++)
  4159. {
  4160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4161. {
  4162. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4163. }
  4164. }// END OF GB_QUANTITY
  4165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4166. }
  4167. else if(gunType[gun_index] == GUN_TYPE_DO)
  4168. {
  4169. tempIndex = gun_index;
  4170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4173. {
  4174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4175. }
  4176. }
  4177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4178. }
  4179. else
  4180. {
  4181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4182. {
  4183. tempIndex = 2;
  4184. }
  4185. else
  4186. {
  4187. tempIndex = gun_index;
  4188. }
  4189. for (int index = 0; index < AC_QUANTITY; index++)
  4190. {
  4191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4192. {
  4193. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4194. }
  4195. }// END OF AC_QUANTITY
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4197. }
  4198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4203. }
  4204. //=================================== Power.Active.Import ==================================================
  4205. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4206. {
  4207. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4208. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4209. {
  4210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4211. {
  4212. tempIndex = ((gun_index==2) ? 1: 0);
  4213. }
  4214. else
  4215. {
  4216. tempIndex = gun_index;
  4217. }
  4218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4219. {
  4220. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4221. {
  4222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4223. }
  4224. } // End for CHAdeMO_QUANTITY
  4225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4226. }
  4227. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4228. {
  4229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4230. {
  4231. tempIndex = ((gun_index==2) ? 1: 0);
  4232. }
  4233. else
  4234. {
  4235. tempIndex = gun_index;
  4236. }
  4237. for (int index = 0; index < CCS_QUANTITY; index++)
  4238. {
  4239. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4240. {
  4241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4242. }
  4243. } // END for CCS_QUANTITY
  4244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4245. }
  4246. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4247. {
  4248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4249. {
  4250. tempIndex = ((gun_index==2) ? 1: 0);
  4251. }
  4252. else
  4253. {
  4254. tempIndex = gun_index;
  4255. }
  4256. for (int index = 0; index < GB_QUANTITY; index++)
  4257. {
  4258. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4259. {
  4260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4261. }
  4262. }// END for GB_QUANTITY
  4263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4264. }
  4265. else if(gunType[gun_index] == GUN_TYPE_DO)
  4266. {
  4267. tempIndex = gun_index;
  4268. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4269. {
  4270. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4271. {
  4272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4273. }
  4274. }
  4275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4276. }
  4277. else
  4278. {
  4279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4280. {
  4281. tempIndex = 2;
  4282. }
  4283. else
  4284. {
  4285. tempIndex = gun_index;
  4286. }
  4287. for (int index = 0; index < AC_QUANTITY; index++)
  4288. {
  4289. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4290. {
  4291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4292. }
  4293. } // END for AC_QUANTITY
  4294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4295. }
  4296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4301. }
  4302. //============================ Voltage L1 ====================================
  4303. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4304. {
  4305. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4306. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4307. {
  4308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4309. {
  4310. tempIndex = ((gun_index==2) ? 1: 0);
  4311. }
  4312. else
  4313. {
  4314. tempIndex = gun_index;
  4315. }
  4316. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4317. {
  4318. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4319. {
  4320. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4321. }
  4322. } // END OF FOR CHAdeMO_QUANTITY
  4323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4324. }
  4325. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4326. {
  4327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4328. {
  4329. tempIndex = ((gun_index==2) ? 1: 0);
  4330. }
  4331. else
  4332. {
  4333. tempIndex = gun_index;
  4334. }
  4335. for (int index = 0; index < CCS_QUANTITY; index++)
  4336. {
  4337. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4338. {
  4339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4340. }
  4341. } // END OF FOR CCS_QUANTITY
  4342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4343. }
  4344. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4345. {
  4346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4347. {
  4348. tempIndex = ((gun_index==2) ? 1: 0);
  4349. }
  4350. else
  4351. {
  4352. tempIndex = gun_index;
  4353. }
  4354. for (int index = 0; index < GB_QUANTITY; index++)
  4355. {
  4356. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4357. {
  4358. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4359. }
  4360. } // END OF FOR GB_QUANTITY
  4361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4362. }
  4363. else if(gunType[gun_index] == GUN_TYPE_DO)
  4364. {
  4365. tempIndex = gun_index;
  4366. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4367. {
  4368. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4369. {
  4370. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4371. }
  4372. }
  4373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4374. }
  4375. else
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4378. {
  4379. tempIndex = 2;
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < AC_QUANTITY; index++)
  4386. {
  4387. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4388. {
  4389. 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
  4390. }
  4391. } // END OF FOR AC_QUANTITY
  4392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4393. }
  4394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4399. }
  4400. //====================== End SoC ================================
  4401. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4402. {
  4403. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4404. 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))
  4405. {
  4406. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4407. {
  4408. tempIndex = ((gun_index==2) ? 1: 0);
  4409. }
  4410. else
  4411. {
  4412. tempIndex = gun_index;
  4413. }
  4414. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4415. {
  4416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4417. {
  4418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4419. {
  4420. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4421. }
  4422. }
  4423. }
  4424. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4425. {
  4426. for (int index = 0; index < CCS_QUANTITY; index++)
  4427. {
  4428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4429. {
  4430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4431. }
  4432. }
  4433. }
  4434. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4435. {
  4436. for (int index = 0; index < GB_QUANTITY; index++)
  4437. {
  4438. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4439. {
  4440. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4441. }
  4442. }
  4443. }
  4444. else if(gunType[gun_index] == GUN_TYPE_DO)
  4445. {
  4446. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4447. {
  4448. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4449. {
  4450. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4451. }
  4452. }
  4453. }
  4454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4460. } // END FOR DC CASE
  4461. }
  4462. // ================================= Current.Import L2 ===============================================
  4463. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4464. {
  4465. // AC 3 phse L2 current
  4466. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4467. {
  4468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4469. {
  4470. tempIndex = 2;
  4471. }
  4472. else
  4473. {
  4474. tempIndex = gun_index;
  4475. }
  4476. for (int index = 0; index < AC_QUANTITY; index++)
  4477. {
  4478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4479. {
  4480. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4481. }
  4482. }// End of for AC_QUANTITY
  4483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4484. }
  4485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4490. }
  4491. // ================================= Current.Import L3 ===============================================
  4492. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4493. {
  4494. // AC 3 phse L3 current
  4495. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4496. {
  4497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4498. {
  4499. tempIndex = 2;
  4500. }
  4501. else
  4502. {
  4503. tempIndex = gun_index;
  4504. }
  4505. for (int index = 0; index < AC_QUANTITY; index++)
  4506. {
  4507. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4508. {
  4509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4510. }
  4511. }// End of for AC_QUANTITY
  4512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4513. }
  4514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4519. }
  4520. //============================ Voltage L2 ====================================
  4521. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4522. {
  4523. // AC 3 phse L2 voltage
  4524. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4525. {
  4526. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4527. {
  4528. tempIndex = 2;
  4529. }
  4530. else
  4531. {
  4532. tempIndex = gun_index;
  4533. }
  4534. for (int index = 0; index < AC_QUANTITY; index++)
  4535. {
  4536. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4537. {
  4538. 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
  4539. }
  4540. } // END OF FOR AC_QUANTITY
  4541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4542. }
  4543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4548. }
  4549. //============================ Voltage L3 ====================================
  4550. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4551. {
  4552. // AC 3 phse L3 voltage
  4553. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4554. {
  4555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4556. {
  4557. tempIndex = 2;
  4558. }
  4559. else
  4560. {
  4561. tempIndex = gun_index;
  4562. }
  4563. for (int index = 0; index < AC_QUANTITY; index++)
  4564. {
  4565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4566. {
  4567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4568. }
  4569. } // END OF FOR AC_QUANTITY
  4570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4571. }
  4572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4577. }
  4578. //====================== Start SoC ================================
  4579. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4580. {
  4581. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4582. 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))
  4583. {
  4584. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4585. {
  4586. tempIndex = ((gun_index==2) ? 1: 0);
  4587. }
  4588. else
  4589. {
  4590. tempIndex = gun_index;
  4591. }
  4592. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4593. {
  4594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4595. {
  4596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4597. {
  4598. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4599. }
  4600. }
  4601. }
  4602. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4603. {
  4604. for (int index = 0; index < CCS_QUANTITY; index++)
  4605. {
  4606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4607. {
  4608. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4609. }
  4610. }
  4611. }
  4612. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4613. {
  4614. for (int index = 0; index < GB_QUANTITY; index++)
  4615. {
  4616. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4617. {
  4618. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4619. }
  4620. }
  4621. }
  4622. else if(gunType[gun_index] == GUN_TYPE_DO)
  4623. {
  4624. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4625. {
  4626. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4627. {
  4628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4629. }
  4630. }
  4631. }
  4632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4638. } // END FOR DC CASE
  4639. }
  4640. //================================================ Message create ====================================================
  4641. json_object *StopTransaction = json_object_new_object();
  4642. json_object *transactionDatas = json_object_new_array();
  4643. json_object *sampledValues = json_object_new_array();
  4644. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4645. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4646. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4647. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4648. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4649. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4650. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4651. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4652. {
  4653. json_object *transactionData = json_object_new_object();
  4654. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4655. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4656. {
  4657. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4658. {
  4659. json_object *sampledValue = json_object_new_object();
  4660. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4661. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4662. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4663. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4664. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4665. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4666. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4667. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4668. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4669. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4670. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4671. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4672. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4673. json_object_array_add(sampledValues, sampledValue);
  4674. }
  4675. }
  4676. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4677. json_object_array_add(transactionDatas, transactionData);
  4678. }
  4679. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4680. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4681. ,MESSAGE_TYPE_CALL
  4682. ,guid
  4683. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4684. json_object_put(StopTransaction);
  4685. #if 1 // for TempStopTransaction
  4686. //Delete TempStopTransaction
  4687. if((access(TempStopTransaction,F_OK))!=-1)
  4688. {
  4689. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4690. }
  4691. #endif
  4692. #if 1
  4693. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4694. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4695. {
  4696. result = PASS;
  4697. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4698. }
  4699. #endif
  4700. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4701. OCPP_insert_transaction_msg(NO, queuedata);
  4702. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4703. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4704. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4705. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4706. {
  4707. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4708. }
  4709. //for test
  4710. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4711. return result;
  4712. }
  4713. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4714. {
  4715. mtrace();
  4716. int result = FAIL;
  4717. char guid[37]={0};
  4718. char tempdata[65]={0};
  4719. int tempIndex = 0;
  4720. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4721. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4722. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4723. //set value
  4724. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4725. 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) )?
  4726. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4727. -1);
  4728. random_uuid(guid);
  4729. //UTC Date time
  4730. struct timeval tmnow;
  4731. struct tm *tm;
  4732. char buf[28];//, usec_buf[6];
  4733. gettimeofday(&tmnow, NULL);
  4734. time_t t;
  4735. t = time(NULL);
  4736. /*UTC time and date*/
  4737. tm = gmtime(&t);
  4738. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4740. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4741. //********************************(1)Current.Import L1************************************************/
  4742. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4743. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4744. (dataType == ReadingContext_Trigger))
  4745. {
  4746. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4747. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4748. {
  4749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4750. {
  4751. tempIndex = ((gun_index==2) ? 1: 0);
  4752. }
  4753. else
  4754. {
  4755. tempIndex = gun_index;
  4756. }
  4757. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4758. {
  4759. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4760. {
  4761. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4762. }
  4763. }
  4764. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4765. }
  4766. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4767. {
  4768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4769. {
  4770. tempIndex = ((gun_index==2) ? 1: 0);
  4771. }
  4772. else
  4773. {
  4774. tempIndex = gun_index;
  4775. }
  4776. for (int index = 0; index < CCS_QUANTITY; index++)
  4777. {
  4778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4779. {
  4780. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4781. }
  4782. }
  4783. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4784. }
  4785. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4786. {
  4787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4788. {
  4789. tempIndex = ((gun_index==2) ? 1: 0);
  4790. }
  4791. else
  4792. {
  4793. tempIndex = gun_index;
  4794. }
  4795. for (int index = 0; index < GB_QUANTITY; index++)
  4796. {
  4797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4798. {
  4799. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4800. }
  4801. }
  4802. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4803. }
  4804. else if(gunType[gun_index] == GUN_TYPE_DO)
  4805. {
  4806. tempIndex = gun_index;
  4807. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4808. {
  4809. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4810. {
  4811. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4812. }
  4813. }
  4814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4815. }
  4816. else
  4817. {
  4818. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4819. {
  4820. tempIndex = 2;
  4821. }
  4822. else
  4823. {
  4824. tempIndex = gun_index;
  4825. }
  4826. for (int index = 0; index < AC_QUANTITY; index++)
  4827. {
  4828. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4829. {
  4830. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4831. }
  4832. }
  4833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4834. }
  4835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4840. }
  4841. //********************************(2)Energy.Active.Import.Register ************************************************/
  4842. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4843. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4844. (dataType == ReadingContext_Trigger))
  4845. {
  4846. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4847. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4848. {
  4849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4850. {
  4851. tempIndex = ((gun_index==2) ? 1: 0);
  4852. }
  4853. else
  4854. {
  4855. tempIndex = gun_index;
  4856. }
  4857. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4858. {
  4859. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4860. {
  4861. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4862. }
  4863. }
  4864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4865. }
  4866. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4867. {
  4868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4869. {
  4870. tempIndex = ((gun_index==2) ? 1: 0);
  4871. }
  4872. else
  4873. {
  4874. tempIndex = gun_index;
  4875. }
  4876. for (int index = 0; index < CCS_QUANTITY; index++)
  4877. {
  4878. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4879. {
  4880. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4881. }
  4882. }
  4883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4884. }
  4885. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4886. {
  4887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4888. {
  4889. tempIndex = ((gun_index==2) ? 1: 0);
  4890. }
  4891. else
  4892. {
  4893. tempIndex = gun_index;
  4894. }
  4895. for (int index = 0; index < GB_QUANTITY; index++)
  4896. {
  4897. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4898. {
  4899. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4900. }
  4901. }
  4902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4903. }
  4904. else if(gunType[gun_index] == GUN_TYPE_DO)
  4905. {
  4906. tempIndex = gun_index;
  4907. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4908. {
  4909. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4910. {
  4911. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4912. }
  4913. }
  4914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4915. }
  4916. else
  4917. {
  4918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4919. {
  4920. tempIndex = 2;
  4921. }
  4922. else
  4923. {
  4924. tempIndex = gun_index;
  4925. }
  4926. for (int index = 0; index < AC_QUANTITY; index++)
  4927. {
  4928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4929. {
  4930. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4931. }
  4932. }
  4933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4934. }
  4935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4940. }
  4941. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4942. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4943. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4944. (dataType == ReadingContext_Trigger))
  4945. {
  4946. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4947. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4948. {
  4949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4950. {
  4951. tempIndex = ((gun_index==2) ? 1: 0);
  4952. }
  4953. else
  4954. {
  4955. tempIndex = gun_index;
  4956. }
  4957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4958. {
  4959. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4960. {
  4961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4962. }
  4963. } // END OF FOR CHAdeMO_QUANTITY
  4964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4965. }
  4966. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4967. {
  4968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4969. {
  4970. tempIndex = ((gun_index==2) ? 1: 0);
  4971. }
  4972. else
  4973. {
  4974. tempIndex = gun_index;
  4975. }
  4976. for (int index = 0; index < CCS_QUANTITY; index++)
  4977. {
  4978. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4979. {
  4980. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4981. }
  4982. } // END OF CCS_QUANTITY
  4983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4984. }
  4985. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4986. {
  4987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4988. {
  4989. tempIndex = ((gun_index==2) ? 1: 0);
  4990. }
  4991. else
  4992. {
  4993. tempIndex = gun_index;
  4994. }
  4995. for (int index = 0; index < GB_QUANTITY; index++)
  4996. {
  4997. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4998. {
  4999. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5000. }
  5001. } // END OF GB_QUANTITY
  5002. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5003. }
  5004. else if(gunType[gun_index] == GUN_TYPE_DO)
  5005. {
  5006. tempIndex = gun_index;
  5007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5008. {
  5009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5010. {
  5011. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5012. }
  5013. }
  5014. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5015. }
  5016. else
  5017. {
  5018. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5019. {
  5020. tempIndex = 2;
  5021. }
  5022. else
  5023. {
  5024. tempIndex = gun_index;
  5025. }
  5026. for (int index = 0; index < AC_QUANTITY; index++)
  5027. {
  5028. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5029. {
  5030. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5031. }
  5032. }
  5033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5034. }
  5035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5040. }
  5041. //********************************(4)Power.Active.Import************************************************/
  5042. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5043. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5044. (dataType == ReadingContext_Trigger))
  5045. {
  5046. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5047. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5048. {
  5049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5050. {
  5051. tempIndex = ((gun_index==2) ? 1: 0);
  5052. }
  5053. else
  5054. {
  5055. tempIndex = gun_index;
  5056. }
  5057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5058. {
  5059. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5060. {
  5061. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5062. }
  5063. } // END OF FOR
  5064. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5065. }
  5066. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5067. {
  5068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5069. {
  5070. tempIndex = ((gun_index==2) ? 1: 0);
  5071. }
  5072. else
  5073. {
  5074. tempIndex = gun_index;
  5075. }
  5076. for (int index = 0; index < CCS_QUANTITY; index++)
  5077. {
  5078. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5079. {
  5080. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5081. }
  5082. }
  5083. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5084. }
  5085. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5086. {
  5087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5088. {
  5089. tempIndex = ((gun_index==2) ? 1: 0);
  5090. }
  5091. else
  5092. {
  5093. tempIndex = gun_index;
  5094. }
  5095. for (int index = 0; index < GB_QUANTITY; index++)
  5096. {
  5097. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5098. {
  5099. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5100. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5101. }
  5102. }
  5103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5104. }
  5105. else if(gunType[gun_index] == GUN_TYPE_DO)
  5106. {
  5107. tempIndex = gun_index;
  5108. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5109. {
  5110. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5111. {
  5112. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5113. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5114. }
  5115. }
  5116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5117. }
  5118. else
  5119. {
  5120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5121. {
  5122. tempIndex = 2;
  5123. }
  5124. else
  5125. {
  5126. tempIndex = gun_index;
  5127. }
  5128. for (int index = 0; index < AC_QUANTITY; index++)
  5129. {
  5130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5131. {
  5132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5133. }
  5134. }
  5135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5136. }
  5137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5142. }
  5143. //***********************************************(5)VOLTAGE L1******************************************************/
  5144. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5145. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5146. (dataType == ReadingContext_Trigger))
  5147. {
  5148. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5149. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5150. {
  5151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5152. {
  5153. tempIndex = ((gun_index==2) ? 1: 0);
  5154. }
  5155. else
  5156. {
  5157. tempIndex = gun_index;
  5158. }
  5159. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5160. {
  5161. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5162. {
  5163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5164. }
  5165. }
  5166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5167. }
  5168. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5169. {
  5170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5171. {
  5172. tempIndex = ((gun_index==2) ? 1: 0);
  5173. }
  5174. else
  5175. {
  5176. tempIndex = gun_index;
  5177. }
  5178. for (int index = 0; index < CCS_QUANTITY; index++)
  5179. {
  5180. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5181. {
  5182. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5183. }
  5184. }
  5185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5186. }
  5187. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5188. {
  5189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5190. {
  5191. tempIndex = ((gun_index==2) ? 1: 0);
  5192. }
  5193. else
  5194. {
  5195. tempIndex = gun_index;
  5196. }
  5197. for (int index = 0; index < GB_QUANTITY; index++)
  5198. {
  5199. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5200. {
  5201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5202. }
  5203. }
  5204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5205. }
  5206. else if(gunType[gun_index] == GUN_TYPE_DO)
  5207. {
  5208. tempIndex = gun_index;
  5209. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5210. {
  5211. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5212. {
  5213. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5214. }
  5215. }
  5216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5217. }
  5218. else
  5219. {
  5220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5221. {
  5222. tempIndex = 2;
  5223. }
  5224. else
  5225. {
  5226. tempIndex = gun_index;
  5227. }
  5228. for (int index = 0; index < AC_QUANTITY; index++)
  5229. {
  5230. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5231. {
  5232. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5233. }
  5234. }
  5235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5236. }
  5237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5242. }
  5243. //***********************************************(6)SOC******************************************************/
  5244. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5245. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5246. (dataType == ReadingContext_Trigger))
  5247. {
  5248. 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))
  5249. {
  5250. //idx_sample=5;
  5251. //sampledValue = NULL;
  5252. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5253. {
  5254. tempIndex = ((gun_index==2) ? 1: 0);
  5255. }
  5256. else
  5257. {
  5258. tempIndex = gun_index;
  5259. }
  5260. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5261. {
  5262. //tempIndex = ((gun_index==2) ? 1: 0);
  5263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5264. {
  5265. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5266. {
  5267. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5268. }
  5269. }
  5270. }
  5271. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5272. {
  5273. //tempIndex = ((gun_index==2) ? 1: 0);
  5274. for (int index = 0; index < CCS_QUANTITY; index++)
  5275. {
  5276. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5277. {
  5278. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5279. }
  5280. }
  5281. }
  5282. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5283. {
  5284. //tempIndex = ((gun_index==2) ? 1: 0);
  5285. for (int index = 0; index < GB_QUANTITY; index++)
  5286. {
  5287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5288. {
  5289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5290. }
  5291. }
  5292. }
  5293. else if(gunType[gun_index] == GUN_TYPE_DO)
  5294. {
  5295. //tempIndex = ((gun_index==2) ? 1: 0);
  5296. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5297. {
  5298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5299. {
  5300. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5301. }
  5302. }
  5303. }
  5304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5305. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5310. }
  5311. }
  5312. //********************************(7)Current.Import L2************************************************/
  5313. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5314. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5315. (dataType == ReadingContext_Trigger))
  5316. {
  5317. // Only for AC 3 phase
  5318. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5319. {
  5320. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5321. {
  5322. tempIndex = 2;
  5323. }
  5324. else
  5325. {
  5326. tempIndex = gun_index;
  5327. }
  5328. for (int index = 0; index < AC_QUANTITY; index++)
  5329. {
  5330. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5331. {
  5332. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5333. }
  5334. }
  5335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5336. }
  5337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5342. }
  5343. //********************************(8)Current.Import L3************************************************/
  5344. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5345. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5346. (dataType == ReadingContext_Trigger))
  5347. {
  5348. // Only for AC 3 phase
  5349. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5350. {
  5351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5352. {
  5353. tempIndex = 2;
  5354. }
  5355. else
  5356. {
  5357. tempIndex = gun_index;
  5358. }
  5359. for (int index = 0; index < AC_QUANTITY; index++)
  5360. {
  5361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5362. {
  5363. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5364. }
  5365. }
  5366. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5367. }
  5368. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5369. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5372. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5373. }
  5374. //***********************************************(9)VOLTAGE L2******************************************************/
  5375. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5376. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5377. (dataType == ReadingContext_Trigger))
  5378. {
  5379. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5380. {
  5381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5382. {
  5383. tempIndex = 2;
  5384. }
  5385. else
  5386. {
  5387. tempIndex = gun_index;
  5388. }
  5389. for (int index = 0; index < AC_QUANTITY; index++)
  5390. {
  5391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5392. {
  5393. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5394. }
  5395. }
  5396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5397. }
  5398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5403. }
  5404. //***********************************************(10)VOLTAGE L3******************************************************/
  5405. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5406. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5407. (dataType == ReadingContext_Trigger))
  5408. {
  5409. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5410. {
  5411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5412. {
  5413. tempIndex = 2;
  5414. }
  5415. else
  5416. {
  5417. tempIndex = gun_index;
  5418. }
  5419. for (int index = 0; index < AC_QUANTITY; index++)
  5420. {
  5421. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5422. {
  5423. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5424. }
  5425. }
  5426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5427. }
  5428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5433. }
  5434. // Message create ====================================================================================================
  5435. if(TRUE)
  5436. {
  5437. json_object *MeterValueReq = json_object_new_object();
  5438. json_object *MeterValues = json_object_new_array();
  5439. json_object *sampledValues = json_object_new_array();
  5440. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5441. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5442. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5443. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5444. {
  5445. json_object *MeterValue = json_object_new_object();
  5446. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5447. {
  5448. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5449. {
  5450. json_object *sampledValue = json_object_new_object();
  5451. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5452. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5453. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5454. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5455. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5456. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5457. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5458. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5459. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5460. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5461. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5462. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5463. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5464. json_object_array_add(sampledValues, sampledValue);
  5465. }
  5466. }
  5467. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5468. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5469. json_object_array_add(MeterValues, MeterValue);
  5470. }
  5471. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5472. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5473. ,gun_index + 1
  5474. ,MESSAGE_TYPE_CALL
  5475. ,guid
  5476. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5477. json_object_put(MeterValueReq);
  5478. }
  5479. // Put request guid to hash map
  5480. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5481. 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*/)
  5482. {
  5483. result = PASS;
  5484. //DEBUG_INFO("MeterValues mapitem pass\n");
  5485. }
  5486. if((dataType != ReadingContext_Trigger) &&
  5487. (dataType != ReadingContext_Sample_Clock) &&
  5488. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5489. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5490. else
  5491. {
  5492. if(FirstHeartBeat)
  5493. LWS_Send(queuedata +2);
  5494. }
  5495. return result;
  5496. }
  5497. int sendLogStatusNotificationRequest(char *status)
  5498. {
  5499. mtrace();
  5500. int result = PASS;
  5501. char message[4096]={0};
  5502. char guid[37]={0};
  5503. char tempdata[128]={0};
  5504. json_object *LogStatusNotification = json_object_new_object();
  5505. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5506. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5507. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5508. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5509. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5510. random_uuid(guid);
  5511. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5512. json_object_put(LogStatusNotification);
  5513. LWS_Send(message);
  5514. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5515. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5516. {
  5517. result = PASS;
  5518. }
  5519. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5520. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5521. return result;
  5522. }
  5523. int sendSecurityEventNotificationRequest()
  5524. {
  5525. mtrace();
  5526. int result = PASS;
  5527. char message[4096]={0};
  5528. char guid[37]={0};
  5529. char tempdata[128]={0};
  5530. json_object *SecurityEventNotification = json_object_new_object();
  5531. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5532. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5533. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5534. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5535. random_uuid(guid);
  5536. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5537. json_object_put(SecurityEventNotification);
  5538. LWS_Send(message);
  5539. sprintf(tempdata, "SecurityEventNotification,0");
  5540. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5541. {
  5542. result = PASS;
  5543. }
  5544. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5545. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5546. return result;
  5547. }
  5548. int sendSignCertificateRequest()
  5549. {
  5550. mtrace();
  5551. int result = PASS;
  5552. char message[4096]={0};
  5553. char guid[37]={0};
  5554. char tempdata[128]={0};
  5555. json_object *SignCertificate = json_object_new_object();
  5556. DEBUG_INFO("sendSignCertificateRequest...\n");
  5557. // Read csr file content
  5558. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5559. FILE *fp=fopen("/Storage/OCPP/cert.csr","r");
  5560. char *line = NULL;
  5561. size_t len = 0;
  5562. while(getline(&line, &len, fp) != -1)
  5563. {
  5564. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5565. {
  5566. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5567. }
  5568. }
  5569. fclose(fp);
  5570. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5571. random_uuid(guid);
  5572. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5573. json_object_put(SignCertificate);
  5574. LWS_Send(message);
  5575. sprintf(tempdata, "SignCertificate,0");
  5576. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5577. {
  5578. result = PASS;
  5579. }
  5580. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5581. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5582. return result;
  5583. }
  5584. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5585. {
  5586. mtrace();
  5587. int result = PASS;
  5588. char message[110]={0};
  5589. char guid[37]={0};
  5590. char tempdata[65]={0};
  5591. json_object *FirmwareStatusNotification = json_object_new_object();
  5592. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5593. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5594. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5595. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5596. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5597. random_uuid(guid);
  5598. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5599. json_object_put(FirmwareStatusNotification);
  5600. LWS_Send(message);
  5601. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5602. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5603. {
  5604. result = PASS;
  5605. }
  5606. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5607. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5608. return result;
  5609. }
  5610. //==========================================
  5611. // send confirm routine
  5612. //==========================================
  5613. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5614. {
  5615. mtrace();
  5616. int result = FAIL;
  5617. char message[100]={0};
  5618. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5619. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5620. LWS_Send(message);
  5621. result = TRUE;
  5622. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5623. return result;
  5624. }
  5625. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5626. {
  5627. mtrace();
  5628. int result = FAIL;
  5629. char message[100]={0};
  5630. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5631. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5632. LWS_Send(message);
  5633. result = TRUE;
  5634. return result;
  5635. }
  5636. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5637. {
  5638. mtrace();
  5639. int result = FAIL;
  5640. char message[100]={0};
  5641. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5642. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5643. LWS_Send(message);
  5644. result = TRUE;
  5645. return result;
  5646. }
  5647. int sendClearCacheConfirmation(char *uuid,char *payload)
  5648. {
  5649. mtrace();
  5650. int result = FAIL;
  5651. char message[500]={0};
  5652. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5653. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5654. LWS_Send(message);
  5655. return result;
  5656. }
  5657. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5658. {
  5659. mtrace();
  5660. int result = FAIL;
  5661. char message[500]={0};
  5662. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5663. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5664. LWS_Send(message);
  5665. return result;
  5666. }
  5667. int sendDataTransferConfirmation(char *uuid,char *payload)
  5668. {
  5669. mtrace();
  5670. char statusStr[20]={0};
  5671. char dataStr[10]={0};
  5672. char sstr[20]={0};
  5673. int c = 0;
  5674. char *loc;
  5675. int result = FAIL;
  5676. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5677. /**********************status**************************/
  5678. loc = strstr(payload, "status");
  5679. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5680. c = 0;
  5681. while (loc[3+strlen("status")+c] != '\"')
  5682. {
  5683. sstr[c] = loc[3+strlen("status")+c];
  5684. c++;
  5685. }
  5686. sstr[c] = '\0';
  5687. strcpy(statusStr, sstr);
  5688. /**********************data**************************/
  5689. loc = strstr(payload, "data");
  5690. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5691. c = 0;
  5692. while (loc[3+strlen("data")+c] != '\"')
  5693. {
  5694. sstr[c] = loc[3+strlen("data")+c];
  5695. c++;
  5696. }
  5697. sstr[c] = '\0';
  5698. strcpy(dataStr, sstr);
  5699. return result;
  5700. }
  5701. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5702. {
  5703. mtrace();
  5704. int result = FAIL;
  5705. char message[1000]={0};
  5706. int CompositeScheduleIndex = 0;
  5707. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5708. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5709. if(nPeriod == 0)
  5710. {
  5711. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5712. {
  5713. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5714. ,MESSAGE_TYPE_CALLRESULT
  5715. ,uuid
  5716. ,payload
  5717. ,connectorIdInt);
  5718. }
  5719. else
  5720. {
  5721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5722. ,MESSAGE_TYPE_CALLRESULT
  5723. ,uuid
  5724. ,payload
  5725. ,connectorIdInt
  5726. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5727. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5728. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5729. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5730. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5731. }
  5732. }
  5733. else
  5734. {
  5735. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5736. ,MESSAGE_TYPE_CALLRESULT
  5737. ,uuid
  5738. ,payload
  5739. ,connectorIdInt
  5740. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5741. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5742. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5743. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5744. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5745. {
  5746. if (idx_sample == 0)
  5747. {
  5748. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5749. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5750. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5751. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5752. }
  5753. else
  5754. {
  5755. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5756. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5757. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5758. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5759. }
  5760. }
  5761. sprintf(message + strlen(message), "]}}]");
  5762. }
  5763. LWS_Send(message);
  5764. result = TRUE;
  5765. return result;
  5766. }
  5767. int sendGetConfigurationConfirmation(char *uuid)
  5768. {
  5769. mtrace();
  5770. int result = FAIL;
  5771. int MaxKeySupported = 0;
  5772. int sentConfigurationNumber= 0;
  5773. int sentunConfigurationNumber= 0;
  5774. char message[4000]={0};
  5775. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5776. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5777. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5778. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5779. ,MESSAGE_TYPE_CALLRESULT
  5780. ,uuid );
  5781. //configuration key
  5782. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5783. {
  5784. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5785. {
  5786. if (sentConfigurationNumber == 0)
  5787. {
  5788. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5789. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5790. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5791. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5792. }
  5793. else
  5794. {
  5795. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5796. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5797. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5798. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5799. }
  5800. sentConfigurationNumber = sentConfigurationNumber + 1;
  5801. }
  5802. }
  5803. sprintf(message + strlen(message), "]");
  5804. if(UnknownKeynum != 0)
  5805. {
  5806. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5807. //unkown key
  5808. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5809. {
  5810. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5811. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5812. if(sentunConfigurationNumber == 0)
  5813. {
  5814. sprintf(message + strlen(message), "\"%s\""
  5815. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5816. }
  5817. else
  5818. {
  5819. sprintf(message + strlen(message), ",\"%s\""
  5820. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5821. }
  5822. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5823. }
  5824. sprintf(message + strlen(message), "]");
  5825. }
  5826. sprintf(message + strlen(message), "}]");
  5827. LWS_Send(message);
  5828. return result;
  5829. }
  5830. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5831. {
  5832. mtrace();
  5833. int result = FAIL;
  5834. char message[400]={0};
  5835. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5836. if(strcmp(payload,"")==0)
  5837. {
  5838. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5839. }
  5840. else
  5841. {
  5842. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5843. }
  5844. LWS_Send(message);
  5845. result = TRUE;
  5846. return result;
  5847. }
  5848. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5849. {
  5850. mtrace();
  5851. int result = FAIL;
  5852. char message[80]={0};
  5853. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5854. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5855. LWS_Send(message);
  5856. result = TRUE;
  5857. return result;
  5858. }
  5859. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5860. {
  5861. mtrace();
  5862. int result = FAIL;
  5863. char message[80]={0};
  5864. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5865. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5866. LWS_Send(message);
  5867. result = TRUE;
  5868. return result;
  5869. }
  5870. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5871. {
  5872. mtrace();
  5873. int result = FAIL;
  5874. char message[80]={0};
  5875. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5876. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5877. LWS_Send(message);
  5878. result = TRUE;
  5879. return result;
  5880. }
  5881. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5882. {
  5883. mtrace();
  5884. int result = FAIL;
  5885. char message[80]={0};
  5886. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5887. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5888. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5889. LWS_Send(message);
  5890. result = TRUE;
  5891. return result;
  5892. }
  5893. int sendResetConfirmation(char *uuid,char *payload)
  5894. {
  5895. mtrace();
  5896. int result = FAIL;
  5897. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5898. char message[80]={0};
  5899. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5900. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5901. LWS_Send(message);
  5902. result = TRUE;
  5903. return result;
  5904. }
  5905. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5906. {
  5907. mtrace();
  5908. int result = FAIL;
  5909. char message[500]={0};
  5910. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5911. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5912. LWS_Send(message);
  5913. result = TRUE;
  5914. return result;
  5915. }
  5916. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5917. {
  5918. mtrace();
  5919. int result = FAIL;
  5920. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5921. char message[80]={0};
  5922. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5923. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5924. LWS_Send(message);
  5925. result = TRUE;
  5926. return result;
  5927. }
  5928. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5929. {
  5930. mtrace();
  5931. int result = FAIL;
  5932. char message[80]={0};
  5933. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5934. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5935. LWS_Send(message);
  5936. result = TRUE;
  5937. return result;
  5938. }
  5939. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5940. {
  5941. mtrace();
  5942. int result = FAIL;
  5943. char message[80]={0};
  5944. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5945. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5946. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5947. LWS_Send(message);
  5948. result = TRUE;
  5949. return result;
  5950. }
  5951. int sendUpdateFirmwareConfirmation(char *uuid)
  5952. {
  5953. mtrace();
  5954. int result = FAIL;
  5955. char message[60]={0};
  5956. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5957. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5958. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5959. LWS_Send(message);
  5960. result = TRUE;
  5961. return result;
  5962. }
  5963. int sendCertificateSignedConfirmation(char *uuid)
  5964. {
  5965. mtrace();
  5966. int result = PASS;
  5967. char message[4096]={0};
  5968. json_object *CertificateSigned = json_object_new_object();
  5969. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  5970. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  5971. sprintf(message,"[%d,\"%s\",%s]"
  5972. ,MESSAGE_TYPE_CALLRESULT
  5973. ,uuid
  5974. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  5975. json_object_put(CertificateSigned);
  5976. LWS_Send(message);
  5977. return result;
  5978. }
  5979. int sendDeleteCertificateConfirmation(char *uuid)
  5980. {
  5981. mtrace();
  5982. int result = PASS;
  5983. char message[4096]={0};
  5984. json_object *DeleteCertificate = json_object_new_object();
  5985. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  5986. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  5987. sprintf(message,"[%d,\"%s\",%s]"
  5988. ,MESSAGE_TYPE_CALLRESULT
  5989. ,uuid
  5990. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  5991. json_object_put(DeleteCertificate);
  5992. LWS_Send(message);
  5993. return result;
  5994. }
  5995. int sendExtendedTriggerMessageConfirmation(char *uuid)
  5996. {
  5997. mtrace();
  5998. int result = PASS;
  5999. char message[4096]={0};
  6000. json_object *ExtendedTriggerMessage = json_object_new_object();
  6001. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6002. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6003. sprintf(message,"[%d,\"%s\",%s]"
  6004. ,MESSAGE_TYPE_CALLRESULT
  6005. ,uuid
  6006. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6007. json_object_put(ExtendedTriggerMessage);
  6008. LWS_Send(message);
  6009. return result;
  6010. }
  6011. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6012. {
  6013. mtrace();
  6014. int result = PASS;
  6015. char message[4096]={0};
  6016. json_object *GetInstalledCertificateIds = json_object_new_object();
  6017. json_object *certificateHashDataDatas = json_object_new_array();
  6018. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6019. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6020. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6021. {
  6022. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6023. {
  6024. json_object *certificateHashData = json_object_new_object();
  6025. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6026. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6027. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6028. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6029. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6030. }
  6031. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6032. }
  6033. else
  6034. {
  6035. json_object_put(certificateHashDataDatas);
  6036. }
  6037. sprintf(message,"[%d,\"%s\",%s]"
  6038. ,MESSAGE_TYPE_CALLRESULT
  6039. ,uuid
  6040. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6041. json_object_put(GetInstalledCertificateIds);
  6042. LWS_Send(message);
  6043. return result;
  6044. }
  6045. int sendGetLogConfirmation(char *uuid)
  6046. {
  6047. mtrace();
  6048. int result = PASS;
  6049. char message[4096]={0};
  6050. json_object *GetLog = json_object_new_object();
  6051. DEBUG_INFO("sendGetLogConfirmation...\n");
  6052. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6053. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6054. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6055. sprintf(message,"[%d,\"%s\",%s]"
  6056. ,MESSAGE_TYPE_CALLRESULT
  6057. ,uuid
  6058. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6059. json_object_put(GetLog);
  6060. LWS_Send(message);
  6061. return result;
  6062. }
  6063. int sendInstallCertificateConfirmation(char *uuid)
  6064. {
  6065. mtrace();
  6066. int result = PASS;
  6067. char message[4096]={0};
  6068. json_object *InstallCertificate = json_object_new_object();
  6069. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6070. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6071. sprintf(message,"[%d,\"%s\",%s]"
  6072. ,MESSAGE_TYPE_CALLRESULT
  6073. ,uuid
  6074. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6075. json_object_put(InstallCertificate);
  6076. LWS_Send(message);
  6077. return result;
  6078. }
  6079. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6080. {
  6081. mtrace();
  6082. int result = PASS;
  6083. char message[4096]={0};
  6084. json_object *SignedUpdateFirmware = json_object_new_object();
  6085. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6086. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6087. sprintf(message,"[%d,\"%s\",%s]"
  6088. ,MESSAGE_TYPE_CALLRESULT
  6089. ,uuid
  6090. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6091. json_object_put(SignedUpdateFirmware);
  6092. LWS_Send(message);
  6093. return result;
  6094. }
  6095. int sendUnknownConfirmation(char *uuid)
  6096. {
  6097. mtrace();
  6098. int result = PASS;
  6099. char message[256]={0};
  6100. DEBUG_INFO("sendUnknownConfirmation...\n");
  6101. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6102. LWS_Send(message);
  6103. return result;
  6104. }
  6105. //==========================================
  6106. // Handle server request routine Start
  6107. //==========================================
  6108. int handleCancelReservationRequest(char *uuid, char *payload)
  6109. {
  6110. mtrace();
  6111. int result = FAIL;
  6112. int gunNO = 0;
  6113. int reservationIdInt = -1;
  6114. char comfirmstr[20];
  6115. DEBUG_INFO("handleCancelReservationRequest...\n");
  6116. json_object *CancelReservation;
  6117. CancelReservation = json_tokener_parse(payload);
  6118. if(!is_error(CancelReservation))
  6119. {
  6120. // Required data
  6121. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6122. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6123. }
  6124. json_object_put(CancelReservation);
  6125. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6126. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6127. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6128. if(reservationIdInt != -1)
  6129. {
  6130. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6131. //check Transaction active
  6132. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6134. {
  6135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6136. {
  6137. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6138. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6139. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6140. {
  6141. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6142. }
  6143. else
  6144. {
  6145. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6146. }
  6147. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6148. goto end;
  6149. }
  6150. }
  6151. for (int index = 0; index < CCS_QUANTITY; index++)
  6152. {
  6153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6154. {
  6155. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6156. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6157. if(gunType[2] == GUN_TYPE_CCS)
  6158. {
  6159. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6160. }
  6161. else
  6162. {
  6163. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6164. }
  6165. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6166. goto end;
  6167. }
  6168. }
  6169. for (int index = 0; index < GB_QUANTITY; index++)
  6170. {
  6171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6172. {
  6173. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6174. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6175. if(gunType[2] == GUN_TYPE_GBT)
  6176. {
  6177. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6178. }
  6179. else
  6180. {
  6181. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6182. }
  6183. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6184. goto end;
  6185. }
  6186. }
  6187. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6188. {
  6189. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6190. {
  6191. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6192. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6193. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6194. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6195. goto end;
  6196. }
  6197. }
  6198. for (int index = 0; index < AC_QUANTITY; index++)
  6199. {
  6200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6201. {
  6202. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6203. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6205. {
  6206. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6207. }
  6208. else
  6209. {
  6210. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6211. }
  6212. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6213. goto end;
  6214. }
  6215. }
  6216. }
  6217. //The reservationId does NOT match the reservationId
  6218. sendCancelReservationConfirmation(uuid, comfirmstr);
  6219. end:
  6220. // Fill in ocpp packet uuid
  6221. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6222. return result;
  6223. }
  6224. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6225. {
  6226. mtrace();
  6227. int result = FAIL;
  6228. int gunIndex = 0;
  6229. char typeStr[16]={0};
  6230. char comfirmstr[20];
  6231. int specificId = FALSE;
  6232. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6233. json_object *ChangeAvailability;
  6234. ChangeAvailability = json_tokener_parse(payload);
  6235. if(!is_error(ChangeAvailability))
  6236. {
  6237. // Required data
  6238. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6239. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6240. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6241. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6242. }
  6243. json_object_put(ChangeAvailability);
  6244. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6245. {
  6246. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6247. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6248. }
  6249. else if(gunIndex == 0)
  6250. {
  6251. for(int i=0; i < gunTotalNumber; i++)
  6252. {
  6253. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6254. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6255. }
  6256. }
  6257. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6258. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6259. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6260. {
  6261. specificId = TRUE;
  6262. }
  6263. if(specificId == FALSE)
  6264. goto end;
  6265. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6266. {
  6267. //----------------------gunIndex is 0 ------------------------------------------------//
  6268. if(gunIndex == 0)
  6269. {
  6270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6271. {
  6272. for(int i=0; i < gunTotalNumber; i++)
  6273. {
  6274. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6275. {
  6276. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6277. {
  6278. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6279. {
  6280. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6281. goto end;
  6282. }
  6283. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6284. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6285. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6286. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6287. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6288. {
  6289. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6290. goto end;
  6291. }
  6292. }
  6293. }//END FOR CHAdeMO_QUANTITY
  6294. for (int index = 0; index < CCS_QUANTITY; index++)
  6295. {
  6296. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6297. {
  6298. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6299. {
  6300. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6301. goto end;
  6302. }
  6303. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6304. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6305. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6307. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6308. {
  6309. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6310. goto end;
  6311. }
  6312. }
  6313. }//END FOR CCS_QUANTITY
  6314. for (int index = 0; index < GB_QUANTITY; index++)
  6315. {
  6316. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6317. {
  6318. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6319. {
  6320. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6321. goto end;
  6322. }
  6323. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6324. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6325. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6326. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6327. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6328. {
  6329. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6330. goto end;
  6331. }
  6332. }
  6333. }// END FOR GB_QUANTITY
  6334. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6335. {
  6336. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6337. {
  6338. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6339. {
  6340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6341. goto end;
  6342. }
  6343. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6344. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6345. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6346. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6347. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6348. {
  6349. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6350. goto end;
  6351. }
  6352. }
  6353. }// END FOR GENERAL_GUN_QUANTITY
  6354. for (int index = 0; index < AC_QUANTITY; index++)
  6355. {
  6356. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6357. {
  6358. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6359. {
  6360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6361. goto end;
  6362. }
  6363. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6364. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6365. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6366. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6367. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6368. {
  6369. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6370. goto end;
  6371. }
  6372. }
  6373. }//END FOR AC_QUANTITY
  6374. }// END FOR gunTotalNumber
  6375. }
  6376. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6377. {
  6378. for(int i=0; i < gunTotalNumber; i++)
  6379. {
  6380. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6381. {
  6382. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6383. goto end;
  6384. }
  6385. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6386. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6387. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6388. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6389. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6390. {
  6391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6392. goto end;
  6393. }
  6394. }
  6395. }
  6396. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6397. goto end;
  6398. }
  6399. //----------------------gunIndex is not 0 ------------------------------------------------//
  6400. //check Transaction active
  6401. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6402. {
  6403. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6404. {
  6405. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6406. {
  6407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6408. goto end;
  6409. }
  6410. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6411. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6412. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6413. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6414. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6415. {
  6416. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6417. goto end;
  6418. }
  6419. else
  6420. {
  6421. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6423. goto end;
  6424. }
  6425. }
  6426. }//END FOR CHAdeMO_QUANTITY
  6427. for (int index = 0; index < CCS_QUANTITY; index++)
  6428. {
  6429. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6430. {
  6431. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6432. {
  6433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6434. goto end;
  6435. }
  6436. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6437. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6438. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6439. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6440. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6441. {
  6442. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6443. goto end;
  6444. }
  6445. else
  6446. {
  6447. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6449. goto end;
  6450. }
  6451. }
  6452. }//END FOR CCS_QUANTITY
  6453. for (int index = 0; index < GB_QUANTITY; index++)
  6454. {
  6455. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6456. {
  6457. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6458. {
  6459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6460. goto end;
  6461. }
  6462. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6463. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6464. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6465. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6466. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6467. {
  6468. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6469. goto end;
  6470. }
  6471. else
  6472. {
  6473. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6474. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6475. goto end;
  6476. }
  6477. }
  6478. }// END FOR GB_QUANTITY
  6479. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6480. {
  6481. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6482. {
  6483. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6484. {
  6485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6486. goto end;
  6487. }
  6488. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6489. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6490. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6491. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6492. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6493. {
  6494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6495. goto end;
  6496. }
  6497. else
  6498. {
  6499. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6501. goto end;
  6502. }
  6503. }
  6504. }// END FOR GENERAL_GUN_QUANTITY
  6505. for (int index = 0; index < AC_QUANTITY; index++)
  6506. {
  6507. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6508. {
  6509. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6510. {
  6511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6512. goto end;
  6513. }
  6514. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6515. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6516. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6517. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6518. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6519. {
  6520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6521. goto end;
  6522. }
  6523. else
  6524. {
  6525. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6527. goto end;
  6528. }
  6529. }
  6530. }//END FOR AC_QUANTITY
  6531. }//END FOR AvailabilityTypeStr[Inoperative]
  6532. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6533. {
  6534. //----------------------gunIndex is 0 ------------------------------------------------//
  6535. if(gunIndex == 0)
  6536. {
  6537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6538. {
  6539. for(int i=0; i < gunTotalNumber; i++)
  6540. {
  6541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6542. {
  6543. 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
  6544. {
  6545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6546. goto end;
  6547. }
  6548. }//END FOR CHAdeMO_QUANTITY
  6549. for (int index = 0; index < CCS_QUANTITY; index++)
  6550. {
  6551. 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
  6552. {
  6553. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6554. goto end;
  6555. }
  6556. }//END FOR CCS_QUANTITY
  6557. for (int index = 0; index < GB_QUANTITY; index++)
  6558. {
  6559. 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
  6560. {
  6561. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6562. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6563. goto end;
  6564. }
  6565. }// END FOR GB_QUANTITY
  6566. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6567. {
  6568. 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
  6569. {
  6570. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6572. goto end;
  6573. }
  6574. }// END FOR GENERAL_GUN_QUANTITY
  6575. for (int index = 0; index < AC_QUANTITY; index++)
  6576. {
  6577. 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
  6578. {
  6579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6580. goto end;
  6581. }
  6582. }//END FOR CHAdeMO_QUANTITY
  6583. }// END FOR gunTotalNumber
  6584. }
  6585. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6586. {
  6587. for(int i=0; i < gunTotalNumber; i++)
  6588. {
  6589. for (int index = 0; index < AC_QUANTITY; index++)
  6590. {
  6591. 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
  6592. {
  6593. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6594. goto end;
  6595. }
  6596. }//END FOR CHAdeMO_QUANTITY
  6597. } // END FOR gunTotalNumber
  6598. }
  6599. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6600. goto end;
  6601. }
  6602. //----------------------gunIndex is not 0 ------------------------------------------------//
  6603. //check Transaction active
  6604. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6605. {
  6606. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6607. {
  6608. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6609. goto end;
  6610. }
  6611. }//END FOR CHAdeMO_QUANTITY
  6612. for (int index = 0; index < CCS_QUANTITY; index++)
  6613. {
  6614. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6615. {
  6616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6617. goto end;
  6618. }
  6619. }//END FOR CCS_QUANTITY
  6620. for (int index = 0; index < GB_QUANTITY; index++)
  6621. {
  6622. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6623. {
  6624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6625. goto end;
  6626. }
  6627. }// END FOR GB_QUANTITY
  6628. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6629. {
  6630. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6631. {
  6632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6633. goto end;
  6634. }
  6635. }// END FOR GENERAL_GUN_QUANTITY
  6636. for (int index = 0; index < AC_QUANTITY; index++)
  6637. {
  6638. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6639. {
  6640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6641. goto end;
  6642. }
  6643. }//END FOR AC_QUANTITY
  6644. }//END FOR AvailabilityTypeStr[Operative]
  6645. end:
  6646. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6647. {
  6648. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6649. }
  6650. else
  6651. {
  6652. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6653. }
  6654. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6655. {
  6656. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6657. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6658. }
  6659. else if(gunIndex == 0)
  6660. {
  6661. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6662. {
  6663. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6664. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6665. }
  6666. }
  6667. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6668. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6669. return result;
  6670. }
  6671. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6672. {
  6673. mtrace();
  6674. int result = FAIL;
  6675. char keystr[40]={0};
  6676. char valuestr[256]={0};
  6677. char comfirmstr[20]={0};
  6678. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6679. json_object *ChangeConfiguration;
  6680. ChangeConfiguration = json_tokener_parse(payload);
  6681. if(!is_error(ChangeConfiguration))
  6682. {
  6683. // Required data
  6684. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6685. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6686. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6687. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6688. }
  6689. json_object_put(ChangeConfiguration);
  6690. if((uuid==NULL) || (payload ==NULL) )
  6691. {
  6692. DEBUG_ERROR("Payload is null\n");
  6693. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6694. }
  6695. else
  6696. {
  6697. int status = setKeyValue(keystr, valuestr);
  6698. switch(status)
  6699. {
  6700. case ConfigurationStatus_Accepted:
  6701. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6702. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6703. StoreConfigurationTable();
  6704. break;
  6705. case RebootRequired:
  6706. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6707. StoreConfigurationTable();
  6708. break;
  6709. case NotSupported:
  6710. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6711. break;
  6712. case ConfigurationStatus_Rejected:
  6713. default:
  6714. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6715. break;
  6716. }
  6717. }
  6718. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6719. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6720. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6721. {
  6722. ChageWebSocketPingInterval(atoi(valuestr));
  6723. }
  6724. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6725. {
  6726. SetOcppConnStatus(FALSE);
  6727. }
  6728. return result;
  6729. }
  6730. int handleClearCacheRequest(char *uuid, char *payload)
  6731. {
  6732. mtrace();
  6733. int result = FAIL;
  6734. char comfirmstr[20];
  6735. char rmFileCmd[100]={0};
  6736. struct stat stats;
  6737. DEBUG_INFO("handleClearCacheRequest...\n");
  6738. stat("/Storage/OCPP", &stats);
  6739. // Check for directory existence
  6740. if (S_ISDIR(stats.st_mode) == 1)
  6741. {}
  6742. else
  6743. {
  6744. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6745. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6746. system(rmFileCmd);
  6747. }
  6748. if(OCPP_cleanLocalCache())
  6749. {
  6750. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6751. }
  6752. else
  6753. {
  6754. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6755. }
  6756. sendClearCacheConfirmation(uuid, comfirmstr);
  6757. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6758. return result;
  6759. }
  6760. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6761. {
  6762. mtrace();
  6763. int result = FAIL;
  6764. int resultRename;
  6765. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6766. char chargingProfilePurposeStr[26]={0};
  6767. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6768. char tempchargingProfilePurposeStr[26]={0};
  6769. char str[100]={0};
  6770. char fname[200]={0};
  6771. char comfirmstr[20]={0};
  6772. char word[1600]={0};
  6773. int clearflag = FALSE;
  6774. int chargingProfileIdIsNULL = FALSE;
  6775. int connectorIsNULL = FALSE;
  6776. int chargingProfilePurposeIsNULL = FALSE;
  6777. int stackLevelIsNULL = FALSE;
  6778. //int GotoEnd = FALSE;
  6779. FILE *fptr1, *fptr2;
  6780. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6781. int n_chargingProfile=0;
  6782. int isEmptyFile = FALSE;
  6783. char sLineWord[1600]={0};
  6784. char chargingProfiles[10][100]={0};
  6785. int ChargeProfileCount = 0;
  6786. int ch;
  6787. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6788. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6789. json_object *ClearChargingProfile;
  6790. ClearChargingProfile = json_tokener_parse(payload);
  6791. if(!is_error(ClearChargingProfile))
  6792. {
  6793. // Optional data
  6794. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6795. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6796. else
  6797. chargingProfileIdIsNULL = TRUE;
  6798. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6799. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6800. else
  6801. connectorIsNULL = TRUE;
  6802. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6803. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6804. else
  6805. chargingProfilePurposeIsNULL = TRUE;
  6806. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6807. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6808. else
  6809. stackLevelIsNULL = TRUE;
  6810. }
  6811. json_object_put(ClearChargingProfile);
  6812. if(connectorIsNULL == FALSE)
  6813. {
  6814. switch(connectorIdInt)
  6815. {
  6816. case 0:
  6817. if(chargingProfilePurposeIsNULL == TRUE)
  6818. {
  6819. int l = 0;
  6820. strcpy(fname, ChargePointMaxProfile_JSON);
  6821. if((access(fname,F_OK))!=-1)
  6822. {
  6823. strcpy(chargingProfiles[l], fname);
  6824. l = l + 1;
  6825. }
  6826. strcpy(fname, TxDefaultProfile_0_JSON);
  6827. if((access(fname,F_OK))!=-1)
  6828. {
  6829. strcpy(chargingProfiles[l], fname);
  6830. l = l + 1;
  6831. }
  6832. ChargeProfileCount = l;
  6833. }
  6834. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6835. {
  6836. strcpy(fname, ChargePointMaxProfile_JSON);
  6837. if((access(fname,F_OK))!=-1)
  6838. {
  6839. strcpy(chargingProfiles[0], fname);
  6840. ChargeProfileCount = 1;
  6841. }
  6842. }
  6843. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6844. {
  6845. strcpy(fname, TxDefaultProfile_0_JSON);
  6846. if((access(fname,F_OK))!=-1)
  6847. {
  6848. strcpy(chargingProfiles[0], fname);
  6849. ChargeProfileCount = 1;
  6850. }
  6851. }
  6852. break;
  6853. default:
  6854. if(chargingProfilePurposeIsNULL == TRUE)
  6855. {
  6856. int m = 0;
  6857. memset(fname, 0, ARRAY_SIZE(fname));
  6858. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6859. if((access(fname,F_OK))!=-1)
  6860. {
  6861. strcpy(chargingProfiles[m], fname);
  6862. m = m + 1;
  6863. }
  6864. memset(fname, 0, ARRAY_SIZE(fname));
  6865. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6866. if((access(fname,F_OK))!=-1)
  6867. {
  6868. strcpy(chargingProfiles[m], fname);
  6869. m = m + 1;
  6870. }
  6871. ChargeProfileCount = m;
  6872. }
  6873. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6874. {
  6875. //strcpy(fname, TxDefaultProfile_1_JSON);
  6876. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6877. if((access(fname,F_OK))!=-1)
  6878. {
  6879. strcpy(chargingProfiles[0], fname);
  6880. ChargeProfileCount = 1;
  6881. }
  6882. }
  6883. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6884. {
  6885. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6886. if((access(fname,F_OK))!=-1)
  6887. {
  6888. strcpy(chargingProfiles[0], fname);
  6889. ChargeProfileCount = 1;
  6890. }
  6891. //strcpy(fname, TxProfile_1_JSON);
  6892. }
  6893. //strcpy(fname, ChargePointMaxProfile_JSON );
  6894. break;
  6895. }
  6896. }
  6897. else // Check all Charging Profiles
  6898. {
  6899. int i = 0;
  6900. char fnametemp[200]={0};
  6901. ChargeProfileCount = 0;
  6902. //Check ChargePointMaxProfile.json exit
  6903. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6904. {
  6905. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6906. i = i + 1;
  6907. }
  6908. //Check TxDefaultProfile_0.json exit
  6909. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6910. {
  6911. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6912. i = i + 1;
  6913. }
  6914. //Check TxDefaultProfile_%d.json
  6915. for(int j=1; j <= gunTotalNumber; j++)
  6916. {
  6917. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6918. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6919. if((access(fnametemp,F_OK))!=-1)
  6920. {
  6921. strcpy(chargingProfiles[i], fnametemp);
  6922. i = i + 1;
  6923. }
  6924. }
  6925. //Check TxProfile_%d.json
  6926. for(int j=1; j <= gunTotalNumber; j++)
  6927. {
  6928. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6929. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6930. if((access(fnametemp,F_OK))!=-1)
  6931. {
  6932. strcpy(chargingProfiles[i], fnametemp);
  6933. i = i + 1;
  6934. }
  6935. }
  6936. ChargeProfileCount = i;
  6937. }// End connectorIsNULL is TRUE
  6938. if(ChargeProfileCount == 0)
  6939. {
  6940. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6941. goto end;
  6942. }
  6943. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6944. {
  6945. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6946. goto end;
  6947. }
  6948. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6949. {
  6950. memset(str, 0, ARRAY_SIZE(str));
  6951. // clear temp file
  6952. sprintf(str,"rm -f %s",temp);
  6953. system(str);
  6954. for(int k=0; k < ChargeProfileCount; k++)
  6955. {
  6956. memset(str, 0, ARRAY_SIZE(str));
  6957. //clear file in C
  6958. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6959. system(str);
  6960. }
  6961. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6962. goto end;
  6963. }
  6964. else if(connectorIsNULL == TRUE)
  6965. {
  6966. for(int k=0; k < ChargeProfileCount; k++)
  6967. {
  6968. fptr1 = fopen(chargingProfiles[k], "r");
  6969. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6970. //Check Charging Profile Count
  6971. while(fscanf(fptr1, "%s", word) != EOF)
  6972. {
  6973. //DEBUG_INFO("word=%s\n",word);
  6974. if(strstr(word, "chargingProfileId")!= NULL)
  6975. {
  6976. //DEBUG_INFO("test chargingProfileId \n");
  6977. n_chargingProfile = n_chargingProfile + 1;
  6978. //DEBUG_INFO("chargingProfileId Found\n");
  6979. }
  6980. }
  6981. rewind(fptr1);
  6982. //search Charging Profile Element
  6983. //int i= 0;
  6984. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6985. {
  6986. json_object *tmpProfilee;
  6987. tmpProfilee = json_tokener_parse(sLineWord);
  6988. if(!is_error(tmpProfilee))
  6989. {
  6990. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6991. {
  6992. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6993. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6994. }
  6995. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6996. {
  6997. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6998. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6999. }
  7000. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7001. {
  7002. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7003. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7004. }
  7005. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7006. {
  7007. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7008. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7009. }
  7010. }
  7011. json_object_put(tmpProfilee);
  7012. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7013. {
  7014. //------- not write to fptr2-------//
  7015. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7016. //clearflag = TRUE;
  7017. }
  7018. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7019. {
  7020. //------- not write to fptr2-------//
  7021. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7022. }
  7023. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7024. {
  7025. //------- not write to fptr2-------//
  7026. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7027. }
  7028. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7029. {
  7030. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7031. }
  7032. else
  7033. {
  7034. fprintf(fptr2, sLineWord);//writing data into file
  7035. }
  7036. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7037. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7038. if(clearflag == TRUE)
  7039. {
  7040. fclose(fptr1);
  7041. fclose(fptr2);
  7042. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7043. system(str);
  7044. // clear temp file
  7045. sprintf(str,"rm -f %s",temp);
  7046. system(str);
  7047. }
  7048. else
  7049. {
  7050. fclose(fptr1);
  7051. fclose(fptr2);
  7052. memset(str, 0, ARRAY_SIZE(str));
  7053. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7054. system(str);
  7055. resultRename = rename(temp, chargingProfiles[k]);
  7056. if(resultRename == 0)
  7057. {
  7058. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7059. }
  7060. else
  7061. {
  7062. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7063. }
  7064. if(comfirmstr[0]== 0)
  7065. {
  7066. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7067. }
  7068. //Check chargingProfile is empty file
  7069. /*------ Read the file ----------------*/
  7070. fptr1=fopen(chargingProfiles[k],"r");
  7071. ch=fgetc(fptr1);
  7072. rewind(fptr1);
  7073. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7074. if(ch!=EOF)
  7075. {
  7076. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7077. {
  7078. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7079. if(sLineWord[0]=='\0')
  7080. {
  7081. isEmptyFile = TRUE;
  7082. break;
  7083. }
  7084. else
  7085. {
  7086. isEmptyFile = FALSE;
  7087. break;
  7088. }
  7089. }
  7090. }
  7091. else
  7092. isEmptyFile = TRUE;
  7093. fclose(fptr1);
  7094. if(isEmptyFile == TRUE)
  7095. {
  7096. memset(str, 0, ARRAY_SIZE(str));
  7097. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7098. system(str);
  7099. }
  7100. }
  7101. }// End of while(int k=0; k < ChargePointCount; k++)
  7102. }
  7103. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7104. {
  7105. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7106. for(int k=0; k < ChargeProfileCount; k++)
  7107. {
  7108. fptr1 = fopen(chargingProfiles[k], "r");
  7109. fptr2 = fopen(temp, "w+");
  7110. //Check Charging Profile Count
  7111. while(fscanf(fptr1, "%s", word) != EOF)
  7112. {
  7113. //DEBUG_INFO("word=%s\n",word);
  7114. if(strstr(word, "chargingProfileId")!= NULL)
  7115. {
  7116. n_chargingProfile = n_chargingProfile + 1;
  7117. }
  7118. }
  7119. rewind(fptr1);
  7120. //search Charging Profile Element
  7121. //int i= 0;
  7122. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7123. {
  7124. json_object *tmpProfilee;
  7125. tmpProfilee = json_tokener_parse(sLineWord);
  7126. if(!is_error(tmpProfilee))
  7127. {
  7128. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7129. {
  7130. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7131. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7132. }
  7133. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7134. {
  7135. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7136. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7137. }
  7138. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7139. {
  7140. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7141. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7142. }
  7143. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7144. {
  7145. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7146. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7147. }
  7148. }
  7149. json_object_put(tmpProfilee);
  7150. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7151. {
  7152. //------- not write to fptr2-------//
  7153. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7154. //clearflag = TRUE;
  7155. }
  7156. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7157. {
  7158. //------- not write to fptr2-------//
  7159. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7160. }
  7161. else if(stackLevelIsNULL == TRUE)
  7162. {
  7163. //Clear Whole File
  7164. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7165. clearflag = TRUE;
  7166. break;
  7167. }
  7168. else
  7169. {
  7170. fprintf(fptr2, sLineWord);//writing data into file
  7171. }
  7172. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7173. }
  7174. if(clearflag == TRUE)
  7175. {
  7176. fclose(fptr1);
  7177. fclose(fptr2);
  7178. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7179. system(str);
  7180. // clear temp file
  7181. sprintf(str,"rm -f %s",temp);
  7182. system(str);
  7183. }
  7184. else
  7185. {
  7186. fclose(fptr1);
  7187. fclose(fptr2);
  7188. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7189. system(str);
  7190. resultRename = rename(temp, chargingProfiles[k]);
  7191. if(resultRename == 0)
  7192. {
  7193. DEBUG_INFO("File ChargingProfile renamed successfully");
  7194. }
  7195. else
  7196. {
  7197. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7198. }
  7199. if(comfirmstr[0]== 0)
  7200. {
  7201. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7202. }
  7203. //Check chargingProfile is empty file
  7204. /*------ Read the file ----------------*/
  7205. fptr1=fopen(chargingProfiles[k],"r");
  7206. ch=fgetc(fptr1);
  7207. rewind(fptr1);
  7208. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7209. if(ch!=EOF)
  7210. {
  7211. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7212. {
  7213. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7214. if(sLineWord[0]=='\0')
  7215. {
  7216. isEmptyFile = TRUE;
  7217. break;
  7218. }
  7219. else
  7220. {
  7221. isEmptyFile = FALSE;
  7222. break;
  7223. }
  7224. }
  7225. }
  7226. else
  7227. isEmptyFile = TRUE;
  7228. fclose(fptr1);
  7229. if(isEmptyFile == TRUE)
  7230. {
  7231. memset(str, 0, ARRAY_SIZE(str));
  7232. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7233. system(str);
  7234. }
  7235. /*------- End of reading ---------------*/
  7236. }
  7237. } // while(int k=0; k < ChargeProfileCount; k++)
  7238. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7239. end:
  7240. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7241. {
  7242. if(connectorIdInt == 0)
  7243. {
  7244. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7245. {
  7246. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7247. }
  7248. }
  7249. else
  7250. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7251. }
  7252. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7253. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7254. return result;
  7255. }
  7256. void createFirmwareVersionByDataTransfer(void)
  7257. {
  7258. json_object *FirmwareDataTransfer = json_object_new_object();
  7259. // AC & DC model
  7260. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7261. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7262. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7263. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7264. // DC model
  7265. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7266. {
  7267. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7268. {
  7269. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7270. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7271. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7272. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7273. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7274. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7275. }
  7276. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7277. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7278. {
  7279. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7280. }
  7281. }
  7282. else
  7283. {
  7284. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7285. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7286. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7287. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7288. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7289. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7290. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7291. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7292. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7293. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7294. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7295. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7296. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7297. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7298. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7299. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7300. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7301. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7302. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7303. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7304. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7305. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7306. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7307. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7308. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7309. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7310. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7311. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7312. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7313. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7314. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7315. }
  7316. // 4G model
  7317. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7318. {
  7319. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7320. }
  7321. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7322. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7323. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7324. json_object_put(FirmwareDataTransfer);
  7325. }
  7326. int handleDataTransferRequest(char *uuid, char *payload)
  7327. {
  7328. mtrace();
  7329. json_object *response = json_object_new_object();
  7330. int result = FAIL;
  7331. char tempvendorId[255]={0};
  7332. char tempmessageId[50]={0};
  7333. char tempdata[512]={0};
  7334. char message[2048]={0};
  7335. DEBUG_INFO("handleDataTransferRequest...\n");
  7336. if((uuid != NULL) && (payload != NULL))
  7337. {
  7338. json_object *DataTransfer;
  7339. DataTransfer = json_tokener_parse(payload);
  7340. if(!is_error(DataTransfer))
  7341. {
  7342. // Required data
  7343. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7344. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7345. // Optional data
  7346. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7347. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7348. if(json_object_object_get(DataTransfer, "data") != NULL)
  7349. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7350. result = PASS;
  7351. }
  7352. json_object_put(DataTransfer);
  7353. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7354. {
  7355. // Send all moudle firmware version on EVSE
  7356. createFirmwareVersionByDataTransfer();
  7357. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7358. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7359. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7360. json_object_put(response);
  7361. }
  7362. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7363. {
  7364. system("/usr/bin/run_tmate_restart.sh &");
  7365. }
  7366. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7367. {
  7368. json_object *data;
  7369. data = json_tokener_parse(tempdata);
  7370. if(!is_error(data))
  7371. {
  7372. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7373. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7374. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7375. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7376. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7377. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7378. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7379. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7380. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7381. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7382. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7383. }
  7384. else
  7385. {
  7386. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7387. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7388. }
  7389. json_object_put(data);
  7390. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7391. json_object_put(response);
  7392. }
  7393. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7394. {
  7395. json_object *data;
  7396. data = json_tokener_parse(tempdata);
  7397. if(!is_error(data))
  7398. {
  7399. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7400. if(json_object_object_get(data, "idToken") != NULL)
  7401. {
  7402. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7403. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7404. }
  7405. if(json_object_object_get(data, "price") != NULL)
  7406. {
  7407. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7408. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7409. }
  7410. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7411. }
  7412. else
  7413. {
  7414. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7415. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7416. }
  7417. json_object_put(data);
  7418. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7419. json_object_put(response);
  7420. }
  7421. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7422. {
  7423. json_object *data;
  7424. data = json_tokener_parse(tempdata);
  7425. if(!is_error(data))
  7426. {
  7427. if(json_object_object_get(data, "txId") != NULL)
  7428. {
  7429. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7430. for(int idx = 0;idx<gunTotalNumber;idx++)
  7431. {
  7432. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7433. {
  7434. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7435. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7436. if(json_object_object_get(data, "description") != NULL)
  7437. {
  7438. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7439. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7440. }
  7441. }
  7442. }
  7443. }
  7444. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7445. }
  7446. else
  7447. {
  7448. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7449. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7450. }
  7451. json_object_put(data);
  7452. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7453. json_object_put(response);
  7454. }
  7455. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7456. {
  7457. json_object *data;
  7458. data = json_tokener_parse(tempdata);
  7459. if(!is_error(data))
  7460. {
  7461. if(json_object_object_get(data, "txId") != NULL)
  7462. {
  7463. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7464. for(int idx = 0;idx<gunTotalNumber;idx++)
  7465. {
  7466. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7467. {
  7468. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7469. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7470. if(json_object_object_get(data, "description") != NULL)
  7471. {
  7472. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7473. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7474. }
  7475. }
  7476. }
  7477. }
  7478. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7479. }
  7480. else
  7481. {
  7482. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7483. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7484. }
  7485. json_object_put(data);
  7486. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7487. json_object_put(response);
  7488. }
  7489. else
  7490. {
  7491. // Can not find valid message id
  7492. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7493. }
  7494. }
  7495. else
  7496. {
  7497. // Payload is null
  7498. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7499. }
  7500. LWS_Send(message);
  7501. return result;
  7502. }
  7503. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7504. {
  7505. mtrace();
  7506. int result = FAIL;
  7507. int connectorIdInt, durationInt;
  7508. char chargingRateUnitStr[4]={0};
  7509. char comfirmstr[20];
  7510. int confirmPeriods = 0;
  7511. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7512. json_object *GetCompositeSchedule;
  7513. GetCompositeSchedule = json_tokener_parse(payload);
  7514. if(!is_error(GetCompositeSchedule))
  7515. {
  7516. // Required data
  7517. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7518. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7519. else
  7520. connectorIdInt = -1;
  7521. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7522. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7523. else
  7524. durationInt = 86400;
  7525. // Optional data
  7526. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7527. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7528. }
  7529. json_object_put(GetCompositeSchedule);
  7530. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7531. if((connectorIdInt == 0) ||
  7532. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7533. {
  7534. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7535. struct StructChargingProfile tmpProfile[1];
  7536. if(strstr(chargingRateUnitStr, "W") != NULL)
  7537. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7538. else
  7539. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7540. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7541. {
  7542. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7543. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7544. }
  7545. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7546. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7547. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7548. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7549. {
  7550. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7551. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7552. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7553. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  7554. {
  7555. confirmPeriods = idx;
  7556. break;
  7557. }
  7558. }
  7559. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7560. }
  7561. else
  7562. {
  7563. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7564. }
  7565. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7566. return result;
  7567. }
  7568. int handleGetConfigurationRequest(char *uuid, char *payload)
  7569. {
  7570. mtrace();
  7571. int result = FAIL;
  7572. int MaxKeySupported = 0;
  7573. int n_keys = 0;
  7574. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7575. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7576. json_object *GetConfiguration;
  7577. GetConfiguration = json_tokener_parse(payload);
  7578. if(!is_error(GetConfiguration))
  7579. {
  7580. // Optional data
  7581. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7582. {
  7583. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7584. {
  7585. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7586. n_keys = idx + 1;
  7587. }
  7588. }
  7589. }
  7590. json_object_put(GetConfiguration);
  7591. UnknownKeynum = 0;
  7592. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7593. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7594. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7595. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7596. if(n_keys != 0)
  7597. {
  7598. for(int i=0;i<n_keys;i++)
  7599. {
  7600. getKeyValue(requestKey[i]);
  7601. }
  7602. }
  7603. else
  7604. {
  7605. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7606. getKeyValue("");
  7607. }
  7608. processUnkownKey();
  7609. sendGetConfigurationConfirmation(uuid);
  7610. return result;
  7611. }
  7612. static char fnamePlusPath[100]={0};
  7613. static char fnamePWithNoPath[60]={0};
  7614. void checkUploadLog(void)
  7615. {
  7616. FILE *fp;
  7617. /* Open the command for reading. */
  7618. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7619. if (fp == NULL) {
  7620. printf("Failed to run command\n" );
  7621. exit(1);
  7622. }
  7623. int ftppathlen = 0;
  7624. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7625. int i = 0;
  7626. /* Read the output a line at a time - output it. */
  7627. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7628. if(i==0)
  7629. {
  7630. ftppathlen = strlen(fnamePlusPath);
  7631. printf("%s\n", fnamePlusPath);
  7632. fnamePlusPath[ftppathlen]='\0';
  7633. break;
  7634. }
  7635. i= i+1;
  7636. }
  7637. /* close */
  7638. pclose(fp);
  7639. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7640. {
  7641. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7642. {
  7643. fnamePlusPath[k]='\0';
  7644. }
  7645. }
  7646. i=1;
  7647. //char fname[60]={0};
  7648. while(i < ftppathlen)
  7649. {
  7650. int len=ftppathlen-i;
  7651. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7652. {
  7653. printf("compare '/' all right\n");
  7654. break;
  7655. }
  7656. i=i+1;
  7657. }
  7658. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7659. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7660. fnamePWithNoPath[i+1] = '\0';
  7661. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7662. {
  7663. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7664. {
  7665. fnamePWithNoPath[j]='\0';
  7666. }
  7667. }
  7668. FILE* fp1 = fopen(fnamePlusPath, "r");
  7669. if (fp1)
  7670. {
  7671. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7672. // file exists
  7673. fclose(fp1);
  7674. }
  7675. else
  7676. {
  7677. // file doesn't exist
  7678. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7679. }
  7680. }
  7681. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7682. {
  7683. mtrace();
  7684. int result = FAIL;
  7685. time_t CurrentTime;
  7686. struct tm *tm;
  7687. pthread_t th_Status;
  7688. CurrentTime = time(NULL);
  7689. tm = localtime(&CurrentTime);
  7690. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7691. 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);
  7692. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7693. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7694. return result;
  7695. }
  7696. void* GetDiagnosticsProcess(void* data)
  7697. {
  7698. pthread_detach(pthread_self());
  7699. mtrace();
  7700. int retriesInt=0, retryIntervalInt=0;
  7701. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7702. 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};
  7703. int port=0;
  7704. int isSuccess = FALSE;
  7705. char ftpbuf[200]={0};
  7706. char cmdBuf[2048];
  7707. struct tm *tmNow;
  7708. time_t CurrentTime;
  7709. struct tm tmStart;
  7710. struct tm tmStop;
  7711. CurrentTime = time(NULL);
  7712. tmNow=localtime(&CurrentTime);
  7713. uint16_t targetYear, targetMonth;
  7714. json_object *GetDiagnostics;
  7715. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7716. GetDiagnostics = json_tokener_parse(data);
  7717. if(!is_error(GetDiagnostics))
  7718. {
  7719. // Required data
  7720. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7721. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7722. // Optional data
  7723. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7724. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7725. else
  7726. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7727. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7728. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7729. else
  7730. retryIntervalInt = 30;
  7731. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7732. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7733. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7734. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7735. }
  7736. json_object_put(GetDiagnostics);
  7737. // Pack log to compress file
  7738. 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) &&
  7739. (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))
  7740. {
  7741. // Pack system log
  7742. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7743. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7744. targetYear = tmStart.tm_year;
  7745. targetMonth = tmStart.tm_mon;
  7746. do
  7747. {
  7748. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7749. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7750. if(targetMonth+1>=13)
  7751. {
  7752. targetYear += 1;
  7753. targetMonth = 1;
  7754. }
  7755. else
  7756. {
  7757. targetMonth += 1;
  7758. }
  7759. }while((targetYear < (tmNow->tm_year+1900)) ||
  7760. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7761. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7762. system(cmdBuf);
  7763. // Pack charging & event log
  7764. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7765. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7766. targetYear = tmStart.tm_year;
  7767. targetMonth = tmStart.tm_mon;
  7768. do
  7769. {
  7770. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7771. if(targetMonth+1>=13)
  7772. {
  7773. targetYear += 1;
  7774. targetMonth = 1;
  7775. }
  7776. else
  7777. {
  7778. targetMonth += 1;
  7779. }
  7780. }while((targetYear < (tmNow->tm_year+1900)) ||
  7781. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7782. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7783. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7784. system(cmdBuf);
  7785. // Combine log file
  7786. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7787. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7788. }
  7789. else
  7790. {
  7791. system("exec /root/logPackTools 'log' 6");
  7792. }
  7793. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7794. system(cmdBuf);
  7795. checkUploadLog();
  7796. //****************location*******************/
  7797. if(strcmp(locationstr,"")==0)
  7798. {
  7799. DEBUG_INFO("location is <Empty>!\n");
  7800. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7801. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7802. goto end;
  7803. }
  7804. memset(protocol, 0, ARRAY_SIZE(protocol));
  7805. memset(user, 0, ARRAY_SIZE(user) );
  7806. memset(password, 0, ARRAY_SIZE(password));
  7807. memset(host, 0, ARRAY_SIZE(host));
  7808. memset(path, 0, ARRAY_SIZE(path));
  7809. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7810. memset(host1, 0, ARRAY_SIZE(host1));
  7811. memset(path1, 0, ARRAY_SIZE(path1));
  7812. /*location: ftp://user:password@host:port/path*/
  7813. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7814. if((access(fnamePlusPath,F_OK))!=-1)
  7815. {
  7816. DEBUG_INFO("fnamePlusPath exist.\n");
  7817. }
  7818. else
  7819. {
  7820. DEBUG_INFO("fnamePlusPath not exist!\n");
  7821. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7822. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7823. goto end;
  7824. }
  7825. if(strchr(locationstr,'@')==NULL)
  7826. {
  7827. sscanf(locationstr,
  7828. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7829. protocol, host, &port, path);
  7830. strcpy(user,"anonymous");
  7831. strcpy(password,"");
  7832. }
  7833. else
  7834. {
  7835. //DEBUG_INFO("pch=%s\n", pch);
  7836. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7837. protocol, user, password, host, &port, path);
  7838. }
  7839. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7840. {
  7841. DEBUG_INFO("protocol is not ftp/http ! \n");
  7842. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7843. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7844. goto end;
  7845. }
  7846. if(strncmp(locationstr,"http", 4) == 0)
  7847. {
  7848. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7849. sprintf(ftppath,"/%s", path);
  7850. do
  7851. {
  7852. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7853. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7854. sleep(3);
  7855. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7856. if(!isSuccess)
  7857. {
  7858. DEBUG_INFO("Diagnostics fail.\n");
  7859. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7860. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7861. sleep(retryIntervalInt);
  7862. }
  7863. else
  7864. {
  7865. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7866. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7867. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7868. }
  7869. retriesInt--;
  7870. }while((isSuccess == 0)&&(retriesInt >= 0));
  7871. }
  7872. else
  7873. {
  7874. sscanf(host,"%[^/]%s",host1, path1);
  7875. if(strlen(path) > 0)
  7876. sprintf(ftppath,"/%s", path);
  7877. else
  7878. sprintf(ftppath,"/%s", path1);
  7879. int ftppathlen=strlen(ftppath);
  7880. int i=1;
  7881. char filenametemp[50];
  7882. while(i < ftppathlen)
  7883. {
  7884. int len=ftppathlen-i;
  7885. if(ftppath[len]== 47) // '/' ascll code: 47
  7886. {
  7887. DEBUG_INFO("find '/' all right\n");
  7888. break;
  7889. }
  7890. i=i+1;
  7891. }
  7892. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7893. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7894. filenametemp[i+1] = 0;
  7895. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7896. if(port == 0)
  7897. port = 21;
  7898. do
  7899. {
  7900. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7901. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7902. sleep(3);
  7903. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7904. if(!isSuccess)
  7905. {
  7906. DEBUG_INFO("Diagnostics fail.\n");
  7907. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7908. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7909. sleep(retryIntervalInt);
  7910. }
  7911. else
  7912. {
  7913. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7914. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7915. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7916. }
  7917. retriesInt--;
  7918. }while((!isSuccess)&&(retriesInt >= 0));
  7919. }
  7920. end:
  7921. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7922. system("rm -f /mnt/*");
  7923. pthread_exit(NULL);
  7924. }
  7925. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7926. {
  7927. mtrace();
  7928. int result = FAIL;
  7929. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7930. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7931. {
  7932. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7933. localversion = -1;
  7934. }
  7935. else
  7936. {
  7937. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7938. OCPP_getListVerion();
  7939. }
  7940. //from db.OCPP_getListVerion
  7941. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7942. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7943. sendGetLocalListVersionConfirmation(uuid,"");
  7944. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7945. return result;
  7946. }
  7947. int handleRemoteStartRequest(char *uuid, char *payload)
  7948. {
  7949. mtrace();
  7950. int result = FAIL;
  7951. int connectorIdInt=0;
  7952. int tempIndex = 0;
  7953. int connectorIdIsNULL, chargingProfileIsNULL;
  7954. char comfirmstr[20]={0};
  7955. char cmdBuf[512];
  7956. json_object *RemoteStartTransaction;
  7957. FILE *fp;
  7958. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7959. if(server_pending == TRUE)
  7960. {
  7961. return 0;
  7962. }
  7963. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7964. RemoteStartTransaction = json_tokener_parse(payload);
  7965. if(!is_error(RemoteStartTransaction))
  7966. {
  7967. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7968. {
  7969. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7970. if(connectorIdInt <= gunTotalNumber)
  7971. {
  7972. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7973. // Required data
  7974. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7975. // Optional data
  7976. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7977. {
  7978. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7979. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7980. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7981. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7982. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7983. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7984. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7985. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7986. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7987. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7988. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7989. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7990. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7991. {
  7992. 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")));
  7993. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7994. 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"));
  7995. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7996. 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"));
  7997. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7998. 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")));
  7999. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8000. {
  8001. 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++)
  8002. {
  8003. 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"));
  8004. 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"));
  8005. 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)
  8006. 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"));
  8007. }
  8008. }
  8009. }
  8010. }
  8011. else
  8012. chargingProfileIsNULL = TRUE;
  8013. }
  8014. }
  8015. else
  8016. connectorIdIsNULL = TRUE;
  8017. }
  8018. else
  8019. connectorIdIsNULL = TRUE;
  8020. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8021. {
  8022. DEBUG_WARN("Connector id is NULL\n.");
  8023. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8024. goto end;
  8025. }
  8026. /*
  8027. enum _SYSTEM_STATUS
  8028. {
  8029. S_BOOTING = 0,
  8030. S_IDLE, = 1
  8031. S_AUTHORIZING, = 2
  8032. S_REASSIGN_CHECK, = 3
  8033. S_REASSIGN, = 4
  8034. S_PRECHARGE, = 5
  8035. S_PREPARING_FOR_EV, = 6
  8036. S_PREPARING_FOR_EVSE, = 7
  8037. S_CHARGING, = 8
  8038. S_TERMINATING, = 9
  8039. S_COMPLETE, = 10
  8040. S_ALARM, = 11
  8041. S_FAULT = 12
  8042. }
  8043. */
  8044. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8045. {
  8046. //check Transaction active
  8047. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8048. {
  8049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8050. {
  8051. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8052. }
  8053. else
  8054. {
  8055. tempIndex = connectorIdInt -1;
  8056. }
  8057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8058. {
  8059. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8060. {
  8061. 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))
  8062. {
  8063. //Reserved
  8064. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8065. }
  8066. 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))
  8067. {
  8068. //Reserved
  8069. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8070. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8071. goto end;
  8072. }
  8073. else
  8074. {
  8075. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8076. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8077. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8078. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8079. {
  8080. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8081. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8082. goto end;
  8083. }
  8084. }//END FOR ELSE
  8085. }
  8086. }// END FOR CHAdeMO_QUANTITY
  8087. }
  8088. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8089. {
  8090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8091. {
  8092. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8093. }
  8094. else
  8095. {
  8096. tempIndex = connectorIdInt -1;
  8097. }
  8098. for (int index = 0; index < CCS_QUANTITY; index++)
  8099. {
  8100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8101. {
  8102. 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))
  8103. {
  8104. //Reserved
  8105. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8106. }
  8107. 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))
  8108. {
  8109. //Reserved
  8110. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8111. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8112. goto end;
  8113. }
  8114. else
  8115. {
  8116. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8117. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8118. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8119. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8120. {
  8121. DEBUG_WARN("CCS connector not allow start\n.");
  8122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8123. goto end;
  8124. }
  8125. }// END FOR ELSE
  8126. }
  8127. }// END FOR CCS_QUANTITY
  8128. }
  8129. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8130. {
  8131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8132. {
  8133. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8134. }
  8135. else
  8136. {
  8137. tempIndex = connectorIdInt -1;
  8138. }
  8139. for (int index = 0; index < GB_QUANTITY; index++)
  8140. {
  8141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8142. {
  8143. 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))
  8144. {
  8145. //Reserved
  8146. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8147. }
  8148. 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))
  8149. {
  8150. //Reserved
  8151. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8153. goto end;
  8154. }
  8155. else
  8156. {
  8157. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8158. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8159. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8160. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8161. {
  8162. DEBUG_WARN("GB connector not allow start\n.");
  8163. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8164. goto end;
  8165. }
  8166. }// END FOR ELSE
  8167. }
  8168. } // END FOR GB_QUANTITY
  8169. }
  8170. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8171. {
  8172. tempIndex = connectorIdInt -1;
  8173. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8174. {
  8175. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8176. {
  8177. 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))
  8178. {
  8179. //Reserved
  8180. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8181. }
  8182. 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))
  8183. {
  8184. //Reserved
  8185. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8186. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8187. goto end;
  8188. }
  8189. else
  8190. {
  8191. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8192. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8193. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8194. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8195. {
  8196. DEBUG_WARN("GB connector not allow start\n.");
  8197. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8198. goto end;
  8199. }
  8200. }// END FOR ELSE
  8201. }
  8202. } // END FOR GB_QUANTITY
  8203. }
  8204. else
  8205. {
  8206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8207. {
  8208. tempIndex = 2;
  8209. }
  8210. else
  8211. {
  8212. tempIndex = connectorIdInt -1;
  8213. }
  8214. for (int index = 0; index < AC_QUANTITY; index++)
  8215. {
  8216. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8217. {
  8218. 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))
  8219. {
  8220. //Reserved
  8221. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8222. }
  8223. 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))
  8224. {
  8225. //Reserved
  8226. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8227. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8228. goto end;
  8229. }
  8230. else
  8231. {
  8232. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8233. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8234. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8235. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8236. {
  8237. DEBUG_WARN("AC connector not allow start\n.");
  8238. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8239. goto end;
  8240. }
  8241. }//END FOR ELSE
  8242. }
  8243. }// END FOR AC_QUANTITY
  8244. }
  8245. if(chargingProfileIsNULL == FALSE)
  8246. {
  8247. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8248. {
  8249. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8250. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8251. //memset idTag
  8252. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8253. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8254. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8255. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8256. // Save profile to file
  8257. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8258. system(cmdBuf);
  8259. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8260. fp = fopen(cmdBuf, "w");
  8261. 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));
  8262. fclose(fp);
  8263. }
  8264. else
  8265. {
  8266. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8267. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8268. }
  8269. }
  8270. else
  8271. {
  8272. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8273. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8274. //memset idTag
  8275. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8276. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8277. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8278. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8279. }
  8280. }
  8281. else
  8282. {
  8283. DEBUG_WARN("Connector id over\n.");
  8284. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8285. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8286. }
  8287. end:
  8288. json_object_put(RemoteStartTransaction);
  8289. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8290. {
  8291. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8292. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8293. }
  8294. //OCPP send RemoteStartConfirmation by first.
  8295. sendRemoteStartConfirmation(uuid, comfirmstr);
  8296. return result;
  8297. }
  8298. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8299. {
  8300. mtrace();
  8301. int result = FAIL;
  8302. int match = FALSE;
  8303. int GunNO = 0;
  8304. int tempIndex = 0;
  8305. int transactionIdInt=0;
  8306. int transactionIdIsNULL= TRUE;
  8307. char comfirmstr[20];
  8308. json_object *RemoteStopTransaction;
  8309. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8310. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8311. if(server_pending == TRUE)
  8312. {
  8313. return 0;
  8314. }
  8315. RemoteStopTransaction = json_tokener_parse(payload);
  8316. if(!is_error(RemoteStopTransaction))
  8317. {
  8318. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8319. {
  8320. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8321. transactionIdIsNULL = FALSE;
  8322. }
  8323. }
  8324. json_object_put(RemoteStopTransaction);
  8325. if(transactionIdIsNULL == FALSE)
  8326. {
  8327. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8328. {
  8329. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8330. {
  8331. //check Transaction active
  8332. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8333. {
  8334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8335. {
  8336. tempIndex = ((gun_index==2) ? 1: 0);
  8337. }
  8338. else
  8339. {
  8340. tempIndex = gun_index;
  8341. }
  8342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8343. {
  8344. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8345. {
  8346. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8347. {
  8348. match = TRUE;
  8349. GunNO = gun_index;
  8350. }
  8351. }
  8352. }// END FOR CHAdeMO_QUANTITY
  8353. }
  8354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8355. {
  8356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8357. {
  8358. tempIndex = ((gun_index==2) ? 1: 0);
  8359. }
  8360. else
  8361. {
  8362. tempIndex = gun_index;
  8363. }
  8364. for (int index = 0; index < CCS_QUANTITY; index++)
  8365. {
  8366. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8367. {
  8368. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8369. {
  8370. match = TRUE;
  8371. GunNO = gun_index;
  8372. }
  8373. }
  8374. }// END FOR CCS_QUANTITY
  8375. }
  8376. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8377. {
  8378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8379. {
  8380. tempIndex = ((gun_index==2) ? 1: 0);
  8381. }
  8382. else
  8383. {
  8384. tempIndex = gun_index;
  8385. }
  8386. for (int index = 0; index < GB_QUANTITY; index++)
  8387. {
  8388. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8389. {
  8390. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8391. {
  8392. match = TRUE;
  8393. GunNO = gun_index;
  8394. }
  8395. }
  8396. }// END FOR GB_QUANTITY
  8397. }
  8398. else if(gunType[gun_index] == GUN_TYPE_DO)
  8399. {
  8400. tempIndex = gun_index;
  8401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8402. {
  8403. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8404. {
  8405. 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
  8406. {
  8407. match = TRUE;
  8408. GunNO = gun_index;
  8409. }
  8410. }
  8411. }// END FOR GB_QUANTITY
  8412. }
  8413. else
  8414. {
  8415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8416. {
  8417. tempIndex = 2;
  8418. }
  8419. else
  8420. {
  8421. tempIndex = gun_index;
  8422. }
  8423. for (int index = 0; index < AC_QUANTITY; index++)
  8424. {
  8425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8426. {
  8427. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8428. {
  8429. match = TRUE;
  8430. GunNO = gun_index;
  8431. }
  8432. }
  8433. }// END FOR CHAdeMO_QUANTITY
  8434. } // END FOR AC ELSE
  8435. }// CHECK IF ResponseTransactionId == transactionIdInt
  8436. }//END FOR
  8437. if( match == TRUE)
  8438. {
  8439. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8440. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8441. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8442. }
  8443. else
  8444. {
  8445. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8446. }
  8447. }
  8448. else
  8449. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8450. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8451. return result;
  8452. }
  8453. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8454. {
  8455. mtrace();
  8456. int result = FAIL;
  8457. int connectorIdInt=0, reservationIdInt=0;
  8458. int tempIndex = 0;
  8459. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8460. char comfirmstr[20]={0};
  8461. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8462. int c = 0;
  8463. char *loc;
  8464. //char *ptr;
  8465. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8466. strcpy(sstrtemp, stringtrimspace(payload));
  8467. //***(1)connectorId ****/
  8468. c=0;
  8469. loc = strstr(sstrtemp, "connectorId");
  8470. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8471. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8472. {
  8473. sstr[c] = loc[strlen("connectorId")+2+c];
  8474. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8475. c++;
  8476. }
  8477. sstr[c] = '\0';
  8478. connectorIdInt = atoi(sstr);
  8479. //***(2)expiryDate ****/
  8480. loc = strstr(sstrtemp, "expiryDate");
  8481. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8482. c = 0;
  8483. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8484. {
  8485. sstr[c] = loc[3+strlen("expiryDate")+c];
  8486. c++;
  8487. }
  8488. sstr[c] = '\0';
  8489. strcpy(expiryDatestr, sstr);
  8490. //***(3)idTag ****/
  8491. loc = strstr(sstrtemp, "idTag");
  8492. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8493. c = 0;
  8494. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8495. {
  8496. sstr[c] = loc[3+strlen("idTag")+c];
  8497. c++;
  8498. }
  8499. sstr[c] = '\0';
  8500. strcpy(idTagstr, sstr);
  8501. //***(4)parentIdTag ****/
  8502. loc = strstr(sstrtemp, "parentIdTag");
  8503. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8504. c = 0;
  8505. if(loc == NULL)
  8506. {
  8507. strcpy(parentIdTagstr, "");
  8508. }
  8509. else
  8510. {
  8511. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8512. {
  8513. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8514. c++;
  8515. }
  8516. sstr[c] = '\0';
  8517. strcpy(parentIdTagstr, sstr);
  8518. }
  8519. //***(5)reservationId ****/
  8520. c=0;
  8521. loc = strstr(sstrtemp, "reservationId");
  8522. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8523. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8524. {
  8525. sstr[c] = loc[strlen("reservationId")+2+c];
  8526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8527. c++;
  8528. }
  8529. sstr[c] = '\0';
  8530. reservationIdInt = atoi(sstr);
  8531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8532. /*
  8533. enum SYSTEM_STATUS
  8534. {
  8535. SYS_MODE_BOOTING = 0,
  8536. SYS_MODE_IDLE = 1,
  8537. SYS_MODE_AUTHORIZING = 2,
  8538. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8539. SYS_MODE_REASSIGN = 4,
  8540. SYS_MODE_PREPARING = 5,
  8541. SYS_MODE_PREPARE_FOR_EV = 6,
  8542. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8543. SYS_MODE_CHARGING = 8,
  8544. SYS_MODE_TERMINATING = 9,
  8545. SYS_MODE_COMPLETE = 10,
  8546. SYS_MODE_ALARM = 11,
  8547. SYS_MODE_FAULT = 12,
  8548. SYS_MODE_RESERVATION = 13,
  8549. SYS_MODE_BOOKING = 14,
  8550. SYS_MODE_MAINTAIN = 15,
  8551. SYS_MODE_DEBUG = 16,
  8552. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8553. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8554. SYS_MODE_UPDATE = 19
  8555. };
  8556. */
  8557. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8558. {
  8559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8560. goto end;
  8561. }
  8562. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8563. {
  8564. //check Transaction active
  8565. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8566. {
  8567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8568. {
  8569. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8570. }
  8571. else
  8572. {
  8573. tempIndex = connectorIdInt -1;
  8574. }
  8575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8576. {
  8577. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8578. {
  8579. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8580. {
  8581. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8582. {
  8583. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8584. {
  8585. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8587. }
  8588. 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'))
  8589. {
  8590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8591. }
  8592. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8593. {
  8594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8595. }
  8596. else
  8597. {
  8598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8599. }
  8600. }
  8601. 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
  8602. {
  8603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8604. }
  8605. }
  8606. else
  8607. {
  8608. //replace reservation
  8609. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8611. }
  8612. }
  8613. } // END FOR CHAdeMO_QUANTITY
  8614. }
  8615. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8616. {
  8617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8618. {
  8619. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8620. }
  8621. else
  8622. {
  8623. tempIndex = connectorIdInt -1;
  8624. }
  8625. for (int index = 0; index < CCS_QUANTITY; index++)
  8626. {
  8627. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8628. {
  8629. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8630. {
  8631. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8632. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8633. {
  8634. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8635. {
  8636. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8638. }
  8639. 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'))
  8640. {
  8641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8642. }
  8643. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8644. {
  8645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8646. }
  8647. else
  8648. {
  8649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8650. }
  8651. }
  8652. 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
  8653. {
  8654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8655. }
  8656. }
  8657. else
  8658. {
  8659. //replace reservation
  8660. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8662. }
  8663. }
  8664. } // END FOR CCS_QUANTITY
  8665. }
  8666. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8667. {
  8668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8669. {
  8670. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8671. }
  8672. else
  8673. {
  8674. tempIndex = connectorIdInt -1;
  8675. }
  8676. for (int index = 0; index < GB_QUANTITY; index++)
  8677. {
  8678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8679. {
  8680. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8681. {
  8682. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8683. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8684. {
  8685. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8686. {
  8687. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8689. }
  8690. 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'))
  8691. {
  8692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8693. }
  8694. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8695. {
  8696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8697. }
  8698. else
  8699. {
  8700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8701. }
  8702. }
  8703. 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
  8704. {
  8705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8706. }
  8707. }
  8708. else
  8709. {
  8710. //replace reservation
  8711. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8713. }
  8714. }
  8715. }// END FOR GB_QUANTITY
  8716. }
  8717. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8718. {
  8719. tempIndex = connectorIdInt -1;
  8720. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8721. {
  8722. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8723. {
  8724. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8725. {
  8726. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8727. 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
  8728. {
  8729. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8730. {
  8731. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8733. }
  8734. 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'))
  8735. {
  8736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8737. }
  8738. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8739. {
  8740. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8741. }
  8742. else
  8743. {
  8744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8745. }
  8746. }
  8747. 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
  8748. {
  8749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8750. }
  8751. }
  8752. else
  8753. {
  8754. //replace reservation
  8755. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8757. }
  8758. }
  8759. }// END FOR GB_QUANTITY
  8760. }
  8761. else
  8762. {
  8763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8764. {
  8765. tempIndex = 2;
  8766. }
  8767. else
  8768. {
  8769. tempIndex = (connectorIdInt -1);
  8770. }
  8771. for (int index = 0; index < AC_QUANTITY; index++)
  8772. {
  8773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8774. {
  8775. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8776. {
  8777. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8778. {
  8779. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8780. {
  8781. 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))
  8782. {
  8783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8784. }
  8785. else
  8786. {
  8787. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8789. }
  8790. }
  8791. 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'))
  8792. {
  8793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8794. }
  8795. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8796. {
  8797. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8798. }
  8799. else
  8800. {
  8801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8802. }
  8803. }
  8804. 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
  8805. {
  8806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8807. }
  8808. }
  8809. else
  8810. {
  8811. //replace reservation
  8812. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8814. }
  8815. }
  8816. } // END FOR AC_QUANTITY
  8817. }
  8818. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8819. }
  8820. else if(connectorIdInt == 0)
  8821. {
  8822. //check Transaction active
  8823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8824. {
  8825. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8826. {
  8827. 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'))
  8828. {
  8829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8830. goto end;
  8831. }
  8832. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8833. {
  8834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8835. goto end;
  8836. }
  8837. 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
  8838. {
  8839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8840. goto end;
  8841. }
  8842. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8843. {
  8844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8845. goto end;
  8846. }
  8847. }
  8848. }// END FOR CHAdeMO_QUANTITY
  8849. for (int index = 0; index < CCS_QUANTITY; index++)
  8850. {
  8851. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8852. {
  8853. 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'))
  8854. {
  8855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8856. goto end;
  8857. }
  8858. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8859. {
  8860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8861. goto end;
  8862. }
  8863. 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
  8864. {
  8865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8866. goto end;
  8867. }
  8868. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8869. {
  8870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8871. goto end;
  8872. }
  8873. }
  8874. } // END FOR CCS_QUANTITY
  8875. for (int index = 0; index < GB_QUANTITY; index++)
  8876. {
  8877. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8878. {
  8879. 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'))
  8880. {
  8881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8882. goto end;
  8883. }
  8884. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8885. {
  8886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8887. goto end;
  8888. }
  8889. 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
  8890. {
  8891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8892. goto end;
  8893. }
  8894. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8895. {
  8896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8897. goto end;
  8898. }
  8899. }
  8900. } // END FOR GB_QUANTITY
  8901. for (int index = 0; index < AC_QUANTITY; index++)
  8902. {
  8903. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8904. {
  8905. 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'))
  8906. {
  8907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8908. goto end;
  8909. }
  8910. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8911. {
  8912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8913. goto end;
  8914. }
  8915. 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
  8916. {
  8917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8918. goto end;
  8919. }
  8920. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8921. {
  8922. 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))
  8923. {
  8924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8925. goto end;
  8926. }
  8927. }
  8928. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8929. {
  8930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8931. goto end;
  8932. }
  8933. }
  8934. }// END FOR AC_QUANTITY
  8935. //The connectorId is 0
  8936. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8938. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8939. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8940. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8941. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8942. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8943. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8944. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8945. result = TRUE;
  8946. return result;
  8947. }
  8948. else
  8949. {
  8950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8951. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8952. }
  8953. if(strcmp(comfirmstr,"Accepted") == 0)
  8954. {
  8955. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8956. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8957. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8958. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8959. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8960. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8961. result = TRUE;
  8962. return result;
  8963. }
  8964. end:
  8965. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8966. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8967. return result;
  8968. }
  8969. int handleResetRequest(char *uuid, char *payload)
  8970. {
  8971. mtrace();
  8972. int result = FAIL;
  8973. char sstr[10]={0},sstrtemp[30]={ 0 };
  8974. char typestr[10]={0};
  8975. char comfirmstr[20]={0};
  8976. int c = 0;
  8977. char *loc;
  8978. DEBUG_INFO("handleResetRequest...\n");
  8979. strcpy(sstrtemp, stringtrimspace(payload));
  8980. loc = strstr(sstrtemp, "type");
  8981. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8982. c = 0;
  8983. while (loc[3+strlen("type")+c] != '\"')
  8984. {
  8985. sstr[c] = loc[3+strlen("type")+c];
  8986. c++;
  8987. }
  8988. sstr[c] = '\0';
  8989. strcpy(typestr,sstr);
  8990. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8991. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8992. {
  8993. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8994. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8995. result = TRUE;
  8996. return result;
  8997. }
  8998. else
  8999. {
  9000. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9001. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9002. goto errorend;
  9003. }
  9004. errorend:
  9005. sendResetConfirmation(uuid, comfirmstr);
  9006. return result;
  9007. }
  9008. int handleSendLocalListRequest(char *uuid, char *payload)
  9009. {
  9010. mtrace();
  9011. int result = FAIL;
  9012. int listVersionInt;
  9013. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9014. char listsearch[]="listVersion";
  9015. char updateTypesearch[]="updateType";
  9016. char localAuthorizationListsearch[]="localAuthorizationList";
  9017. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9018. char CardList[500][160]={0};
  9019. char updateTypestr[15]={0};
  9020. char idTagstr[20]={0};
  9021. char parentIdTag[20]={0};
  9022. char expiryDate[30]={0};
  9023. char idTagstatus[16]={0};
  9024. int c = 0;
  9025. int i = 0;
  9026. char *delim1 = "}";
  9027. char * pch;
  9028. char *loc;
  9029. //char *ptr;
  9030. char comfirmstr[20];
  9031. //int n_localAuthorizations = 0;
  9032. int checkState_Faulted = FALSE;
  9033. DEBUG_INFO("handleSendLocalListRequest...\n");
  9034. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9035. {
  9036. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9037. goto end;
  9038. }
  9039. //check Charge Point state
  9040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9041. {
  9042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9043. {
  9044. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9045. }
  9046. }
  9047. for (int index = 0; index < CCS_QUANTITY; index++)
  9048. {
  9049. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9050. {
  9051. checkState_Faulted = TRUE; //OCPP Status
  9052. }
  9053. }
  9054. for (int index = 0; index < GB_QUANTITY; index++)
  9055. {
  9056. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9057. {
  9058. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9059. }
  9060. }
  9061. //check Charge Point state
  9062. for (int index = 0; index < AC_QUANTITY; index++)
  9063. {
  9064. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9065. {
  9066. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9067. }
  9068. }
  9069. if(checkState_Faulted == TRUE)
  9070. {
  9071. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9072. goto end;
  9073. }
  9074. //Filter payload space
  9075. strcpy(sstrtemp, stringtrimspace(payload));
  9076. //listVersion
  9077. c = 0;
  9078. loc = strstr(sstrtemp, listsearch);
  9079. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9080. {
  9081. sstr[c] = loc[strlen("listVersion")+2+c];
  9082. c++;
  9083. }
  9084. sstr[c] = '\0';
  9085. listVersionInt = atoi(sstr);
  9086. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9087. //updateType
  9088. loc = strstr(sstrtemp, updateTypesearch);
  9089. c = 0;
  9090. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9091. {
  9092. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9093. c++;
  9094. }
  9095. sstr[c] = '\0';
  9096. strcpy(updateTypestr, sstr);
  9097. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9098. //localAuthorizationList
  9099. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9100. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9101. if(loc != NULL) // localAuthorizationList is not NULL
  9102. {
  9103. //Check UpdateType
  9104. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9105. {
  9106. //Local list full update
  9107. printf("Local list full update.\n");
  9108. OCPP_getListVerion();
  9109. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9110. {
  9111. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9112. goto end;
  9113. }
  9114. OCPP_cleanLocalList();
  9115. }
  9116. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9117. {
  9118. //Local list different update
  9119. printf("Local list different update.\n");
  9120. OCPP_getListVerion();
  9121. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9122. {
  9123. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9124. goto end;
  9125. }
  9126. }
  9127. else
  9128. {
  9129. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9130. goto end;
  9131. }
  9132. c = 0;
  9133. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9134. {
  9135. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9136. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9137. c++;
  9138. }
  9139. sstr[c] = '\0';
  9140. //DEBUG_INFO("sstr=%s\n", sstr);
  9141. //parsing strings to words
  9142. i = 0;
  9143. pch = strtok(sstr,delim1);
  9144. while (pch != NULL)
  9145. {
  9146. strcpy(CardList[i], pch);
  9147. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9148. pch = strtok (NULL, delim1);
  9149. i = i + 1;
  9150. }
  9151. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9152. //local Authorizations List Numbers
  9153. //n_localAuthorizations = i;
  9154. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9155. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9156. c= 0;
  9157. while(c < i) // i is CardList Number
  9158. {
  9159. //Search "IdToken"
  9160. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9161. loc = strstr(CardList[c], "idTag");
  9162. int j = 0;
  9163. while (loc[3+strlen("idTag")+j] != '\"')
  9164. {
  9165. sstr[j] = loc[3+strlen("idTag")+j];
  9166. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9167. j++;
  9168. }
  9169. sstr[j] = '\0';
  9170. strcpy(idTagstr, sstr);
  9171. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9172. //Search "expiryDate"
  9173. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9174. loc = strstr(CardList[c], "expiryDate");
  9175. j = 0;
  9176. if(loc != NULL)
  9177. {
  9178. while (loc[3+strlen("expiryDate")+j] != '\"')
  9179. {
  9180. sstr[j] = loc[3+strlen("expiryDate")+j];
  9181. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9182. j++;
  9183. }
  9184. sstr[j] = '\0';
  9185. strcpy(expiryDate, sstr);
  9186. }
  9187. else
  9188. {
  9189. strcpy(expiryDate, "");
  9190. }
  9191. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9192. //Search "parentIdTag"
  9193. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9194. loc = strstr(CardList[c], "parentIdTag");
  9195. j = 0;
  9196. if(loc != NULL)
  9197. {
  9198. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9199. {
  9200. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9201. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9202. j++;
  9203. }
  9204. sstr[j] = '\0';
  9205. strcpy(parentIdTag, sstr);
  9206. }
  9207. else
  9208. {
  9209. strcpy(parentIdTag, "");
  9210. }
  9211. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9212. //Search "status"
  9213. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9214. loc = strstr(CardList[c], "status");
  9215. j = 0;
  9216. while (loc[3+strlen("status")+j] != '\"')
  9217. {
  9218. sstr[j] = loc[3+strlen("status")+j];
  9219. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9220. j++;
  9221. }
  9222. sstr[j] = '\0';
  9223. strcpy(idTagstatus, sstr);
  9224. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9225. OCPP_getIdTagFromLocalList(idTagstr);
  9226. //OCPP_getIdTagFromLocalList("test"); For Test
  9227. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9228. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9229. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9230. {
  9231. //Local list full update
  9232. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9233. // update list
  9234. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9235. //DEBUG_INFO("Local list full update. 1\n");
  9236. //OCPP_get_TableAuthlocalAllData();
  9237. //DEBUG_INFO("Local list full update. 2\n");
  9238. }
  9239. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9240. {
  9241. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9242. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9243. }
  9244. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9245. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9246. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9247. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9248. c++;
  9249. }
  9250. }
  9251. else
  9252. {
  9253. //Check UpdateType
  9254. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9255. {
  9256. //Local list full update
  9257. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9258. OCPP_cleanLocalList();
  9259. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9260. goto end;
  9261. }
  9262. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9263. {
  9264. //Local list different update
  9265. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9266. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9267. goto end;
  9268. }
  9269. }
  9270. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9271. end:
  9272. sendSendLocalListConfirmation(uuid, comfirmstr);
  9273. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9274. return result;
  9275. }
  9276. #define MAX 200
  9277. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9278. {
  9279. mtrace();
  9280. int result = FAIL;
  9281. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9282. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9283. char chargingProfilePurposeStr[30]={0};
  9284. char chargingProfileKindStr[16]={0};
  9285. char recurrencyKindStr[10]={0};
  9286. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9287. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9288. int chargingSchedulePeriodCount = 0;
  9289. char comfirmstr[20]={0};
  9290. int meet= FALSE;
  9291. FILE *fptr1;
  9292. char filename[MAX]={0};
  9293. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9294. char rmFileCmd[50]={0};
  9295. char tempchargingProfilePurposeStr[30]={0};
  9296. char word[1600]={0};
  9297. int n_chargingProfile = 0;
  9298. json_object *SetChargingProfile;
  9299. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9300. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9301. SetChargingProfile = json_tokener_parse(payload);
  9302. if(!is_error(SetChargingProfile))
  9303. {
  9304. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9305. {
  9306. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9307. if(connectorIdInt == 0)
  9308. {
  9309. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9310. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9311. }
  9312. else
  9313. {
  9314. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9315. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9316. }
  9317. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9318. }
  9319. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9320. {
  9321. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9322. {
  9323. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9324. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9325. {
  9326. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9327. }
  9328. else
  9329. {
  9330. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9331. }
  9332. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9333. }
  9334. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9335. {
  9336. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9337. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9338. {
  9339. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9340. }
  9341. else
  9342. {
  9343. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9344. }
  9345. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9346. }
  9347. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9348. {
  9349. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9350. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9351. {
  9352. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9353. }
  9354. else
  9355. {
  9356. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9357. }
  9358. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9359. }
  9360. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9361. {
  9362. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9363. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9364. {
  9365. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9366. }
  9367. else
  9368. {
  9369. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9370. }
  9371. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9372. }
  9373. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9374. {
  9375. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9376. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9377. {
  9378. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9379. }
  9380. else
  9381. {
  9382. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9383. }
  9384. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9385. }
  9386. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9387. {
  9388. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9389. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9390. {
  9391. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9392. }
  9393. else
  9394. {
  9395. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9396. }
  9397. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9398. }
  9399. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9400. {
  9401. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9402. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9403. {
  9404. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9405. }
  9406. else
  9407. {
  9408. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9409. }
  9410. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9411. }
  9412. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9413. {
  9414. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9415. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9418. }
  9419. else
  9420. {
  9421. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9422. }
  9423. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9424. }
  9425. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9426. {
  9427. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9428. {
  9429. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9430. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9433. }
  9434. else
  9435. {
  9436. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9437. }
  9438. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9439. }
  9440. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9441. {
  9442. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9443. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9444. {
  9445. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9446. }
  9447. else
  9448. {
  9449. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9450. }
  9451. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9452. }
  9453. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9454. {
  9455. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9456. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9457. {
  9458. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9459. }
  9460. else
  9461. {
  9462. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9463. }
  9464. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9465. }
  9466. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9467. {
  9468. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9469. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9470. {
  9471. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9472. }
  9473. else
  9474. {
  9475. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9476. }
  9477. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9478. }
  9479. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9480. {
  9481. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9482. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9483. if(chargingSchedulePeriodCount <= 10)
  9484. {
  9485. 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++)
  9486. {
  9487. 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)
  9488. {
  9489. 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"));
  9490. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9491. {
  9492. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9493. }
  9494. else
  9495. {
  9496. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9497. }
  9498. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9499. }
  9500. 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)
  9501. {
  9502. 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"));
  9503. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9504. {
  9505. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9506. }
  9507. else
  9508. {
  9509. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9510. }
  9511. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9512. }
  9513. 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)
  9514. {
  9515. 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"));
  9516. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9517. {
  9518. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9519. }
  9520. else
  9521. {
  9522. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9523. }
  9524. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9525. }
  9526. }
  9527. }
  9528. }
  9529. }
  9530. }
  9531. }
  9532. json_object_put(SetChargingProfile);
  9533. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9534. {
  9535. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9536. goto end;
  9537. }
  9538. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9539. {
  9540. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9541. if(connectorIdInt != 0)
  9542. {
  9543. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9544. goto end;
  9545. }
  9546. strcpy(filename, ChargePointMaxProfile_JSON );
  9547. fptr1 = fopen(filename, "r");
  9548. if (!fptr1)
  9549. {
  9550. //file not exist
  9551. DEBUG_INFO("Unable to open the input file!!\n");
  9552. fptr1 = fopen(filename, "w+");
  9553. }
  9554. else
  9555. {
  9556. //Check Charging Profile Count
  9557. while(fscanf(fptr1, "%s", word) != EOF)
  9558. {
  9559. //DEBUG_INFO("word=%s\n",word);
  9560. if(strstr(word, "chargingProfileId")!= NULL)
  9561. {
  9562. //DEBUG_INFO("test chargingProfileId \n");
  9563. n_chargingProfile = n_chargingProfile + 1;
  9564. //DEBUG_INFO("chargingProfileId Found\n");
  9565. }
  9566. }
  9567. }
  9568. fclose(fptr1);
  9569. }
  9570. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9571. {
  9572. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9573. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9574. {
  9575. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9576. goto end;
  9577. }
  9578. memset(filename, 0, ARRAY_SIZE(filename));
  9579. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9580. fptr1 = fopen(filename, "r");
  9581. if (!fptr1)
  9582. {
  9583. //file not exist
  9584. //DEBUG_INFO("Unable to open the input file!!\n");
  9585. fptr1 = fopen(filename, "w+");
  9586. }
  9587. else
  9588. {
  9589. //Check Charging Profile Count
  9590. while(fscanf(fptr1, "%s", word) != EOF)
  9591. {
  9592. //DEBUG_INFO("word=%s\n",word);
  9593. if(strstr(word, "chargingProfileId")!= NULL)
  9594. {
  9595. //DEBUG_INFO("test chargingProfileId \n");
  9596. n_chargingProfile = n_chargingProfile + 1;
  9597. //DEBUG_INFO("chargingProfileId Found\n");
  9598. }
  9599. }
  9600. }
  9601. fclose(fptr1);
  9602. }
  9603. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9604. {
  9605. //printf("set chargingProfile 1-4\n");
  9606. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9607. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9608. if(connectorIdInt == 0)
  9609. {
  9610. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9611. goto end;
  9612. }
  9613. int tempIndex = 0;
  9614. //check Transaction active
  9615. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9616. {
  9617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9618. {
  9619. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9620. }
  9621. else
  9622. {
  9623. tempIndex = connectorIdInt -1;
  9624. }
  9625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9626. {
  9627. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9628. {
  9629. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9630. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9631. {
  9632. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9633. {
  9634. meet = TRUE;
  9635. break;
  9636. }
  9637. }
  9638. }
  9639. }
  9640. }
  9641. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9642. {
  9643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9644. {
  9645. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9646. }
  9647. else
  9648. {
  9649. tempIndex = connectorIdInt -1;
  9650. }
  9651. for (int index = 0; index < CCS_QUANTITY; index++)
  9652. {
  9653. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9654. {
  9655. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9656. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9657. {
  9658. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9659. {
  9660. meet = TRUE;
  9661. break;
  9662. }
  9663. }
  9664. }
  9665. }
  9666. }
  9667. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9668. {
  9669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9670. {
  9671. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9672. }
  9673. else
  9674. {
  9675. tempIndex = connectorIdInt -1;
  9676. }
  9677. for (int index = 0; index < GB_QUANTITY; index++)
  9678. {
  9679. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9680. {
  9681. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9682. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9683. {
  9684. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9685. {
  9686. meet = TRUE;
  9687. break;
  9688. }
  9689. }
  9690. }
  9691. }
  9692. }
  9693. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9694. {
  9695. tempIndex = connectorIdInt -1;
  9696. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9697. {
  9698. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9699. {
  9700. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9701. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9702. {
  9703. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9704. {
  9705. meet = TRUE;
  9706. break;
  9707. }
  9708. }
  9709. }
  9710. }
  9711. }
  9712. else
  9713. {
  9714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9715. {
  9716. tempIndex = 2;
  9717. }
  9718. else
  9719. {
  9720. tempIndex = (connectorIdInt -1);
  9721. }
  9722. for (int index = 0; index < AC_QUANTITY; index++)
  9723. {
  9724. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9725. {
  9726. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9727. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9728. {
  9729. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9730. {
  9731. meet = TRUE;
  9732. break;
  9733. }
  9734. }
  9735. }
  9736. }
  9737. }
  9738. //check Transaction active
  9739. if(meet == FALSE)
  9740. {
  9741. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9742. goto end;
  9743. }
  9744. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9745. {
  9746. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9747. goto end;
  9748. }
  9749. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9750. fptr1 = fopen(filename, "r");
  9751. if (!fptr1)
  9752. {
  9753. //file not exist
  9754. DEBUG_INFO("Unable to open the input file!!\n");
  9755. fptr1 = fopen(filename, "w+");
  9756. }
  9757. else
  9758. {
  9759. //Check Charging Profile Count
  9760. while(fscanf(fptr1, "%s", word) != EOF)
  9761. {
  9762. //DEBUG_INFO("word=%s\n",word);
  9763. if(strstr(word, "chargingProfileId")!= NULL)
  9764. {
  9765. //DEBUG_INFO("test chargingProfileId \n");
  9766. n_chargingProfile = n_chargingProfile + 1;
  9767. //DEBUG_INFO("chargingProfileId Found\n");
  9768. }
  9769. }
  9770. }
  9771. fclose(fptr1);
  9772. }
  9773. // Check ChargeProfileMaxStackLevel
  9774. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9775. {
  9776. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9777. goto end;
  9778. }
  9779. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9780. {
  9781. int i = 0;
  9782. char fnametemp[200]={0};
  9783. n_chargingProfile = 0;
  9784. //Check ChargePointMaxProfile.json exit
  9785. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9786. {
  9787. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9788. //Check Charging Profile Count
  9789. while(fscanf(fptr1, "%s", word) != EOF)
  9790. {
  9791. //DEBUG_INFO("word=%s\n",word);
  9792. if(strstr(word, "chargingProfileId")!= NULL)
  9793. {
  9794. //DEBUG_INFO("test chargingProfileId \n");
  9795. n_chargingProfile = n_chargingProfile + 1;
  9796. i = i + 1;
  9797. //DEBUG_INFO("chargingProfileId Found\n");
  9798. }
  9799. memset(word, 0, ARRAY_SIZE(word));
  9800. }
  9801. fclose(fptr1);
  9802. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9803. }
  9804. //Check TxDefaultProfile_0.json exit
  9805. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9806. {
  9807. i = 0;
  9808. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9809. //Check Charging Profile Count
  9810. while(fscanf(fptr1, "%s", word) != EOF)
  9811. {
  9812. //DEBUG_INFO("word=%s\n",word);
  9813. if(strstr(word, "chargingProfileId")!= NULL)
  9814. {
  9815. //DEBUG_INFO("test chargingProfileId \n");
  9816. n_chargingProfile = n_chargingProfile + 1;
  9817. i = i + 1;
  9818. //DEBUG_INFO("chargingProfileId Found\n");
  9819. }
  9820. memset(word, 0, ARRAY_SIZE(word));
  9821. }
  9822. fclose(fptr1);
  9823. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9824. }
  9825. //Check TxDefaultProfile_%d.json
  9826. for(int j=1; j <= gunTotalNumber; j++)
  9827. {
  9828. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9829. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9830. if((access(fnametemp,F_OK))!=-1)
  9831. {
  9832. i = 0;
  9833. fptr1 = fopen(fnametemp, "r");
  9834. //Check Charging Profile Count
  9835. while(fscanf(fptr1, "%s", word) != EOF)
  9836. {
  9837. //DEBUG_INFO("word=%s\n",word);
  9838. if(strstr(word, "chargingProfileId")!= NULL)
  9839. {
  9840. //DEBUG_INFO("test chargingProfileId \n");
  9841. n_chargingProfile = n_chargingProfile + 1;
  9842. i = i + 1;
  9843. //DEBUG_INFO("chargingProfileId Found\n");
  9844. }
  9845. memset(word, 0, ARRAY_SIZE(word));
  9846. }
  9847. fclose(fptr1);
  9848. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9849. }
  9850. }
  9851. //Check TxProfile_%d.json
  9852. for(int j=1; j <= gunTotalNumber; j++)
  9853. {
  9854. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9855. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9856. if((access(fnametemp,F_OK))!=-1)
  9857. {
  9858. i = 0;
  9859. fptr1 = fopen(fnametemp, "r");
  9860. //Check Charging Profile Count
  9861. while(fscanf(fptr1, "%s", word) != EOF)
  9862. {
  9863. //DEBUG_INFO("word=%s\n",word);
  9864. if(strstr(word, "chargingProfileId")!= NULL)
  9865. {
  9866. //DEBUG_INFO("test chargingProfileId \n");
  9867. n_chargingProfile = n_chargingProfile + 1;
  9868. i = i + 1;
  9869. //DEBUG_INFO("chargingProfileId Found\n");
  9870. }
  9871. memset(word, 0, ARRAY_SIZE(word));
  9872. }
  9873. fclose(fptr1);
  9874. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9875. }
  9876. }
  9877. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9878. {
  9879. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9880. goto end;
  9881. }
  9882. }
  9883. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9884. //**********************************Write to File********************************************************/
  9885. FILE *infile;
  9886. FILE *outfile;
  9887. infile = fopen (filename, "r");
  9888. outfile = fopen (tempfile, "w");
  9889. int d =0;
  9890. d = fgetc(infile);
  9891. rewind(infile);
  9892. if(d == EOF)
  9893. {
  9894. // Profile is empty
  9895. fprintf(outfile,"%s\n",payload);
  9896. fclose(infile);
  9897. fclose(outfile);
  9898. sprintf(rmFileCmd,"rm -f %s",filename);
  9899. system(rmFileCmd);
  9900. rename(tempfile, filename);
  9901. }
  9902. else
  9903. {
  9904. // Profile is not empty
  9905. char buf[2048]={0};
  9906. int ChargingProfileAdded = FALSE;
  9907. while (fgets(buf, sizeof(buf), infile) != NULL)
  9908. {
  9909. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9910. json_object *tmpChargingProfile;
  9911. tmpChargingProfile = json_tokener_parse(buf);
  9912. if(!is_error(SetChargingProfile))
  9913. {
  9914. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9915. {
  9916. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9917. }
  9918. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9919. {
  9920. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9921. {
  9922. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9923. }
  9924. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9925. {
  9926. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9927. }
  9928. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9929. {
  9930. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9931. }
  9932. }
  9933. }
  9934. json_object_put(tmpChargingProfile);
  9935. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9936. {
  9937. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9938. {
  9939. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9940. if(ChargingProfileAdded == FALSE)
  9941. {
  9942. fprintf(outfile,"%s\n",payload);
  9943. ChargingProfileAdded = TRUE;
  9944. }
  9945. }
  9946. else
  9947. {
  9948. if(tempstackLevelInt < stackLevelInt)
  9949. {
  9950. if(ChargingProfileAdded == FALSE)
  9951. {
  9952. fprintf(outfile,"%s\n",buf);
  9953. fprintf(outfile,"%s\n",payload);
  9954. ChargingProfileAdded = TRUE;
  9955. }
  9956. else
  9957. {
  9958. fprintf(outfile,"%s\n",buf);
  9959. }
  9960. }
  9961. else
  9962. {
  9963. if(ChargingProfileAdded == FALSE)
  9964. {
  9965. fprintf(outfile,"%s\n",buf);
  9966. fprintf(outfile,"%s\n",payload);
  9967. ChargingProfileAdded = TRUE;
  9968. }
  9969. else
  9970. {
  9971. fprintf(outfile,"%s\n",buf);
  9972. }
  9973. }
  9974. }
  9975. }
  9976. else
  9977. {
  9978. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9979. {
  9980. if(ChargingProfileAdded == FALSE)
  9981. {
  9982. fprintf(outfile,"%s\n",buf);
  9983. fprintf(outfile,"%s\n",payload);
  9984. ChargingProfileAdded = TRUE;
  9985. }
  9986. else
  9987. {
  9988. fprintf(outfile,"%s\n",buf);
  9989. }
  9990. }
  9991. else if(tempstackLevelInt < stackLevelInt)
  9992. {
  9993. if(ChargingProfileAdded == FALSE)
  9994. {
  9995. fprintf(outfile,"%s\n",buf);
  9996. fprintf(outfile,"%s\n",payload);
  9997. ChargingProfileAdded = TRUE;
  9998. }
  9999. else
  10000. {
  10001. fprintf(outfile,"%s\n",buf);
  10002. }
  10003. }
  10004. else
  10005. {
  10006. if(ChargingProfileAdded == FALSE)
  10007. {
  10008. fprintf(outfile,"%s\n",buf);
  10009. fprintf(outfile,"%s\n",payload);
  10010. ChargingProfileAdded = TRUE;
  10011. }
  10012. else
  10013. {
  10014. fprintf(outfile,"%s\n",buf);
  10015. }
  10016. }
  10017. }
  10018. } // end of while loop
  10019. fclose(infile);
  10020. fclose(outfile);
  10021. sprintf(rmFileCmd,"rm -f %s",filename);
  10022. system(rmFileCmd);
  10023. rename(tempfile, filename);
  10024. }
  10025. sleep(1);
  10026. result = TRUE;
  10027. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10028. end:
  10029. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10030. {
  10031. if(connectorIdInt == 0)
  10032. {
  10033. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10034. {
  10035. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10036. }
  10037. }
  10038. else
  10039. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10040. }
  10041. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10042. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10043. return result;
  10044. }
  10045. int handleTriggerMessageRequest(char *uuid, char *payload)
  10046. {
  10047. mtrace();
  10048. int result = FAIL;
  10049. int connectorIdIsNULL = FALSE;
  10050. int connectorIdInt =0;
  10051. char sstr[40]={0},sstrtemp[100]={ 0 };
  10052. char requestedMessagestr[40]={0};
  10053. char comfirmstr[20]={0};
  10054. int c = 0;
  10055. char *loc;
  10056. DEBUG_INFO("handleTriggerMessageRequest\n");
  10057. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10058. strcpy(sstrtemp, stringtrimspace(payload));
  10059. c = 0;
  10060. loc = strstr(sstrtemp, "requestedMessage");
  10061. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10062. {
  10063. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10064. c++;
  10065. }
  10066. sstr[c] = '\0';
  10067. strcpy(requestedMessagestr, sstr);
  10068. c = 0;
  10069. loc = strstr(sstrtemp, "connectorId");
  10070. if(loc == NULL)
  10071. {
  10072. connectorIdIsNULL = TRUE;
  10073. }
  10074. else
  10075. {
  10076. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10077. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10078. {
  10079. sstr[c] = loc[strlen("connectorId")+2+c];
  10080. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10081. c++;
  10082. }
  10083. sstr[c] = '\0';
  10084. connectorIdInt = atoi(sstr);
  10085. }
  10086. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10087. {
  10088. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10089. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10090. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10091. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10092. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10093. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10094. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10095. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10096. {
  10097. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10098. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10099. return TRUE;
  10100. }
  10101. else
  10102. {
  10103. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10104. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10105. }
  10106. }
  10107. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10108. {
  10109. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10110. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10111. return TRUE;
  10112. }
  10113. //==========================
  10114. // Trigger message
  10115. //==========================
  10116. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10117. {
  10118. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10119. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10120. {
  10121. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10122. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10123. }
  10124. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10125. }
  10126. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10127. {
  10128. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10129. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10130. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10131. }
  10132. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10133. {
  10134. //sendBootNotificationRequest();
  10135. server_sign = FALSE;
  10136. }
  10137. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10138. {
  10139. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10140. }
  10141. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10142. {
  10143. if(connectorIdIsNULL == FALSE)
  10144. {
  10145. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10146. {
  10147. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10148. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10149. }
  10150. }
  10151. else
  10152. {
  10153. for(int idx=0;idx< gunTotalNumber;idx++)
  10154. {
  10155. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10156. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10157. }
  10158. }
  10159. }
  10160. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10161. {
  10162. if(connectorIdIsNULL == FALSE)
  10163. {
  10164. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10165. {
  10166. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10167. }
  10168. }
  10169. else
  10170. {
  10171. for(int idx=0;idx< gunTotalNumber;idx++)
  10172. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10173. }
  10174. }
  10175. return result;
  10176. }
  10177. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10178. {
  10179. mtrace();
  10180. int result = FAIL;
  10181. int connectorIdInt =0;
  10182. char comfirmstr[20]={0};
  10183. int tempIndex = 0;
  10184. json_object *UnlockConnector;
  10185. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10186. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10187. UnlockConnector = json_tokener_parse(payload);
  10188. if(!is_error(UnlockConnector))
  10189. {
  10190. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10191. {
  10192. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10193. }
  10194. }
  10195. json_object_put(UnlockConnector);
  10196. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10197. if(gunTotalNumber == 0)
  10198. {
  10199. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10200. goto end;
  10201. }
  10202. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10203. {
  10204. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10205. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10206. goto end;
  10207. }
  10208. else
  10209. {
  10210. //check Transaction active
  10211. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10212. {
  10213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10214. {
  10215. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10216. }
  10217. else
  10218. {
  10219. tempIndex = connectorIdInt -1;
  10220. }
  10221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10222. {
  10223. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10224. {
  10225. //stop Transaction
  10226. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10227. }
  10228. }
  10229. }
  10230. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10231. {
  10232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10233. {
  10234. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10235. }
  10236. else
  10237. {
  10238. tempIndex = connectorIdInt -1;
  10239. }
  10240. for (int index = 0; index < CCS_QUANTITY; index++)
  10241. {
  10242. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10243. {
  10244. //stop Transaction
  10245. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10246. }
  10247. }
  10248. }
  10249. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10250. {
  10251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10252. {
  10253. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10254. }
  10255. else
  10256. {
  10257. tempIndex = connectorIdInt -1;
  10258. }
  10259. for (int index = 0; index < GB_QUANTITY; index++)
  10260. {
  10261. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10262. {
  10263. //stop Transaction
  10264. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10265. }
  10266. }
  10267. }
  10268. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10269. {
  10270. tempIndex = connectorIdInt -1;
  10271. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10272. {
  10273. 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)))
  10274. {
  10275. //stop Transaction
  10276. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10277. }
  10278. }
  10279. }
  10280. else
  10281. {
  10282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10283. {
  10284. tempIndex = 2;
  10285. }
  10286. else
  10287. {
  10288. tempIndex = connectorIdInt-1;
  10289. }
  10290. for (int index = 0; index < AC_QUANTITY; index++)
  10291. {
  10292. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10293. {
  10294. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10295. }
  10296. }
  10297. }
  10298. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10299. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10300. result = TRUE;
  10301. return result;
  10302. }
  10303. end:
  10304. //json_object_put(obj); --- remove temporally
  10305. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10306. return result;
  10307. }
  10308. static char UpdateFirmwarepayloadData[300]={0};
  10309. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10310. {
  10311. mtrace();
  10312. int result = FAIL;
  10313. pthread_t t;
  10314. sendUpdateFirmwareConfirmation(uuid);
  10315. memset(UpdateFirmwarepayloadData, 0, 300);
  10316. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10317. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10318. ////pthread_join(t, NULL); //
  10319. //pthread_detach(t);
  10320. //sendUpdateFirmwareConfirmation(uuid);
  10321. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10322. return result;
  10323. }
  10324. void *UpdateFirmwareProcess(void *data)
  10325. {
  10326. pthread_detach(pthread_self());
  10327. mtrace();
  10328. int retriesInt =0, retryIntervalInt=0;
  10329. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10330. int port=0;
  10331. char locationstr[160]={0}, retrieveDatestr[30]={0};
  10332. int isSuccess = 0;
  10333. char ftpbuf[200];
  10334. char temp[100];
  10335. char * pch;
  10336. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10337. json_object *UpdateFirmware;
  10338. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10339. if(!is_error(UpdateFirmware))
  10340. {
  10341. // Required data
  10342. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10343. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10344. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10345. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10346. // Optional data
  10347. if(json_object_object_get(UpdateFirmware, "retries"))
  10348. {
  10349. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10350. }
  10351. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10352. {
  10353. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10354. }
  10355. }
  10356. json_object_put(UpdateFirmware);
  10357. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10358. memset(path, 0, ARRAY_SIZE(path));
  10359. system("rm -f /mnt/*");
  10360. if(strncmp(locationstr,"http", 4) == 0)
  10361. {
  10362. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10363. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  10364. // protocol, user, password, host, path);
  10365. sprintf(ftppath,"/%s", path);
  10366. DEBUG_INFO("locationstr: %s\n", locationstr);
  10367. DEBUG_INFO("protocol: %s\n",protocol);
  10368. DEBUG_INFO("host: %s\n",host);
  10369. DEBUG_INFO("path: %s\n",path);
  10370. DEBUG_INFO("ftppath: %s\n",ftppath);
  10371. int ftppathlen=strlen(ftppath);
  10372. int i=1;
  10373. char filenametemp[50];
  10374. while(i < ftppathlen)
  10375. {
  10376. int len=ftppathlen-i;
  10377. if(ftppath[len]== 47) // '/' ascll code: 47
  10378. {
  10379. DEBUG_INFO("compare '/' all right\n");
  10380. break;
  10381. }
  10382. i=i+1;
  10383. }
  10384. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10385. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10386. filenametemp[i+1] = 0;
  10387. do
  10388. {
  10389. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10390. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10391. sleep(3);
  10392. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10393. if(!isSuccess)
  10394. {
  10395. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10396. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10397. sleep(retryIntervalInt);
  10398. }
  10399. else
  10400. {
  10401. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10402. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10403. }
  10404. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  10405. }
  10406. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10407. {
  10408. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10409. memset(temp, 0, ARRAY_SIZE(temp));
  10410. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10411. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10412. int ftppathlen=strlen(ftpbuf);
  10413. int i=1;
  10414. char filenametemp[50];
  10415. while(i < ftppathlen)
  10416. {
  10417. int len=ftppathlen-i;
  10418. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10419. {
  10420. DEBUG_INFO(" compare '/' all right\n");
  10421. break;
  10422. }
  10423. i=i+1;
  10424. }
  10425. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10426. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10427. filenametemp[i+1] = 0;
  10428. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10429. pch=strchr(temp,'@');
  10430. if(pch==NULL)
  10431. {
  10432. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10433. protocol, host, &port, path);
  10434. strcpy(user,"anonymous");
  10435. strcpy(password,"");
  10436. }
  10437. else
  10438. {
  10439. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10440. protocol, user, password, host, &port, path);
  10441. }
  10442. sscanf(host,"%[^/]%s",host1, path1);
  10443. sprintf(ftppath,"%s", path1);
  10444. //DEBUG_INFO("protocol =%s\n",protocol);
  10445. //DEBUG_INFO("user =%s\n",user);
  10446. //DEBUG_INFO("password =%s\n",password);
  10447. //DEBUG_INFO("host1 =%s\n",host1);
  10448. //DEBUG_INFO("port =%d\n",port);
  10449. //DEBUG_INFO("path1 =%s\n",path1);
  10450. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10451. //ftpFile(host, user, password, port, ftppath, fname);
  10452. //download firmware pthred
  10453. if(port == 0)
  10454. {
  10455. port = 21;
  10456. }
  10457. do
  10458. {
  10459. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10460. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10461. sleep(3);
  10462. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10463. if(!isSuccess)
  10464. {
  10465. //BulldogUtil.sleepMs(interval*1000);
  10466. DEBUG_INFO("Update firmware request and download file fail.\n");
  10467. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10468. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10469. sleep(retryIntervalInt);
  10470. }
  10471. else
  10472. {
  10473. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10474. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10475. }
  10476. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  10477. }
  10478. else
  10479. {
  10480. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10481. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10482. }
  10483. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10484. pthread_exit(NULL);
  10485. }
  10486. int handleCertificateSignedRequest(char *uuid, char *payload)
  10487. {
  10488. mtrace();
  10489. int result = PASS;
  10490. json_object *CertificateSigned;
  10491. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10492. CertificateSigned = json_tokener_parse(payload);
  10493. if(!is_error(CertificateSigned))
  10494. {
  10495. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10496. }
  10497. json_object_put(CertificateSigned);
  10498. FILE *fp = fopen("/Storage/OCPP/cert.crt", "w");
  10499. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10500. fclose(fp);
  10501. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10502. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10503. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10504. sendCertificateSignedConfirmation(uuid);
  10505. return result;
  10506. }
  10507. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10508. {
  10509. mtrace();
  10510. int result = PASS;
  10511. json_object *DeleteCertificate;
  10512. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10513. DeleteCertificate = json_tokener_parse(payload);
  10514. if(!is_error(DeleteCertificate))
  10515. {
  10516. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10517. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10518. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10519. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10520. }
  10521. json_object_put(DeleteCertificate);
  10522. /*
  10523. * TODO: Delete certificateSigned process
  10524. */
  10525. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10526. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10527. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10528. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10529. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10530. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10531. sendDeleteCertificateConfirmation(uuid);
  10532. return result;
  10533. }
  10534. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10535. {
  10536. mtrace();
  10537. int result = PASS;
  10538. json_object *ExtendedTriggerMessage;
  10539. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10540. ExtendedTriggerMessage = json_tokener_parse(payload);
  10541. if(!is_error(ExtendedTriggerMessage))
  10542. {
  10543. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10544. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10545. {
  10546. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10547. }
  10548. else
  10549. {
  10550. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10551. }
  10552. }
  10553. json_object_put(ExtendedTriggerMessage);
  10554. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10555. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10556. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10557. {
  10558. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10559. }
  10560. else
  10561. {
  10562. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10563. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10564. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10565. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10566. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10567. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10568. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10569. {
  10570. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10571. }
  10572. else
  10573. {
  10574. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10575. }
  10576. }
  10577. sendExtendedTriggerMessageConfirmation(uuid);
  10578. //==========================
  10579. // Trigger message
  10580. //==========================
  10581. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10582. {
  10583. //sendBootNotificationRequest();
  10584. server_sign = FALSE;
  10585. }
  10586. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10587. {
  10588. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10589. }
  10590. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10591. {
  10592. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10593. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10594. {
  10595. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10596. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10597. }
  10598. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10599. }
  10600. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10601. {
  10602. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10603. }
  10604. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10605. {
  10606. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10607. {
  10608. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10609. }
  10610. else
  10611. {
  10612. for(int idx=0;idx< gunTotalNumber;idx++)
  10613. {
  10614. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10615. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10616. }
  10617. }
  10618. }
  10619. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10620. {
  10621. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10622. if(access("/Storage/OCPP/cert.csr",F_OK) == -1)
  10623. {
  10624. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/cert.csr -nodes -keyout /Storage/OCPP/cert.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  10625. }
  10626. }
  10627. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10628. {
  10629. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10630. {
  10631. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10632. }
  10633. else
  10634. {
  10635. for(int idx=0;idx< gunTotalNumber;idx++)
  10636. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10637. }
  10638. }
  10639. return result;
  10640. }
  10641. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10642. {
  10643. mtrace();
  10644. int result = PASS;
  10645. json_object *GetInstalledCertificateIds;
  10646. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10647. GetInstalledCertificateIds = json_tokener_parse(payload);
  10648. if(!is_error(GetInstalledCertificateIds))
  10649. {
  10650. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10651. }
  10652. json_object_put(GetInstalledCertificateIds);
  10653. /*
  10654. * TODO: Return installed certificate process
  10655. */
  10656. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10657. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10658. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10659. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10660. sendGetInstalledCertificateIdsConfirmation(uuid);
  10661. return result;
  10662. }
  10663. int handleGetLogRequest(char *uuid, char *payload)
  10664. {
  10665. mtrace();
  10666. int result = PASS;
  10667. json_object *GetLog;
  10668. DEBUG_INFO("handleGetLogRequest...\n");
  10669. GetLog = json_tokener_parse(payload);
  10670. if(!is_error(GetLog))
  10671. {
  10672. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10673. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10674. if(json_object_object_get(GetLog, "retries") != NULL)
  10675. {
  10676. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10677. }
  10678. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10679. {
  10680. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10681. }
  10682. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10683. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10684. {
  10685. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10686. }
  10687. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10688. {
  10689. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10690. }
  10691. }
  10692. json_object_put(GetLog);
  10693. /*
  10694. * TODO: Upload log process
  10695. */
  10696. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10697. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10698. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10699. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10700. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10701. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10702. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10703. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10704. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10705. sendGetLogConfirmation(uuid);
  10706. return result;
  10707. }
  10708. int handleInstallCertificateRequest(char *uuid, char *payload)
  10709. {
  10710. mtrace();
  10711. int result = PASS;
  10712. json_object *InstallCertificate;
  10713. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10714. InstallCertificate = json_tokener_parse(payload);
  10715. if(!is_error(InstallCertificate))
  10716. {
  10717. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10718. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10719. /*
  10720. * TODO: Install certificate process
  10721. */
  10722. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10723. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10724. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10725. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10726. sendInstallCertificateConfirmation(uuid);
  10727. }
  10728. json_object_put(InstallCertificate);
  10729. return result;
  10730. }
  10731. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10732. {
  10733. mtrace();
  10734. int result = PASS;
  10735. json_object *SignedUpdateFirmware;
  10736. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10737. SignedUpdateFirmware = json_tokener_parse(payload);
  10738. if(!is_error(SignedUpdateFirmware))
  10739. {
  10740. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10741. {
  10742. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10743. }
  10744. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10745. {
  10746. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10747. }
  10748. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10749. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10750. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10751. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10752. {
  10753. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10754. }
  10755. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10756. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10757. }
  10758. json_object_put(SignedUpdateFirmware);
  10759. /*
  10760. * TODO: Upgrade firmware process
  10761. */
  10762. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10763. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10764. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10765. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10766. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10767. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10768. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10769. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10770. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10771. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10772. sendInstallCertificateConfirmation(uuid);
  10773. return result;
  10774. }
  10775. int handleUnknownRequest(char *uuid, char *payload)
  10776. {
  10777. mtrace();
  10778. int result = PASS;
  10779. DEBUG_INFO("handleUnknownRequest...\n");
  10780. sendUnknownConfirmation(uuid);
  10781. result = PASS;
  10782. return result;
  10783. }
  10784. //==========================================
  10785. // Handle server response routine
  10786. //==========================================
  10787. void handleAuthorizeResponse(char *payload, int gun_index)
  10788. {
  10789. mtrace();
  10790. char expiryDatestr[30]={0};
  10791. char parentIdTagstr[20]={0};
  10792. char statusstr[20]={0};
  10793. int expiryDateISNULL=FALSE;
  10794. int parentIdTagISNULL=FALSE;
  10795. DEBUG_INFO("handleAuthorizeResponse...\n");
  10796. json_object *Authorize;
  10797. Authorize = json_tokener_parse(payload);
  10798. if(!is_error(Authorize))
  10799. {
  10800. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10801. {
  10802. // Required data
  10803. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10804. // Optional data
  10805. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10806. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10807. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10808. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10809. }
  10810. }
  10811. json_object_put(Authorize);
  10812. if(expiryDateISNULL == FALSE)
  10813. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10814. if(parentIdTagISNULL == FALSE)
  10815. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10816. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10817. //Update idTag information to authorization cache if supproted
  10818. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10819. {
  10820. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10821. }
  10822. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10823. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10824. authorizeRetryTimes = 0;
  10825. }
  10826. void handleBootNotificationResponse(char *payload, int gun_index)
  10827. {
  10828. mtrace();
  10829. char statusStr[12]={0};
  10830. char currentTimeStr[30]={0};
  10831. int intervalInt = 0;
  10832. DEBUG_INFO("handleBootNotificationResponse...\n");
  10833. json_object *BootNotification;
  10834. BootNotification = json_tokener_parse(payload);
  10835. if(!is_error(BootNotification))
  10836. {
  10837. // Required data
  10838. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10839. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10840. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10841. }
  10842. json_object_put(BootNotification);
  10843. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10844. BootNotificationInterval = intervalInt;
  10845. HeartBeatWaitTime = intervalInt;
  10846. //write back to ShmOCPP16Data->BootNotification
  10847. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10848. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10849. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10850. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10851. {
  10852. server_sign = TRUE;
  10853. server_pending =FALSE;
  10854. }
  10855. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10856. {
  10857. server_pending = TRUE;
  10858. }
  10859. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10860. srand(time(NULL));
  10861. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10862. SetOcppConnStatus(TRUE);
  10863. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10864. }
  10865. void handleDataTransferResponse(char *payload, int gun_index)
  10866. {
  10867. char sstr[160]={0};//sstr[200]={ 0 };
  10868. int c = 0;
  10869. char *loc;
  10870. DEBUG_INFO("handleDataTransferResponse ...\n");
  10871. loc = strstr(payload, "status");
  10872. printf("loc=%s\n",loc);
  10873. c = 0;
  10874. while (loc[3+strlen("status")+c] != '\"')
  10875. {
  10876. sstr[c] = loc[3+strlen("status")+c];
  10877. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10878. c++;
  10879. }
  10880. sstr[c] = '\0';
  10881. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10882. }
  10883. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10884. {
  10885. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10886. //struct json_object *obj;
  10887. // obj = json_tokener_parse(payload);
  10888. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10889. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10890. //No fields are defined.
  10891. }
  10892. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10893. {
  10894. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10895. //struct json_object *obj;
  10896. // obj = json_tokener_parse(payload);
  10897. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10898. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10899. //No fields are defined.
  10900. }
  10901. void handleHeartbeatResponse(char *payload, int gun_index)
  10902. {
  10903. mtrace();
  10904. DEBUG_INFO("handleHeartbeatResponse...\n");
  10905. json_object *Heartbeat;
  10906. Heartbeat = json_tokener_parse(payload);
  10907. if(!is_error(Heartbeat))
  10908. {
  10909. // Required data
  10910. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10911. }
  10912. json_object_put(Heartbeat);
  10913. if(FirstHeartBeat == 0)
  10914. {
  10915. FirstHeartBeat = 1;
  10916. DEBUG_INFO("FirstHeartBeat \n");
  10917. }
  10918. HeartBeatWithNOResponse = 0;
  10919. clientTime.Heartbeat=time((time_t*)NULL);
  10920. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  10921. }
  10922. void handleMeterValuesResponse(char *payload, int gun_index)
  10923. {
  10924. mtrace();
  10925. DEBUG_INFO("handleMeterValuesResponse...\n");
  10926. }
  10927. void handleStartTransactionResponse(char *payload, int gun_index)
  10928. {
  10929. mtrace();
  10930. //int transactionIdInt = 0;
  10931. FILE *outfile;
  10932. char data[100]={0};
  10933. DEBUG_INFO("handleStartTransactionResponse...\n");
  10934. json_object *StartTransaction;
  10935. StartTransaction = json_tokener_parse(payload);
  10936. if(!is_error(StartTransaction))
  10937. {
  10938. // Required data
  10939. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10940. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10941. // Optional data
  10942. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10943. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10944. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10945. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10946. }
  10947. json_object_put(StartTransaction);
  10948. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10949. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10950. //-----------Start : write to the Queue TransactionId file -----------------//
  10951. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10952. {}
  10953. else
  10954. {
  10955. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10956. if(log == NULL)
  10957. {
  10958. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10959. return ;
  10960. }
  10961. else
  10962. {
  10963. fclose(log);
  10964. }
  10965. }
  10966. // open file for writing
  10967. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10968. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10969. {
  10970. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10971. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10972. fputs(data, outfile);
  10973. fclose (outfile);
  10974. }
  10975. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10976. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10977. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10978. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10979. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10980. }
  10981. void handleStatusNotificationResponse(char *payload, int gun_index)
  10982. {
  10983. mtrace();
  10984. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10985. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10986. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10987. }
  10988. void handleStopTransactionnResponse(char *payload, int gun_index)
  10989. {
  10990. mtrace();
  10991. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10992. json_object *StopTransaction;
  10993. StopTransaction = json_tokener_parse(payload);
  10994. if(!is_error(StopTransaction))
  10995. {
  10996. // Optional data
  10997. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10998. {
  10999. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11000. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11001. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11002. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11003. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11004. }
  11005. }
  11006. json_object_put(StopTransaction);
  11007. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11008. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11009. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11010. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11011. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11012. }
  11013. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11014. {
  11015. mtrace();
  11016. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11017. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11018. }
  11019. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11020. {
  11021. mtrace();
  11022. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11023. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11024. }
  11025. void handleSignCertificateResponse(char *payload, int gun_index)
  11026. {
  11027. mtrace();
  11028. DEBUG_INFO("handleSignCertificateResponse...\n");
  11029. json_object *SignCertificate;
  11030. SignCertificate = json_tokener_parse(payload);
  11031. if(!is_error(SignCertificate))
  11032. {
  11033. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11034. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11035. }
  11036. json_object_put(SignCertificate);
  11037. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11038. }
  11039. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11040. {
  11041. mtrace();
  11042. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11043. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11044. }
  11045. //==========================================
  11046. // Handle Error routine
  11047. //==========================================
  11048. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11049. {
  11050. mtrace();
  11051. #ifdef SystemLogMessage
  11052. DEBUG_INFO("errorCode: %s\n", errorCode);
  11053. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11054. DEBUG_INFO("errorDetails: %s\n", payload);
  11055. #endif
  11056. }
  11057. //===============================================
  11058. // Common routine
  11059. //===============================================
  11060. int initialConfigurationTable(void)
  11061. {
  11062. //clock_t start_t, end_t, total_t;
  11063. FILE *fp;
  11064. FILE *outfile;
  11065. char str[512]={0};
  11066. char sstr[256]={0};
  11067. int c = 0;
  11068. char *loc;
  11069. int confVersion = 1;
  11070. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11071. //start_t = clock();
  11072. //printf("Starting of the program, start_t = %ld\n", start_t);
  11073. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11074. // Check configuration file size is correct
  11075. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11076. {
  11077. struct stat st;
  11078. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11079. if(st.st_size < 3100)
  11080. {
  11081. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11082. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11083. }
  11084. }
  11085. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11086. {
  11087. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11088. if(outfile == NULL)
  11089. {
  11090. DEBUG_INFO("Error opening file\n");
  11091. return FALSE;
  11092. }
  11093. /*Core Profile*/
  11094. //AllowOfflineTxForUnknownId
  11095. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11099. //AuthorizationCacheEnabled
  11100. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11104. //AuthorizeRemoteTxRequests
  11105. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11109. //BlinkRepeat
  11110. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11114. //ClockAlignedDataInterval
  11115. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11119. //ConnectionTimeOut
  11120. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11124. //GetConfigurationMaxKeys
  11125. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11129. // HeartbeatInterval
  11130. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11134. // LightIntensity
  11135. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11139. // LocalAuthorizeOffline
  11140. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11144. // LocalPreAuthorize
  11145. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11149. // MaxEnergyOnInvalidId
  11150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11154. // MeterValuesAlignedData
  11155. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11157. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11159. else
  11160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11162. // MeterValuesAlignedDataMaxLength
  11163. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11167. else
  11168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11170. // MeterValuesSampledData
  11171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11175. else
  11176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11178. // MeterValuesSampledDataMaxLength
  11179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11183. else
  11184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11186. // MeterValueSampleInterval
  11187. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11191. // MinimumStatusDuration
  11192. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11195. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11197. // NumberOfConnectors
  11198. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11200. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11201. {
  11202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11203. }
  11204. else
  11205. {
  11206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11207. }
  11208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11209. // ResetRetries
  11210. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11214. // ConnectorPhaseRotation
  11215. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11219. // ConnectorPhaseRotationMaxLength
  11220. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11224. // StopTransactionOnEVSideDisconnect
  11225. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11229. // StopTransactionOnInvalidId
  11230. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11234. // StopTxnAlignedData
  11235. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11239. // StopTxnAlignedDataMaxLength
  11240. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11244. // StopTxnSampledData
  11245. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11247. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11249. else
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11252. // StopTxnSampledDataMaxLength
  11253. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11255. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11256. {
  11257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11258. }
  11259. else
  11260. {
  11261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11262. }
  11263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11264. // SupportedFeatureProfiles
  11265. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11269. // SupportedFeatureProfilesMaxLength
  11270. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11274. // TransactionMessageAttempts
  11275. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11278. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11280. // TransactionMessageRetryInterval
  11281. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11284. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11286. // UnlockConnectorOnEVSideDisconnect
  11287. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11291. // WebSocketPingInterval
  11292. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11296. // QueueOffLineStartTransactionMessage
  11297. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11301. // AuthorizationKey
  11302. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  11305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11306. // SecurityProfile
  11307. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  11310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11311. // DefaultPrice
  11312. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11316. // CustomDisplayCostAndPrice
  11317. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11321. // CustomIdleFeeAfterStop
  11322. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11326. // Configuration Version
  11327. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11331. //* Local Auth List Management Profile*/
  11332. #if 0
  11333. //For OCTT Test Case
  11334. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11337. #endif
  11338. #if 1
  11339. //LocalAuthListEnabled
  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. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11344. #endif
  11345. //LocalAuthListMaxLength
  11346. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11350. //SendLocalListMaxLength
  11351. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11355. //ReserveConnectorZeroSupported
  11356. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11360. //* Smart Charging Profile */
  11361. //ChargeProfileMaxStackLevel
  11362. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11366. // ChargingScheduleAllowedChargingRateUnit
  11367. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11371. // ChargingScheduleMaxPeriods
  11372. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11376. // ConnectorSwitch3to1PhaseSupported
  11377. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11381. // MaxChargingProfilesInstalled
  11382. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11386. fclose(outfile);
  11387. }
  11388. else
  11389. {
  11390. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11391. char keystr[60]={0};
  11392. char readonlystr[10]={0};
  11393. char valuestr[256]={0};
  11394. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11395. if(fp == NULL) {
  11396. DEBUG_INFO("Error opening file");
  11397. return FALSE;
  11398. }
  11399. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11400. {
  11401. //DEBUG_INFO("Get Configuration \n");
  11402. if(strlen(str) > 0)
  11403. {
  11404. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11405. //*************************key*********************************/
  11406. if(strstr(str, "key") != NULL)
  11407. {
  11408. loc = strstr(str, "key");
  11409. c = 0;
  11410. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11411. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11412. {
  11413. sstr[c] = loc[strlen("key")+3+c];
  11414. c++;
  11415. }
  11416. sstr[c] = '\0';
  11417. strcpy(keystr,sstr);
  11418. }
  11419. //*************************readonly*********************************/
  11420. if(strstr(str, "readonly") != NULL)
  11421. {
  11422. loc = strstr(str, "readonly");
  11423. c = 0;
  11424. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11425. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11426. {
  11427. sstr[c] = loc[strlen("readonly")+2+c];
  11428. c++;
  11429. }
  11430. sstr[c] = '\0';
  11431. strcpy(readonlystr,sstr);
  11432. }
  11433. //*************************value*********************************/
  11434. if(strstr(str, "value") != NULL)
  11435. {
  11436. loc = strstr(str, "value");
  11437. c = 0;
  11438. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11439. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11440. {
  11441. sstr[c] = loc[strlen("value")+3+c];
  11442. c++;
  11443. }
  11444. sstr[c] = '\0';
  11445. strcpy(valuestr,sstr);
  11446. }
  11447. // DEBUG_INFO("keystr=%s\n",keystr);
  11448. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11449. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11450. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11451. {
  11452. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11453. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11455. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11456. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11457. }
  11458. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11459. {
  11460. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11461. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11463. }
  11464. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11465. {
  11466. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11468. }
  11469. if(strcmp(keystr, "BlinkRepeat") == 0)
  11470. {
  11471. //Charger.BlinkRepeat = Integer.parseInt(value);
  11472. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11474. }
  11475. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11476. {
  11477. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11479. }
  11480. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11481. {
  11482. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11484. }
  11485. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11486. {
  11487. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11489. }
  11490. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11491. {
  11492. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11494. HeartBeatWaitTime = atoi(valuestr);
  11495. }
  11496. if(strcmp(keystr, "LightIntensity") == 0)
  11497. {
  11498. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11500. }
  11501. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11502. {
  11503. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11505. }
  11506. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11507. {
  11508. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11510. }
  11511. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11512. {
  11513. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11515. }
  11516. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11517. {
  11518. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11520. }
  11521. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11522. {
  11523. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11525. }
  11526. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11527. {
  11528. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11530. }
  11531. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11532. {
  11533. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11535. }
  11536. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11537. {
  11538. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11540. }
  11541. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11542. {
  11543. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11545. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11546. }
  11547. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11548. {
  11549. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11551. }
  11552. if(strcmp(keystr, "ResetRetries") == 0)
  11553. {
  11554. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11556. }
  11557. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11558. {
  11559. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11561. }
  11562. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11563. {
  11564. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11566. }
  11567. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11568. {
  11569. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11571. }
  11572. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11573. {
  11574. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11576. }
  11577. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11578. {
  11579. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11581. }
  11582. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11583. {
  11584. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11586. }
  11587. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11588. {
  11589. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11591. }
  11592. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11593. {
  11594. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11596. }
  11597. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11598. {
  11599. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11601. }
  11602. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11603. {
  11604. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11606. }
  11607. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11608. {
  11609. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11611. TransactionMessageAttemptsValue = atoi(valuestr);
  11612. }
  11613. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11614. {
  11615. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11617. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11618. }
  11619. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11620. {
  11621. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11623. }
  11624. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11625. {
  11626. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11628. }
  11629. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11630. {
  11631. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11633. }
  11634. if(strcmp(keystr, "AuthorizationKey") == 0)
  11635. {
  11636. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11637. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11638. }
  11639. if(strcmp(keystr, "SecurityProfile") == 0)
  11640. {
  11641. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11643. }
  11644. if(strcmp(keystr, "DefaultPrice") == 0)
  11645. {
  11646. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11648. }
  11649. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11650. {
  11651. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11653. }
  11654. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11655. {
  11656. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11658. }
  11659. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11660. {
  11661. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11663. }
  11664. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11665. {
  11666. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11668. }
  11669. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11670. {
  11671. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11673. }
  11674. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11675. {
  11676. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11678. }
  11679. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11680. {
  11681. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11683. }
  11684. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11685. {
  11686. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11688. }
  11689. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11690. {
  11691. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11693. }
  11694. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11695. {
  11696. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11698. }
  11699. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11700. {
  11701. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11703. }
  11704. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11705. {
  11706. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11708. }
  11709. }
  11710. }
  11711. fclose(fp);
  11712. }
  11713. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11714. {
  11715. return PASS;
  11716. }
  11717. else
  11718. {
  11719. return FAIL;
  11720. }
  11721. }
  11722. void StoreConfigurationTable(void)
  11723. {
  11724. FILE *outfile;
  11725. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11726. if(outfile == NULL)
  11727. {
  11728. DEBUG_INFO("Error opening file");
  11729. return ;
  11730. }
  11731. /*Core Profile*/
  11732. //AllowOfflineTxForUnknownId
  11733. /*
  11734. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11735. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11738. */
  11739. //DEBUG_INFO("data=%s\n",data);
  11740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11741. //AuthorizationCacheEnabled
  11742. /*
  11743. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11746. */
  11747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11748. //AuthorizeRemoteTxRequests
  11749. /*
  11750. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11753. */
  11754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11755. //BlinkRepeat
  11756. /*
  11757. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11760. */
  11761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11762. //ClockAlignedDataInterval
  11763. /*
  11764. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11767. */
  11768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11769. //ConnectionTimeOut
  11770. /*
  11771. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11774. */
  11775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11776. //GetConfigurationMaxKeys
  11777. /*
  11778. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11781. */
  11782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11783. // HeartbeatInterval
  11784. /*
  11785. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11788. */
  11789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11790. // LightIntensity
  11791. /*
  11792. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11795. */
  11796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11797. // LocalAuthorizeOffline
  11798. /*
  11799. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11802. */
  11803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11804. // LocalPreAuthorize
  11805. /*
  11806. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11809. */
  11810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11811. // MaxEnergyOnInvalidId
  11812. /*
  11813. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11816. */
  11817. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11819. // MeterValuesAlignedData
  11820. /*
  11821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11824. */
  11825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11826. // MeterValuesAlignedDataMaxLength
  11827. /*
  11828. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11831. */
  11832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11833. // MeterValuesSampledData
  11834. /*
  11835. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11838. */
  11839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11840. // MeterValuesSampledDataMaxLength
  11841. /*
  11842. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11845. */
  11846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11847. // MeterValueSampleInterval
  11848. /*
  11849. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11852. */
  11853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11854. // MinimumStatusDuration
  11855. /*
  11856. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11859. */
  11860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11861. // NumberOfConnectors
  11862. /*
  11863. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11866. {
  11867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11868. }
  11869. else
  11870. {
  11871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11872. }
  11873. */
  11874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11875. // ResetRetries
  11876. /*
  11877. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11880. */
  11881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11882. // ConnectorPhaseRotation
  11883. /*
  11884. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11887. */
  11888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11889. // ConnectorPhaseRotationMaxLength
  11890. /*
  11891. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11894. */
  11895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11896. // StopTransactionOnEVSideDisconnect
  11897. /*
  11898. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11901. */
  11902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11903. // StopTransactionOnInvalidId
  11904. /*
  11905. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11908. */
  11909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11910. // StopTxnAlignedData
  11911. /*
  11912. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11915. */
  11916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11917. // StopTxnAlignedDataMaxLength
  11918. /*
  11919. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11922. */
  11923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11924. // StopTxnSampledData
  11925. /*
  11926. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11929. */
  11930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11931. // StopTxnSampledDataMaxLength
  11932. /*
  11933. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11936. */
  11937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11938. // SupportedFeatureProfiles
  11939. /*
  11940. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11943. */
  11944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11945. // SupportedFeatureProfilesMaxLength
  11946. /*
  11947. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11950. */
  11951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11952. // TransactionMessageAttempts
  11953. /*
  11954. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11957. */
  11958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11959. // TransactionMessageRetryInterval
  11960. /*
  11961. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11964. */
  11965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11966. // UnlockConnectorOnEVSideDisconnect
  11967. /*
  11968. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11971. */
  11972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11973. // WebSocketPingInterval
  11974. /*
  11975. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11978. */
  11979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11980. // QueueOffLineStartTransactionMessage
  11981. /*
  11982. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11985. */
  11986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11987. // AuthorizationKey
  11988. /*
  11989. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  11992. */
  11993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11994. // SecurityProfile
  11995. /*
  11996. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  11999. */
  12000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12001. // DefaultPrice
  12002. /*
  12003. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12006. */
  12007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12008. // CustomDisplayCostAndPrice
  12009. /*
  12010. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12013. */
  12014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12015. // CustomIdleFeeAfterStop
  12016. /*
  12017. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12020. */
  12021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12022. // ConfigurationVersion
  12023. /*
  12024. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12027. */
  12028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12029. //* Local Auth List Management Profile*/
  12030. //LocalAuthListEnabled
  12031. /*
  12032. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12035. */
  12036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12037. //LocalAuthListMaxLength
  12038. /*
  12039. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12042. */
  12043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12044. //SendLocalListMaxLength
  12045. /*
  12046. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12049. */
  12050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12051. //ReserveConnectorZeroSupported
  12052. /*
  12053. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12056. */
  12057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12058. //* Smart Charging Profile */
  12059. //ChargeProfileMaxStackLevel
  12060. /*
  12061. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12064. */
  12065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12066. // ChargingScheduleAllowedChargingRateUnit
  12067. /*
  12068. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12071. */
  12072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12073. // ChargingScheduleMaxPeriods
  12074. /*
  12075. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12078. */
  12079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12080. // ConnectorSwitch3to1PhaseSupported
  12081. /*
  12082. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12085. */
  12086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12087. // MaxChargingProfilesInstalled
  12088. /*
  12089. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12092. */
  12093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12094. fclose(outfile);
  12095. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12096. }
  12097. void getKeyValue(char *keyReq)
  12098. {
  12099. int isEmpty = FALSE;
  12100. int isKnowKey = FALSE;
  12101. DEBUG_INFO("keyReq = %s\n", keyReq);
  12102. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12103. isEmpty = TRUE;
  12104. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12105. {
  12106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12109. {
  12110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12111. }
  12112. else
  12113. {
  12114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12115. }
  12116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12117. isKnowKey = TRUE;
  12118. }
  12119. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12120. {
  12121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12124. {
  12125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12126. }
  12127. else
  12128. {
  12129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12130. }
  12131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12132. isKnowKey = TRUE;
  12133. }
  12134. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12135. {
  12136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12139. {
  12140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12141. }
  12142. else
  12143. {
  12144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12145. }
  12146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12147. isKnowKey = TRUE;
  12148. }
  12149. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12150. {
  12151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12154. {
  12155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12156. }
  12157. else
  12158. {
  12159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12160. }
  12161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12162. isKnowKey = TRUE;
  12163. }
  12164. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12165. {
  12166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12169. {
  12170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12171. }
  12172. else
  12173. {
  12174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12175. }
  12176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12177. isKnowKey = TRUE;
  12178. }
  12179. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12180. {
  12181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12184. {
  12185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12186. }
  12187. else
  12188. {
  12189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12190. }
  12191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12192. isKnowKey = TRUE;
  12193. }
  12194. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12195. {
  12196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12199. {
  12200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12201. }
  12202. else
  12203. {
  12204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12205. }
  12206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12207. isKnowKey = TRUE;
  12208. }
  12209. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12210. {
  12211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12214. {
  12215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12216. }
  12217. else
  12218. {
  12219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12220. }
  12221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12222. isKnowKey = TRUE;
  12223. }
  12224. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12225. {
  12226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12229. {
  12230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12231. }
  12232. else
  12233. {
  12234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12235. }
  12236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12237. isKnowKey = TRUE;
  12238. }
  12239. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12240. {
  12241. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12244. {
  12245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12246. }
  12247. else
  12248. {
  12249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12250. }
  12251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12252. isKnowKey = TRUE;
  12253. }
  12254. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12255. {
  12256. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12259. {
  12260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12261. }
  12262. else
  12263. {
  12264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12265. }
  12266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12267. isKnowKey = TRUE;
  12268. }
  12269. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12270. {
  12271. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12274. {
  12275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12276. }
  12277. else
  12278. {
  12279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12280. }
  12281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12282. isKnowKey = TRUE;
  12283. }
  12284. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12285. {
  12286. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12289. {
  12290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12291. }
  12292. else
  12293. {
  12294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12295. }
  12296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12297. isKnowKey = TRUE;
  12298. }
  12299. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12300. {
  12301. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12304. {
  12305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12306. }
  12307. else
  12308. {
  12309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12310. }
  12311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12312. isKnowKey = TRUE;
  12313. }
  12314. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12315. {
  12316. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12319. {
  12320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12321. }
  12322. else
  12323. {
  12324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12325. }
  12326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12327. isKnowKey = TRUE;
  12328. }
  12329. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12330. {
  12331. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12334. {
  12335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12336. }
  12337. else
  12338. {
  12339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12340. }
  12341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12342. isKnowKey = TRUE;
  12343. }
  12344. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12345. {
  12346. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12349. {
  12350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12351. }
  12352. else
  12353. {
  12354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12355. }
  12356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12357. isKnowKey = TRUE;
  12358. }
  12359. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12360. {
  12361. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12364. {
  12365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12366. }
  12367. else
  12368. {
  12369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12370. }
  12371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12372. isKnowKey = TRUE;
  12373. }
  12374. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12375. {
  12376. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12379. {
  12380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12381. }
  12382. else
  12383. {
  12384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12385. }
  12386. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12388. isKnowKey = TRUE;
  12389. }
  12390. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12391. {
  12392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12395. {
  12396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12397. }
  12398. else
  12399. {
  12400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12401. }
  12402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12403. isKnowKey = TRUE;
  12404. }
  12405. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12406. {
  12407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12410. {
  12411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12412. }
  12413. else
  12414. {
  12415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12416. }
  12417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12418. isKnowKey = TRUE;
  12419. }
  12420. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12421. {
  12422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12425. {
  12426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12427. }
  12428. else
  12429. {
  12430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12431. }
  12432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12433. isKnowKey = TRUE;
  12434. }
  12435. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12436. {
  12437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12440. {
  12441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12442. }
  12443. else
  12444. {
  12445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12446. }
  12447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12448. isKnowKey = TRUE;
  12449. }
  12450. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12451. {
  12452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12455. {
  12456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12457. }
  12458. else
  12459. {
  12460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12461. }
  12462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12463. isKnowKey = TRUE;
  12464. }
  12465. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12466. {
  12467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12470. {
  12471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12472. }
  12473. else
  12474. {
  12475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12476. }
  12477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12478. isKnowKey = TRUE;
  12479. }
  12480. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12481. {
  12482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12485. {
  12486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12487. }
  12488. else
  12489. {
  12490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12491. }
  12492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12493. isKnowKey = TRUE;
  12494. }
  12495. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12496. {
  12497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12500. {
  12501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12502. }
  12503. else
  12504. {
  12505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12506. }
  12507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12508. isKnowKey = TRUE;
  12509. }
  12510. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12511. {
  12512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12515. {
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12517. }
  12518. else
  12519. {
  12520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12521. }
  12522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12523. isKnowKey = TRUE;
  12524. }
  12525. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12526. {
  12527. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12530. {
  12531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12532. }
  12533. else
  12534. {
  12535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12536. }
  12537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12538. isKnowKey = TRUE;
  12539. }
  12540. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12541. {
  12542. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12545. {
  12546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12547. }
  12548. else
  12549. {
  12550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12551. }
  12552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12553. isKnowKey = TRUE;
  12554. }
  12555. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12556. {
  12557. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12560. {
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12562. }
  12563. else
  12564. {
  12565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12566. }
  12567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12568. isKnowKey = TRUE;
  12569. }
  12570. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12571. {
  12572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12575. {
  12576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12577. }
  12578. else
  12579. {
  12580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12581. }
  12582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12583. isKnowKey = TRUE;
  12584. }
  12585. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12586. {
  12587. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12590. {
  12591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12592. }
  12593. else
  12594. {
  12595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12596. }
  12597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12598. isKnowKey = TRUE;
  12599. }
  12600. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12601. {
  12602. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12605. {
  12606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12607. }
  12608. else
  12609. {
  12610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12611. }
  12612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12613. isKnowKey = TRUE;
  12614. }
  12615. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12616. {
  12617. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12620. {
  12621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12622. }
  12623. else
  12624. {
  12625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12626. }
  12627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12628. isKnowKey = TRUE;
  12629. }
  12630. /*
  12631. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12632. {
  12633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12636. {
  12637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12638. }
  12639. else
  12640. {
  12641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12642. }
  12643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12644. isKnowKey = TRUE;
  12645. }*/
  12646. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12647. {
  12648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12651. {
  12652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12653. }
  12654. else
  12655. {
  12656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12657. }
  12658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12659. isKnowKey = TRUE;
  12660. }
  12661. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12662. {
  12663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12666. {
  12667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12668. }
  12669. else
  12670. {
  12671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12672. }
  12673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12674. isKnowKey = TRUE;
  12675. }
  12676. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12677. {
  12678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12681. {
  12682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12683. }
  12684. else
  12685. {
  12686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12687. }
  12688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12689. isKnowKey = TRUE;
  12690. }
  12691. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12692. {
  12693. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12696. {
  12697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12698. }
  12699. else
  12700. {
  12701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12702. }
  12703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12704. isKnowKey = TRUE;
  12705. }
  12706. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12707. {
  12708. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12710. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12711. {
  12712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12713. }
  12714. else
  12715. {
  12716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12717. }
  12718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12719. isKnowKey = TRUE;
  12720. }
  12721. #if 1
  12722. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12723. {
  12724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12726. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12727. {
  12728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12729. }
  12730. else
  12731. {
  12732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12733. }
  12734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12735. isKnowKey = TRUE;
  12736. }
  12737. #endif
  12738. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12739. {
  12740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12742. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12743. {
  12744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12745. }
  12746. else
  12747. {
  12748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12749. }
  12750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12751. isKnowKey = TRUE;
  12752. }
  12753. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12754. {
  12755. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12757. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12758. {
  12759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12760. }
  12761. else
  12762. {
  12763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12764. }
  12765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12766. isKnowKey = TRUE;
  12767. }
  12768. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12769. {
  12770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12772. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12773. {
  12774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12775. }
  12776. else
  12777. {
  12778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12779. }
  12780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12781. isKnowKey = TRUE;
  12782. }
  12783. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12784. {
  12785. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12787. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12788. {
  12789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12790. }
  12791. else
  12792. {
  12793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12794. }
  12795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12796. isKnowKey = TRUE;
  12797. }
  12798. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12799. {
  12800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12802. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12803. {
  12804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12805. }
  12806. else
  12807. {
  12808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12809. }
  12810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12811. isKnowKey = TRUE;
  12812. }
  12813. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12814. {
  12815. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12817. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12818. {
  12819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12820. }
  12821. else
  12822. {
  12823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12824. }
  12825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12826. isKnowKey = TRUE;
  12827. }
  12828. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12829. {
  12830. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12832. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12833. {
  12834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12835. }
  12836. else
  12837. {
  12838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12839. }
  12840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12841. isKnowKey = TRUE;
  12842. }
  12843. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12844. {
  12845. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12847. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12848. {
  12849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12850. }
  12851. else
  12852. {
  12853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12854. }
  12855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12856. isKnowKey = TRUE;
  12857. }
  12858. //=========================================================
  12859. if(!isEmpty && !isKnowKey)
  12860. {
  12861. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12862. strcpy(unknownkey[UnknownKeynum], keyReq);
  12863. UnknownKeynum = UnknownKeynum + 1;
  12864. }
  12865. }
  12866. void processUnkownKey(void)
  12867. {
  12868. DEBUG_INFO("processUnkownKey...\n");
  12869. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12870. for(int index=0; index < UnknownKeynum; index++)
  12871. {
  12872. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12873. {
  12874. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12875. }
  12876. }
  12877. }
  12878. int setKeyValue(char *key, char *value)
  12879. {
  12880. int isSuccess = NotSupported;
  12881. int check_ascii=0;
  12882. char str[256]={0};
  12883. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12884. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12885. {
  12886. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12888. {
  12889. strcpy(str, (const char*)value);
  12890. for(int i = 0; str[i]; i++){
  12891. str[i] = tolower(str[i]);
  12892. }
  12893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12894. isSuccess = ConfigurationStatus_Accepted;
  12895. }
  12896. else
  12897. {
  12898. isSuccess = ConfigurationStatus_Rejected;
  12899. }
  12900. }
  12901. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12902. {
  12903. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12905. {
  12906. strcpy(str, (const char*)value);
  12907. for(int i = 0; str[i]; i++){
  12908. str[i] = tolower(str[i]);
  12909. }
  12910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12911. isSuccess = ConfigurationStatus_Accepted;
  12912. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12913. }
  12914. else
  12915. {
  12916. isSuccess = ConfigurationStatus_Rejected;
  12917. }
  12918. }
  12919. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12920. {
  12921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12922. {
  12923. strcpy(str, (const char*)value);
  12924. for(int i = 0; str[i]; i++)
  12925. {
  12926. str[i] = tolower(str[i]);
  12927. }
  12928. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12930. isSuccess = ConfigurationStatus_Accepted;
  12931. }
  12932. else
  12933. {
  12934. isSuccess = ConfigurationStatus_Rejected;
  12935. }
  12936. }
  12937. if(strcmp(key, "BlinkRepeat") == 0)
  12938. {
  12939. //Charger.BlinkRepeat = Integer.parseInt(value);
  12940. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12941. {
  12942. check_ascii = value[0];
  12943. if( (check_ascii < 48) || (check_ascii > 57) )
  12944. {
  12945. isSuccess = ConfigurationStatus_Rejected;
  12946. }
  12947. else
  12948. {
  12949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12950. isSuccess = ConfigurationStatus_Accepted;
  12951. }
  12952. }
  12953. else
  12954. {
  12955. isSuccess = ConfigurationStatus_Rejected;
  12956. }
  12957. }
  12958. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12959. {
  12960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12961. {
  12962. check_ascii = value[0];
  12963. if( (check_ascii < 48) || (check_ascii > 57) )
  12964. {
  12965. isSuccess = ConfigurationStatus_Rejected;
  12966. }
  12967. else
  12968. {
  12969. if((atoi(value) == 0) || (atoi(value) >= 10))
  12970. {
  12971. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12973. isSuccess = ConfigurationStatus_Accepted;
  12974. }
  12975. else
  12976. isSuccess = ConfigurationStatus_Rejected;
  12977. }
  12978. }
  12979. else
  12980. {
  12981. isSuccess = ConfigurationStatus_Rejected;
  12982. }
  12983. }
  12984. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12985. {
  12986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12987. {
  12988. check_ascii = value[0];
  12989. if( (check_ascii < 48) || (check_ascii > 57) )
  12990. {
  12991. isSuccess = ConfigurationStatus_Rejected;
  12992. }
  12993. else
  12994. {
  12995. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12997. isSuccess = ConfigurationStatus_Accepted;
  12998. }
  12999. }
  13000. else
  13001. {
  13002. isSuccess = ConfigurationStatus_Rejected;
  13003. }
  13004. }
  13005. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13006. {
  13007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13008. {
  13009. check_ascii = value[0];
  13010. if( (check_ascii < 48) || (check_ascii > 57) )
  13011. {
  13012. isSuccess = ConfigurationStatus_Rejected;
  13013. }
  13014. else
  13015. {
  13016. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13018. isSuccess = ConfigurationStatus_Accepted;
  13019. }
  13020. }
  13021. else
  13022. {
  13023. isSuccess = ConfigurationStatus_Rejected;
  13024. }
  13025. }
  13026. if(strcmp(key, "HeartbeatInterval") == 0)
  13027. {
  13028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13029. {
  13030. check_ascii = value[0];
  13031. if( (check_ascii < 48) || (check_ascii > 57) )
  13032. {
  13033. isSuccess = ConfigurationStatus_Rejected;
  13034. }
  13035. else
  13036. {
  13037. if((atoi(value) == 0) || (atoi(value) >= 10))
  13038. {
  13039. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13041. HeartBeatWaitTime = atoi(value);
  13042. isSuccess = ConfigurationStatus_Accepted;
  13043. }
  13044. else
  13045. {
  13046. isSuccess = ConfigurationStatus_Rejected;
  13047. }
  13048. }
  13049. }
  13050. else
  13051. {
  13052. isSuccess = ConfigurationStatus_Rejected;
  13053. }
  13054. }
  13055. if(strcmp(key, "LightIntensity") == 0)
  13056. {
  13057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13058. {
  13059. check_ascii = value[0];
  13060. if( (check_ascii < 48) || (check_ascii > 57) )
  13061. {
  13062. isSuccess = ConfigurationStatus_Rejected;
  13063. }
  13064. else
  13065. {
  13066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13067. isSuccess = ConfigurationStatus_Accepted;
  13068. }
  13069. }
  13070. else
  13071. {
  13072. isSuccess = ConfigurationStatus_Rejected;
  13073. }
  13074. }
  13075. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13076. {
  13077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13078. {
  13079. strcpy(str, (const char*)value);
  13080. for(int i = 0; str[i]; i++)
  13081. {
  13082. str[i] = tolower(str[i]);
  13083. }
  13084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13085. isSuccess = ConfigurationStatus_Accepted;
  13086. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13087. }
  13088. else
  13089. {
  13090. isSuccess = ConfigurationStatus_Rejected;
  13091. }
  13092. }
  13093. if(strcmp(key, "LocalPreAuthorize") == 0)
  13094. {
  13095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13096. {
  13097. strcpy(str, (const char*)value);
  13098. for(int i = 0; str[i]; i++)
  13099. {
  13100. str[i] = tolower(str[i]);
  13101. }
  13102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13103. isSuccess = ConfigurationStatus_Accepted;
  13104. }
  13105. else
  13106. {
  13107. isSuccess = ConfigurationStatus_Rejected;
  13108. }
  13109. }
  13110. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13111. {
  13112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13113. {
  13114. check_ascii = value[0];
  13115. if( (check_ascii < 48) || (check_ascii > 57) )
  13116. {
  13117. isSuccess = ConfigurationStatus_Rejected;
  13118. }
  13119. else
  13120. {
  13121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13122. isSuccess = ConfigurationStatus_Accepted;
  13123. }
  13124. }
  13125. else
  13126. {
  13127. isSuccess = ConfigurationStatus_Rejected;
  13128. }
  13129. }
  13130. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13131. {
  13132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13133. {
  13134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13135. isSuccess = ConfigurationStatus_Accepted;
  13136. }
  13137. else
  13138. {
  13139. isSuccess = ConfigurationStatus_Rejected;
  13140. }
  13141. }
  13142. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13143. {
  13144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13145. {
  13146. check_ascii = value[0];
  13147. if( (check_ascii < 48) || (check_ascii > 57) )
  13148. {
  13149. isSuccess = ConfigurationStatus_Rejected;
  13150. }
  13151. else
  13152. {
  13153. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13155. isSuccess = ConfigurationStatus_Accepted;
  13156. }
  13157. }
  13158. else
  13159. {
  13160. isSuccess = ConfigurationStatus_Rejected;
  13161. }
  13162. }
  13163. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13164. {
  13165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13166. {
  13167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13168. isSuccess = ConfigurationStatus_Accepted;
  13169. }
  13170. else
  13171. {
  13172. isSuccess = ConfigurationStatus_Rejected;
  13173. }
  13174. }
  13175. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13176. {
  13177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13178. {
  13179. check_ascii = value[0];
  13180. if( (check_ascii < 48) || (check_ascii > 57) )
  13181. {
  13182. isSuccess = ConfigurationStatus_Rejected;
  13183. }
  13184. else
  13185. {
  13186. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13188. isSuccess = ConfigurationStatus_Accepted;
  13189. }
  13190. }
  13191. else
  13192. {
  13193. isSuccess = ConfigurationStatus_Rejected;
  13194. }
  13195. }
  13196. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13197. {
  13198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13199. {
  13200. check_ascii = value[0];
  13201. if( (check_ascii < 48) || (check_ascii > 57) )
  13202. {
  13203. isSuccess = ConfigurationStatus_Rejected;
  13204. }
  13205. else
  13206. {
  13207. if((atoi(value) == 0) || (atoi(value) >= 10))
  13208. {
  13209. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13211. isSuccess = ConfigurationStatus_Accepted;
  13212. }
  13213. else
  13214. {
  13215. isSuccess = ConfigurationStatus_Rejected;
  13216. }
  13217. }
  13218. }
  13219. else
  13220. {
  13221. isSuccess = ConfigurationStatus_Rejected;
  13222. }
  13223. }
  13224. if(strcmp(key, "MinimumStatusDuration") == 0)
  13225. {
  13226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13227. {
  13228. check_ascii = value[0];
  13229. if( (check_ascii < 48) || (check_ascii > 57) )
  13230. {
  13231. isSuccess = ConfigurationStatus_Rejected;
  13232. }
  13233. else
  13234. {
  13235. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13236. {
  13237. isSuccess = ConfigurationStatus_Rejected;
  13238. }
  13239. else
  13240. {
  13241. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13243. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13244. isSuccess = ConfigurationStatus_Accepted;
  13245. }
  13246. }
  13247. }
  13248. else
  13249. {
  13250. isSuccess = ConfigurationStatus_Rejected;
  13251. }
  13252. }
  13253. if(strcmp(key, "NumberOfConnectors") == 0)
  13254. {
  13255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13256. {
  13257. check_ascii = value[0];
  13258. if( (check_ascii < 48) || (check_ascii > 57) )
  13259. {
  13260. isSuccess = ConfigurationStatus_Rejected;
  13261. }
  13262. else
  13263. {
  13264. //Charger.ResetRetries = Integer.parseInt(value);
  13265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13266. isSuccess = ConfigurationStatus_Accepted;
  13267. }
  13268. }
  13269. else
  13270. {
  13271. isSuccess = ConfigurationStatus_Rejected;
  13272. }
  13273. }
  13274. if(strcmp(key, "ResetRetries") == 0)
  13275. {
  13276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13277. {
  13278. check_ascii = value[0];
  13279. if( (check_ascii < 48) || (check_ascii > 57) )
  13280. {
  13281. isSuccess = ConfigurationStatus_Rejected;
  13282. }
  13283. else
  13284. {
  13285. //Charger.ResetRetries = Integer.parseInt(value);
  13286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13287. isSuccess = ConfigurationStatus_Accepted;
  13288. }
  13289. }
  13290. else
  13291. {
  13292. isSuccess = ConfigurationStatus_Rejected;
  13293. }
  13294. }
  13295. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13296. {
  13297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13298. {
  13299. strcpy(str, (const char*)value);
  13300. for(int i = 0; str[i]; i++)
  13301. {
  13302. str[i] = tolower(str[i]);
  13303. }
  13304. if(strcmp(str, "notapplicable")== 0)
  13305. {
  13306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13307. isSuccess = ConfigurationStatus_Accepted;
  13308. }
  13309. else if(strcmp(str, "unknown")== 0)
  13310. {
  13311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13312. isSuccess = ConfigurationStatus_Accepted;
  13313. }
  13314. else if(strcmp(str, "rst")== 0)
  13315. {
  13316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13317. isSuccess = ConfigurationStatus_Accepted;
  13318. }
  13319. else if(strcmp(str, "rts")== 0)
  13320. {
  13321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13322. isSuccess = ConfigurationStatus_Accepted;
  13323. }
  13324. else if(strcmp(str, "srt")== 0)
  13325. {
  13326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13327. isSuccess = ConfigurationStatus_Accepted;
  13328. }
  13329. else if(strcmp(str, "str")== 0)
  13330. {
  13331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13332. isSuccess = ConfigurationStatus_Accepted;
  13333. }
  13334. else if(strcmp(str, "trs")== 0)
  13335. {
  13336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13337. isSuccess = ConfigurationStatus_Accepted;
  13338. }
  13339. else if(strcmp(str, "tsr")== 0)
  13340. {
  13341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13342. isSuccess = ConfigurationStatus_Accepted;
  13343. }
  13344. else
  13345. {
  13346. isSuccess = ConfigurationStatus_Rejected;
  13347. }
  13348. }
  13349. else
  13350. {
  13351. isSuccess = ConfigurationStatus_Rejected;
  13352. }
  13353. }
  13354. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13355. {
  13356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13357. {
  13358. check_ascii = value[0];
  13359. if( (check_ascii < 48) || (check_ascii > 57) )
  13360. {
  13361. isSuccess = ConfigurationStatus_Rejected;
  13362. }
  13363. else
  13364. {
  13365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13366. isSuccess = ConfigurationStatus_Accepted;
  13367. }
  13368. }
  13369. else
  13370. {
  13371. isSuccess = ConfigurationStatus_Rejected;
  13372. }
  13373. }
  13374. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13375. {
  13376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13377. {
  13378. strcpy(str, (const char*)value);
  13379. for(int i = 0; str[i]; i++)
  13380. {
  13381. str[i] = tolower(str[i]);
  13382. }
  13383. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13385. isSuccess = ConfigurationStatus_Accepted;
  13386. }
  13387. else
  13388. {
  13389. isSuccess = ConfigurationStatus_Rejected;
  13390. }
  13391. }
  13392. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13393. {
  13394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13395. {
  13396. strcpy(str, (const char*)value);
  13397. for(int i = 0; str[i]; i++)
  13398. {
  13399. str[i] = tolower(str[i]);
  13400. }
  13401. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13403. isSuccess = ConfigurationStatus_Accepted;
  13404. }
  13405. else
  13406. {
  13407. isSuccess = ConfigurationStatus_Rejected;
  13408. }
  13409. }
  13410. if(strcmp(key, "StopTxnAlignedData") == 0)
  13411. {
  13412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13413. {
  13414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13415. isSuccess = ConfigurationStatus_Accepted;
  13416. }
  13417. else
  13418. {
  13419. isSuccess = ConfigurationStatus_Rejected;
  13420. }
  13421. }
  13422. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13423. {
  13424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13425. {
  13426. check_ascii = value[0];
  13427. if( (check_ascii < 48) || (check_ascii > 57) )
  13428. {
  13429. isSuccess = ConfigurationStatus_Rejected;
  13430. }
  13431. else
  13432. {
  13433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13434. isSuccess = ConfigurationStatus_Accepted;
  13435. }
  13436. }
  13437. else
  13438. {
  13439. isSuccess = ConfigurationStatus_Rejected;
  13440. }
  13441. }
  13442. if(strcmp(key, "StopTxnSampledData") == 0)
  13443. {
  13444. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13445. {
  13446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13447. isSuccess = ConfigurationStatus_Accepted;
  13448. }
  13449. else
  13450. {
  13451. isSuccess = ConfigurationStatus_Rejected;
  13452. }
  13453. }
  13454. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13455. {
  13456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13457. {
  13458. check_ascii = value[0];
  13459. if( (check_ascii < 48) || (check_ascii > 57) )
  13460. {
  13461. isSuccess = ConfigurationStatus_Rejected;
  13462. }
  13463. else
  13464. {
  13465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13466. isSuccess = ConfigurationStatus_Accepted;
  13467. }
  13468. }
  13469. else
  13470. {
  13471. isSuccess = ConfigurationStatus_Rejected;
  13472. }
  13473. }
  13474. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13475. {
  13476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13477. {
  13478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13479. isSuccess = ConfigurationStatus_Accepted;
  13480. }
  13481. else
  13482. {
  13483. isSuccess = ConfigurationStatus_Rejected;
  13484. }
  13485. }
  13486. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13487. {
  13488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13489. {
  13490. check_ascii = value[0];
  13491. if( (check_ascii < 48) || (check_ascii > 57) )
  13492. {
  13493. isSuccess = ConfigurationStatus_Rejected;
  13494. }
  13495. else
  13496. {
  13497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13498. isSuccess = ConfigurationStatus_Accepted;
  13499. }
  13500. }
  13501. else
  13502. {
  13503. isSuccess = ConfigurationStatus_Rejected;
  13504. }
  13505. }
  13506. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13507. {
  13508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13509. {
  13510. check_ascii = value[0];
  13511. if( (check_ascii < 48) || (check_ascii > 57) )
  13512. {
  13513. isSuccess = ConfigurationStatus_Rejected;
  13514. }
  13515. else
  13516. {
  13517. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13519. TransactionMessageAttemptsValue = atoi(value);
  13520. isSuccess = ConfigurationStatus_Accepted;
  13521. }
  13522. }
  13523. else
  13524. {
  13525. isSuccess = ConfigurationStatus_Rejected;
  13526. }
  13527. }
  13528. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13529. {
  13530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13531. {
  13532. check_ascii = value[0];
  13533. if( (check_ascii < 48) || (check_ascii > 57) )
  13534. {
  13535. isSuccess = ConfigurationStatus_Rejected;
  13536. }
  13537. else
  13538. {
  13539. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13541. TransactionMessageRetryIntervalValue = atoi(value);
  13542. isSuccess = ConfigurationStatus_Accepted;
  13543. }
  13544. }
  13545. else
  13546. {
  13547. isSuccess = ConfigurationStatus_Rejected;
  13548. }
  13549. }
  13550. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13551. {
  13552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13553. {
  13554. strcpy(str, (const char*)value);
  13555. for(int i = 0; str[i]; i++)
  13556. {
  13557. str[i] = tolower(str[i]);
  13558. }
  13559. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13561. isSuccess = ConfigurationStatus_Accepted;
  13562. }
  13563. else
  13564. {
  13565. isSuccess = ConfigurationStatus_Rejected;
  13566. }
  13567. }
  13568. if(strcmp(key, "WebSocketPingInterval") == 0)
  13569. {
  13570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13571. {
  13572. check_ascii = value[0];
  13573. if( (check_ascii < 48) || (check_ascii > 57) )
  13574. {
  13575. isSuccess = ConfigurationStatus_Rejected;
  13576. }
  13577. else
  13578. {
  13579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13580. isSuccess = ConfigurationStatus_Accepted;
  13581. }
  13582. }
  13583. else
  13584. {
  13585. isSuccess = ConfigurationStatus_Rejected;
  13586. }
  13587. }
  13588. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13589. {
  13590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13591. {
  13592. strcpy(str, (const char*)value);
  13593. for(int i = 0; str[i]; i++)
  13594. {
  13595. str[i] = tolower(str[i]);
  13596. }
  13597. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13599. isSuccess = ConfigurationStatus_Accepted;
  13600. }
  13601. else
  13602. {
  13603. isSuccess = ConfigurationStatus_Rejected;
  13604. }
  13605. }
  13606. if(strcmp(key, "AuthorizationKey") == 0)
  13607. {
  13608. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13609. {
  13610. strcpy(str, (const char*)value);
  13611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13612. isSuccess = ConfigurationStatus_Accepted;
  13613. }
  13614. else
  13615. {
  13616. isSuccess = ConfigurationStatus_Rejected;
  13617. }
  13618. }
  13619. if(strcmp(key, "SecurityProfile") == 0)
  13620. {
  13621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13622. {
  13623. check_ascii = value[0];
  13624. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13625. {
  13626. isSuccess = ConfigurationStatus_Rejected;
  13627. }
  13628. else if(check_ascii == 0x33)
  13629. {
  13630. isSuccess = NotSupported;
  13631. }
  13632. else
  13633. {
  13634. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13635. {
  13636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13637. isSuccess = ConfigurationStatus_Accepted;
  13638. }
  13639. else
  13640. isSuccess = ConfigurationStatus_Rejected;
  13641. }
  13642. }
  13643. else
  13644. {
  13645. isSuccess = ConfigurationStatus_Rejected;
  13646. }
  13647. }
  13648. if(strcmp(key, "DefaultPrice") == 0)
  13649. {
  13650. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13651. {
  13652. strcpy(str, (const char*)value);
  13653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13654. isSuccess = ConfigurationStatus_Accepted;
  13655. }
  13656. else
  13657. {
  13658. isSuccess = ConfigurationStatus_Rejected;
  13659. }
  13660. }
  13661. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13662. {
  13663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13664. {
  13665. strcpy(str, (const char*)value);
  13666. for(int i = 0; str[i]; i++)
  13667. {
  13668. str[i] = tolower(str[i]);
  13669. }
  13670. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13672. isSuccess = ConfigurationStatus_Accepted;
  13673. }
  13674. else
  13675. {
  13676. isSuccess = ConfigurationStatus_Rejected;
  13677. }
  13678. }
  13679. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13680. {
  13681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13682. {
  13683. strcpy(str, (const char*)value);
  13684. for(int i = 0; str[i]; i++)
  13685. {
  13686. str[i] = tolower(str[i]);
  13687. }
  13688. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13690. isSuccess = ConfigurationStatus_Accepted;
  13691. }
  13692. else
  13693. {
  13694. isSuccess = ConfigurationStatus_Rejected;
  13695. }
  13696. }
  13697. #if 0
  13698. //For OCPP Test Case
  13699. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13700. {
  13701. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13702. {
  13703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13704. isSuccess = ConfigurationStatus_Accepted;
  13705. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13706. }
  13707. else
  13708. {
  13709. isSuccess = ConfigurationStatus_Rejected;
  13710. }
  13711. }
  13712. #endif
  13713. #if 1
  13714. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13715. {
  13716. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13717. {
  13718. strcpy(str, (const char*)value);
  13719. for(int i = 0; str[i]; i++)
  13720. {
  13721. str[i] = tolower(str[i]);
  13722. }
  13723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13724. isSuccess = ConfigurationStatus_Accepted;
  13725. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13726. }
  13727. else
  13728. {
  13729. isSuccess = ConfigurationStatus_Rejected;
  13730. }
  13731. }
  13732. #endif
  13733. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13734. {
  13735. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13736. {
  13737. check_ascii = value[0];
  13738. if( (check_ascii < 48) || (check_ascii > 57) )
  13739. {
  13740. isSuccess = ConfigurationStatus_Rejected;
  13741. }
  13742. else
  13743. {
  13744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13745. isSuccess = ConfigurationStatus_Accepted;
  13746. }
  13747. }
  13748. else
  13749. {
  13750. isSuccess = ConfigurationStatus_Rejected;
  13751. }
  13752. }
  13753. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13754. {
  13755. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13756. {
  13757. check_ascii = value[0];
  13758. if( (check_ascii < 48) || (check_ascii > 57) )
  13759. {
  13760. isSuccess = ConfigurationStatus_Rejected;
  13761. }
  13762. else
  13763. {
  13764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13765. isSuccess = ConfigurationStatus_Accepted;
  13766. }
  13767. }
  13768. else
  13769. {
  13770. isSuccess = ConfigurationStatus_Rejected;
  13771. }
  13772. }
  13773. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13774. {
  13775. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13776. {
  13777. strcpy(str, (const char*)value);
  13778. for(int i = 0; str[i]; i++)
  13779. {
  13780. str[i] = tolower(str[i]);
  13781. }
  13782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13783. isSuccess = ConfigurationStatus_Accepted;
  13784. }
  13785. else
  13786. {
  13787. isSuccess = ConfigurationStatus_Rejected;
  13788. }
  13789. }
  13790. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13791. {
  13792. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13793. {
  13794. check_ascii = value[0];
  13795. if( (check_ascii < 48) || (check_ascii > 57) )
  13796. {
  13797. isSuccess = ConfigurationStatus_Rejected;
  13798. }
  13799. else
  13800. {
  13801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13802. isSuccess = ConfigurationStatus_Accepted;
  13803. }
  13804. }
  13805. else
  13806. {
  13807. isSuccess = ConfigurationStatus_Rejected;
  13808. }
  13809. }
  13810. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13811. {
  13812. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13813. {
  13814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13815. isSuccess = ConfigurationStatus_Accepted;
  13816. }
  13817. else
  13818. {
  13819. isSuccess = ConfigurationStatus_Rejected;
  13820. }
  13821. }
  13822. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13823. {
  13824. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13825. {
  13826. check_ascii = value[0];
  13827. if( (check_ascii < 48) || (check_ascii > 57) )
  13828. {
  13829. isSuccess = ConfigurationStatus_Rejected;
  13830. }
  13831. else
  13832. {
  13833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13834. isSuccess = ConfigurationStatus_Accepted;
  13835. }
  13836. }
  13837. else
  13838. {
  13839. isSuccess = ConfigurationStatus_Rejected;
  13840. }
  13841. }
  13842. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13843. {
  13844. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13845. {
  13846. strcpy(str, (const char*)value);
  13847. for(int i = 0; str[i]; i++)
  13848. {
  13849. str[i] = tolower(str[i]);
  13850. }
  13851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13852. isSuccess = ConfigurationStatus_Accepted;
  13853. }
  13854. else
  13855. {
  13856. isSuccess = ConfigurationStatus_Rejected;
  13857. }
  13858. }
  13859. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13860. {
  13861. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13862. {
  13863. check_ascii = value[0];
  13864. if( (check_ascii < 48) || (check_ascii > 57) )
  13865. {
  13866. isSuccess = ConfigurationStatus_Rejected;
  13867. }
  13868. else
  13869. {
  13870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13871. isSuccess = ConfigurationStatus_Accepted;
  13872. }
  13873. }
  13874. else
  13875. {
  13876. isSuccess = ConfigurationStatus_Rejected;
  13877. }
  13878. }
  13879. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13880. return isSuccess;
  13881. }
  13882. int TransactionMessageAttemptsGet(void)
  13883. {
  13884. return TransactionMessageAttemptsValue;
  13885. }
  13886. int FirstHeartBeatResponse(void)
  13887. {
  13888. return FirstHeartBeat;
  13889. }
  13890. int TransactionMessageRetryIntervalGet(void)
  13891. {
  13892. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13893. }
  13894. int ReadHttpStatus(int sock)
  13895. {
  13896. //char c;
  13897. char buff[1024]="",*ptr=buff+1;
  13898. int bytes_received, status;
  13899. DEBUG_INFO("Begin Response ..\n");
  13900. while((bytes_received = recv(sock, ptr, 1, 0))){
  13901. if(bytes_received==-1){
  13902. perror("ReadHttpStatus");
  13903. exit(1);
  13904. }
  13905. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13906. ptr++;
  13907. }
  13908. *ptr=0;
  13909. ptr=buff+1;
  13910. sscanf(ptr,"%*s %d ", &status);
  13911. DEBUG_INFO("%s\n",ptr);
  13912. DEBUG_INFO("status=%d\n",status);
  13913. DEBUG_INFO("End Response ..\n");
  13914. return (bytes_received>0)?status:0;
  13915. }
  13916. //the only filed that it parsed is 'Content-Length'
  13917. int ParseHeader(int sock)
  13918. {
  13919. //char c;
  13920. char buff[1024]="",*ptr=buff+4;
  13921. int bytes_received;
  13922. DEBUG_INFO("Begin HEADER ..\n");
  13923. while((bytes_received = recv(sock, ptr, 1, 0))){
  13924. if(bytes_received==-1){
  13925. perror("Parse Header");
  13926. exit(1);
  13927. }
  13928. if(
  13929. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13930. (ptr[-1]=='\r') && (*ptr=='\n' )
  13931. ) break;
  13932. ptr++;
  13933. }
  13934. *ptr=0;
  13935. ptr=buff+4;
  13936. //printf("%s",ptr);
  13937. if(bytes_received){
  13938. ptr=strstr(ptr,"Content-Length:");
  13939. if(ptr){
  13940. sscanf(ptr,"%*s %d",&bytes_received);
  13941. }else
  13942. bytes_received=-1; //unknown size
  13943. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13944. }
  13945. DEBUG_INFO("End HEADER ..\n");
  13946. return bytes_received ;
  13947. }
  13948. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13949. {
  13950. int result = TRUE;
  13951. char rmFileCmd[100]={0};
  13952. char FilePath[100]={0};
  13953. char ftpbuf[200];
  13954. int systemresult;
  13955. //DEBUG_INFO("filename=%s\n",filename);
  13956. //DEBUG_INFO("url=%s\n",url);
  13957. sprintf(FilePath,"/mnt/%s",filename);
  13958. system("ping 8.8.8.8 &");
  13959. if((access(FilePath,F_OK))!=-1)
  13960. {
  13961. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13962. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13963. system(rmFileCmd);
  13964. }
  13965. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13966. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13967. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13968. systemresult = system(ftpbuf);
  13969. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13970. if(systemresult != 0)
  13971. {
  13972. DEBUG_INFO("http DownLoad error!\n");
  13973. result = FALSE;
  13974. }
  13975. system("pkill ping");
  13976. return result;
  13977. }
  13978. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13979. {
  13980. int result = TRUE;
  13981. char rmFileCmd[100]={0};
  13982. char FilePath[100]={0};
  13983. char ftpbuf[200];
  13984. int systemresult;
  13985. //char temp[100];
  13986. sprintf(FilePath,"/mnt/%s",filename);
  13987. system("ping 8.8.8.8 &");
  13988. if((access(FilePath,F_OK))!=-1)
  13989. {
  13990. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13991. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13992. system(rmFileCmd);
  13993. }
  13994. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13995. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13996. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13997. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13998. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13999. systemresult = system(ftpbuf);
  14000. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14001. if(systemresult != 0)
  14002. {
  14003. printf("wget error!\n");
  14004. result = FALSE;
  14005. }
  14006. system("pkill ping");
  14007. return result;
  14008. }
  14009. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14010. {
  14011. char rmFileCmd[100]={0};
  14012. char FilePath[100]={0};
  14013. char buf[512];
  14014. int systemresult = 0;
  14015. //DEBUG_INFO("filename=%s\n",filename);
  14016. //DEBUG_INFO("url=%s\n",url);
  14017. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14018. if((access(FilePath,F_OK))!=-1)
  14019. {
  14020. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14021. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14022. system(rmFileCmd);
  14023. }
  14024. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14025. if(fp == NULL)
  14026. {
  14027. DEBUG_INFO("log is NULL\n");
  14028. return FALSE;
  14029. }
  14030. else
  14031. {
  14032. fprintf(fp, "%s\n", url);
  14033. fprintf(fp, "%s\n", filename);
  14034. fclose(fp);
  14035. }
  14036. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14037. if(phpFP == NULL)
  14038. {
  14039. DEBUG_INFO("PHP upload fail.\n");
  14040. return FALSE;
  14041. }
  14042. else
  14043. {
  14044. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14045. {
  14046. if(strstr(buf, "result") != NULL)
  14047. {
  14048. sscanf(buf, "result: %d", &systemresult);
  14049. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14050. }
  14051. }
  14052. pclose(phpFP);
  14053. }
  14054. if(systemresult != 1)
  14055. {
  14056. DEBUG_INFO("HTTP upload error!\n");
  14057. return FALSE;
  14058. }
  14059. return TRUE;
  14060. }
  14061. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14062. {
  14063. struct hostent* server;
  14064. char *IPbuffer;
  14065. char ftpbuf[200];
  14066. int systemresult;
  14067. // To retrieve host information
  14068. server = gethostbyname(location);
  14069. // To convert an Internet network
  14070. // address into ASCII string
  14071. IPbuffer = inet_ntoa(*((struct in_addr*)
  14072. server->h_addr_list[0]));
  14073. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14074. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14075. /* format : ftpput -u username -p passwd IP target source*/
  14076. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14077. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14078. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14079. systemresult = system(ftpbuf);
  14080. DEBUG_INFO("systemresult=%d\n",systemresult);
  14081. if(systemresult != 0)
  14082. {
  14083. DEBUG_INFO("ftpput error!\n");
  14084. return FALSE;
  14085. }
  14086. return TRUE;
  14087. }
  14088. int GetOcppServerURL()
  14089. {
  14090. int result = FALSE;
  14091. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14092. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14093. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14094. struct yuarel url;
  14095. char urlStr[512];
  14096. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14097. {
  14098. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14099. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14100. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14101. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14102. if(yuarel_parse(&url, urlStr) != -1)
  14103. {
  14104. sprintf(OcppProtocol, "%s", url.scheme);
  14105. sprintf(OcppHost, "%s", url.host);
  14106. if(url.path == NULL)
  14107. OcppTempPath[0] = '\0';
  14108. else
  14109. {
  14110. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14111. {
  14112. sprintf(OcppTempPath, "%s/", url.path);
  14113. }
  14114. else
  14115. {
  14116. sprintf(OcppTempPath, "%s", url.path);
  14117. }
  14118. }
  14119. if(url.port == 0)
  14120. {
  14121. if(strcmp(OcppProtocol, "wss") == 0)
  14122. OcppPort = 443;
  14123. else
  14124. OcppPort = 80;
  14125. }
  14126. else
  14127. OcppPort = url.port;
  14128. result = TRUE;
  14129. }
  14130. }
  14131. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14132. {
  14133. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14134. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14135. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14136. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14137. if(yuarel_parse(&url, urlStr) != -1)
  14138. {
  14139. sprintf(OcppProtocol, "%s", url.scheme);
  14140. sprintf(OcppHost, "%s", url.host);
  14141. if(url.path == NULL)
  14142. OcppTempPath[0] = '\0';
  14143. else
  14144. sprintf(OcppTempPath, "%s", url.path);
  14145. if(url.port == 0)
  14146. {
  14147. if(strcmp(OcppProtocol, "wss") == 0)
  14148. OcppPort = 443;
  14149. else
  14150. OcppPort = 80;
  14151. }
  14152. else
  14153. OcppPort = url.port;
  14154. result = TRUE;
  14155. }
  14156. }
  14157. else
  14158. {
  14159. strcpy(OcppHost,"");
  14160. }
  14161. return result;
  14162. }
  14163. int GetOcppPath()
  14164. {
  14165. int result = FALSE;
  14166. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14167. {
  14168. if(OcppTempPath == NULL)
  14169. {
  14170. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14171. }
  14172. else
  14173. {
  14174. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14175. }
  14176. result = TRUE;
  14177. goto End;
  14178. }
  14179. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14180. {
  14181. if(OcppTempPath == NULL)
  14182. {
  14183. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14184. }
  14185. else
  14186. {
  14187. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14188. }
  14189. result = TRUE;
  14190. goto End;
  14191. }
  14192. else
  14193. {
  14194. strcpy(OcppPath,"");
  14195. }
  14196. End:
  14197. return result;
  14198. }
  14199. int GetOcppPort()
  14200. {
  14201. return OcppPort;
  14202. }
  14203. int GetOcppConnStatus(void)
  14204. {
  14205. return ShmOCPP16Data->OcppConnStatus;
  14206. }
  14207. void SetOcppConnStatus(uint8_t status)
  14208. {
  14209. ShmOCPP16Data->OcppConnStatus = status;
  14210. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14211. }
  14212. int GetHeartBeatWithNOResponse(void)
  14213. {
  14214. return HeartBeatWithNOResponse;
  14215. }
  14216. void SetHeartBeatWithNOResponse(void)
  14217. {
  14218. HeartBeatWithNOResponse = 0;
  14219. }
  14220. void GetStartTransactionIdTag(int gun_index)
  14221. {
  14222. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14223. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14224. }
  14225. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14226. {
  14227. char ch;
  14228. FILE *fptr1;
  14229. int temptransactionId;
  14230. char str[100]={0};
  14231. temptransactionId = 0;
  14232. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14233. {
  14234. DEBUG_INFO("IdTag is empty.\n");
  14235. return temptransactionId;
  14236. }
  14237. /*------ Read the file ----------------*/
  14238. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14239. if (!fptr1)
  14240. {
  14241. DEBUG_INFO("QueueTransactionId file open error.\n");
  14242. //printf(" File not found or unable to open the input file!!\n");
  14243. return temptransactionId;
  14244. }
  14245. ch=fgetc(fptr1);
  14246. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14247. rewind(fptr1);
  14248. if(ch!=EOF)
  14249. {
  14250. // printf("%c",ch);
  14251. while (fgets(str, 100, fptr1) != NULL)
  14252. {
  14253. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14254. if(str[0]=='\0')
  14255. {
  14256. break;
  14257. }
  14258. char *revbuf[8] = {0}; // Variable store string split
  14259. int num = 0;// Quantity after string split
  14260. DEBUG_INFO("Transaction queue data= %s\n", str);
  14261. splitstring(str,",",revbuf,&num); // String split
  14262. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14263. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14264. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14265. DEBUG_INFO("------------------------------\n");
  14266. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14267. {
  14268. if(isStopTransaction)
  14269. {
  14270. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14271. {
  14272. temptransactionId = atoi(revbuf[2]);
  14273. //break;
  14274. }
  14275. }
  14276. else
  14277. {
  14278. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14279. {
  14280. temptransactionId = atoi(revbuf[2]);
  14281. //break;
  14282. }
  14283. }
  14284. }
  14285. }
  14286. }
  14287. else
  14288. DEBUG_INFO("EOF\n");
  14289. fclose(fptr1);
  14290. /*------- End of reading ---------------*/
  14291. return temptransactionId;
  14292. }
  14293. void SetTransactionIdZero(int transactionId)
  14294. {
  14295. char ch;
  14296. FILE *fptr1, *fptr2;
  14297. int temptransactionId = 0;
  14298. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14299. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14300. if (!fptr1)
  14301. {
  14302. //printf(" File not found or unable to open the input file!!\n");
  14303. return ;
  14304. }
  14305. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14306. if (!fptr2)
  14307. {
  14308. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14309. fclose(fptr1);
  14310. return ;
  14311. }
  14312. ch=fgetc(fptr1);
  14313. rewind(fptr1);
  14314. if(ch!=EOF)
  14315. {
  14316. // copy all contents to the temporary file except the specific line
  14317. while (fgets(str, 100, fptr1) != NULL)
  14318. {
  14319. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14320. if(str[0]=='\0')
  14321. {
  14322. break;
  14323. }
  14324. char *revbuf[8] = {0};
  14325. int num = 0;
  14326. strcpy(strtemp, str);
  14327. splitstring(str,",",revbuf,&num);
  14328. if(revbuf[2][0] != '\0')
  14329. {
  14330. temptransactionId = atoi(revbuf[2]);
  14331. if(transactionId != temptransactionId)
  14332. {
  14333. fprintf(fptr2, "%s\n", strtemp);
  14334. }
  14335. }
  14336. }
  14337. }
  14338. fclose(fptr1);
  14339. fclose(fptr2);
  14340. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14341. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14342. /*------ Read the file ----------------*/
  14343. }
  14344. int InternetDisconnect(void)
  14345. {
  14346. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14347. }
  14348. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14349. void storeTempStopTransaction(int gun_index)
  14350. {
  14351. char guid[37]={0};
  14352. int tempIndex = 0;
  14353. char TempStopTransaction[256];
  14354. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14355. DEBUG_INFO("storeTempStopTransaction...\n");
  14356. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14357. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14358. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14359. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14360. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14361. {
  14362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14363. {
  14364. tempIndex = ((gun_index==2) ? 1: 0);
  14365. }
  14366. else
  14367. {
  14368. tempIndex = gun_index;
  14369. }
  14370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14371. {
  14372. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14373. {
  14374. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14375. }
  14376. }// END OF CHAdeMO_QUANTITY
  14377. }
  14378. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14379. {
  14380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14381. {
  14382. tempIndex = ((gun_index==2) ? 1: 0);
  14383. }
  14384. else
  14385. {
  14386. tempIndex = gun_index;
  14387. }
  14388. for (int index = 0; index < CCS_QUANTITY; index++)
  14389. {
  14390. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14391. {
  14392. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14393. }
  14394. }// END OF CCS_QUANTITY
  14395. }
  14396. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14397. {
  14398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14399. {
  14400. tempIndex = ((gun_index==2) ? 1: 0);
  14401. }
  14402. else
  14403. {
  14404. tempIndex = gun_index;
  14405. }
  14406. for (int index = 0; index < GB_QUANTITY; index++)
  14407. {
  14408. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14409. {
  14410. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14411. }
  14412. }// END OF GB_QUANTITY
  14413. }
  14414. else if(gunType[gun_index] == GUN_TYPE_DO)
  14415. {
  14416. tempIndex = gun_index;
  14417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14418. {
  14419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14420. {
  14421. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14422. }
  14423. }
  14424. }
  14425. else
  14426. {
  14427. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14428. {
  14429. tempIndex = 2;
  14430. }
  14431. else
  14432. {
  14433. tempIndex = gun_index;
  14434. }
  14435. for (int index = 0; index < AC_QUANTITY; index++)
  14436. {
  14437. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14438. {
  14439. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14440. }
  14441. }// END OF AC_QUANTITY
  14442. }
  14443. //Stop Transaction Time
  14444. struct timeval tmnow;
  14445. struct tm *tm;
  14446. char buf[28];//, usec_buf[6];
  14447. gettimeofday(&tmnow, NULL);
  14448. time_t t;
  14449. t = time(NULL);
  14450. /*UTC time and date*/
  14451. tm = gmtime(&t);
  14452. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14454. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14456. random_uuid(guid);
  14457. /***********************************transactionData******************************************************/
  14458. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14460. //=================================
  14461. //1. Transaction_Begin
  14462. //=================================
  14463. //============================== Energy.Active.Import.Interval ===========================================
  14464. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14465. {
  14466. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14469. 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*/]);
  14470. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14471. 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))
  14472. {
  14473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14474. }
  14475. else
  14476. {
  14477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14478. }
  14479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14481. }
  14482. //=================================
  14483. //2. Transaction_End
  14484. //=================================
  14485. //2.1====================================== Current.Import L1 ==============================================
  14486. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14487. {
  14488. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14489. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14490. {
  14491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14492. {
  14493. tempIndex = ((gun_index==2) ? 1: 0);
  14494. }
  14495. else
  14496. {
  14497. tempIndex = gun_index;
  14498. }
  14499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14500. {
  14501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14502. {
  14503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14504. }
  14505. }// End of for CHAdeMO_QUANTITY
  14506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14507. }
  14508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14509. {
  14510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14511. {
  14512. tempIndex = ((gun_index==2) ? 1: 0);
  14513. }
  14514. else
  14515. {
  14516. tempIndex = gun_index;
  14517. }
  14518. for (int index = 0; index < CCS_QUANTITY; index++)
  14519. {
  14520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14521. {
  14522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14523. }
  14524. }// End of for CCS_QUANTITY
  14525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14526. }
  14527. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14528. {
  14529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14530. {
  14531. tempIndex = ((gun_index==2) ? 1: 0);
  14532. }
  14533. else
  14534. {
  14535. tempIndex = gun_index;
  14536. }
  14537. for (int index = 0; index < GB_QUANTITY; index++)
  14538. {
  14539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14540. {
  14541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14542. }
  14543. }// End of for GB_QUANTITY
  14544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14545. }
  14546. else if(gunType[gun_index] == GUN_TYPE_DO)
  14547. {
  14548. tempIndex = gun_index;
  14549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14550. {
  14551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14552. {
  14553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14554. }
  14555. }
  14556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14557. }
  14558. else
  14559. {
  14560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14561. {
  14562. tempIndex = 2;
  14563. }
  14564. else
  14565. {
  14566. tempIndex = gun_index;
  14567. }
  14568. for (int index = 0; index < AC_QUANTITY; index++)
  14569. {
  14570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14571. {
  14572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14573. }
  14574. }// End of for AC_QUANTITY
  14575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14576. }
  14577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14580. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14583. }
  14584. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14585. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14586. {
  14587. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14589. {
  14590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14591. {
  14592. tempIndex = ((gun_index==2) ? 1: 0);
  14593. }
  14594. else
  14595. {
  14596. tempIndex = gun_index;
  14597. }
  14598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14599. {
  14600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14601. {
  14602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14603. }
  14604. }// END OF CHAdeMO_QUANTITY
  14605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14606. }
  14607. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14608. {
  14609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14610. {
  14611. tempIndex = ((gun_index==2) ? 1: 0);
  14612. }
  14613. else
  14614. {
  14615. tempIndex = gun_index;
  14616. }
  14617. for (int index = 0; index < CCS_QUANTITY; index++)
  14618. {
  14619. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14620. {
  14621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14622. }
  14623. }// END OF CCS_QUANTITY
  14624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14625. }
  14626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14627. {
  14628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14629. {
  14630. tempIndex = ((gun_index==2) ? 1: 0);
  14631. }
  14632. else
  14633. {
  14634. tempIndex = gun_index;
  14635. }
  14636. for (int index = 0; index < GB_QUANTITY; index++)
  14637. {
  14638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14639. {
  14640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14641. }
  14642. }// END OF GB_QUANTITY
  14643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14644. }
  14645. else if(gunType[gun_index] == GUN_TYPE_DO)
  14646. {
  14647. tempIndex = gun_index;
  14648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14649. {
  14650. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14651. {
  14652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14653. }
  14654. }
  14655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14656. }
  14657. else
  14658. {
  14659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14660. {
  14661. tempIndex = 2;
  14662. }
  14663. else
  14664. {
  14665. tempIndex = gun_index;
  14666. }
  14667. for (int index = 0; index < AC_QUANTITY; index++)
  14668. {
  14669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14670. {
  14671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14672. }
  14673. }// END OF AC_QUANTITY
  14674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14675. }
  14676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14679. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14682. }
  14683. //2.3====================================== Power.Active.Import =========================================
  14684. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14685. {
  14686. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14687. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14688. {
  14689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14690. {
  14691. tempIndex = ((gun_index==2) ? 1: 0);
  14692. }
  14693. else
  14694. {
  14695. tempIndex = gun_index;
  14696. }
  14697. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14698. {
  14699. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14700. {
  14701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14702. }
  14703. } // End for CHAdeMO_QUANTITY
  14704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14705. }
  14706. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14707. {
  14708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14709. {
  14710. tempIndex = ((gun_index==2) ? 1: 0);
  14711. }
  14712. else
  14713. {
  14714. tempIndex = gun_index;
  14715. }
  14716. for (int index = 0; index < CCS_QUANTITY; index++)
  14717. {
  14718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14719. {
  14720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14721. }
  14722. } // END for CCS_QUANTITY
  14723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14724. }
  14725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14726. {
  14727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14728. {
  14729. tempIndex = ((gun_index==2) ? 1: 0);
  14730. }
  14731. else
  14732. {
  14733. tempIndex = gun_index;
  14734. }
  14735. for (int index = 0; index < GB_QUANTITY; index++)
  14736. {
  14737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14738. {
  14739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14740. }
  14741. }// END for GB_QUANTITY
  14742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14743. }
  14744. else if(gunType[gun_index] == GUN_TYPE_DO)
  14745. {
  14746. tempIndex = gun_index;
  14747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14748. {
  14749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14750. {
  14751. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14752. }
  14753. }
  14754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14755. }
  14756. else
  14757. {
  14758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14759. {
  14760. tempIndex = 2;
  14761. }
  14762. else
  14763. {
  14764. tempIndex = gun_index;
  14765. }
  14766. for (int index = 0; index < AC_QUANTITY; index++)
  14767. {
  14768. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14769. {
  14770. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14771. }
  14772. } // END for AC_QUANTITY
  14773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14774. }
  14775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14778. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14781. }
  14782. //2.4====================================== Voltage L1 ====================================================
  14783. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14784. {
  14785. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14786. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14787. {
  14788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14789. {
  14790. tempIndex = ((gun_index==2) ? 1: 0);
  14791. }
  14792. else
  14793. {
  14794. tempIndex = gun_index;
  14795. }
  14796. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14797. {
  14798. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14799. {
  14800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14801. }
  14802. } // END OF FOR CHAdeMO_QUANTITY
  14803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14804. }
  14805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14806. {
  14807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14808. {
  14809. tempIndex = ((gun_index==2) ? 1: 0);
  14810. }
  14811. else
  14812. {
  14813. tempIndex = gun_index;
  14814. }
  14815. for (int index = 0; index < CCS_QUANTITY; index++)
  14816. {
  14817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14818. {
  14819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14820. }
  14821. } // END OF FOR CCS_QUANTITY
  14822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14823. }
  14824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14825. {
  14826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14827. {
  14828. tempIndex = ((gun_index==2) ? 1: 0);
  14829. }
  14830. else
  14831. {
  14832. tempIndex = gun_index;
  14833. }
  14834. for (int index = 0; index < GB_QUANTITY; index++)
  14835. {
  14836. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14837. {
  14838. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14839. }
  14840. } // END OF FOR GB_QUANTITY
  14841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14842. }
  14843. else if(gunType[gun_index] == GUN_TYPE_DO)
  14844. {
  14845. tempIndex = gun_index;
  14846. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14847. {
  14848. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14849. {
  14850. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14851. }
  14852. }
  14853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14854. }
  14855. else
  14856. {
  14857. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14858. {
  14859. tempIndex = 2;
  14860. }
  14861. else
  14862. {
  14863. tempIndex = gun_index;
  14864. }
  14865. for (int index = 0; index < AC_QUANTITY; index++)
  14866. {
  14867. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14868. {
  14869. 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
  14870. }
  14871. } // END OF FOR AC_QUANTITY
  14872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14873. }
  14874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14877. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14880. }
  14881. //2.5============================================== End SoC =========================================================
  14882. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14883. {
  14884. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14885. 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))
  14886. {
  14887. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14888. {
  14889. tempIndex = ((gun_index==2) ? 1: 0);
  14890. }
  14891. else
  14892. {
  14893. tempIndex = gun_index;
  14894. }
  14895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14896. {
  14897. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14898. {
  14899. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14900. {
  14901. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14902. }
  14903. }
  14904. }
  14905. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14906. {
  14907. for (int index = 0; index < CCS_QUANTITY; index++)
  14908. {
  14909. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14910. {
  14911. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14912. }
  14913. }
  14914. }
  14915. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14916. {
  14917. for (int index = 0; index < GB_QUANTITY; index++)
  14918. {
  14919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14920. {
  14921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14922. }
  14923. }
  14924. }
  14925. else if(gunType[gun_index] == GUN_TYPE_DO)
  14926. {
  14927. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14928. {
  14929. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14930. {
  14931. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14932. }
  14933. }
  14934. }
  14935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14941. } // END FOR DC CASE
  14942. }
  14943. //2.6====================================== Current.Import L2 ==============================================
  14944. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14945. {
  14946. // AC 3 phase L2 current
  14947. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14948. {
  14949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14950. {
  14951. tempIndex = 2;
  14952. }
  14953. else
  14954. {
  14955. tempIndex = gun_index;
  14956. }
  14957. for (int index = 0; index < AC_QUANTITY; index++)
  14958. {
  14959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14960. {
  14961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14962. }
  14963. }// End of for AC_QUANTITY
  14964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14965. }
  14966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14971. }
  14972. //2.7====================================== Current.Import L3 ==============================================
  14973. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14974. {
  14975. // AC 3 phase L3 current
  14976. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14977. {
  14978. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14979. {
  14980. tempIndex = 2;
  14981. }
  14982. else
  14983. {
  14984. tempIndex = gun_index;
  14985. }
  14986. for (int index = 0; index < AC_QUANTITY; index++)
  14987. {
  14988. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14989. {
  14990. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14991. }
  14992. }// End of for AC_QUANTITY
  14993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14994. }
  14995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15000. }
  15001. //2.9====================================== Voltage L2 ====================================================
  15002. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15003. {
  15004. // AC 3 phase L2 volatge
  15005. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15006. {
  15007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15008. {
  15009. tempIndex = 2;
  15010. }
  15011. else
  15012. {
  15013. tempIndex = gun_index;
  15014. }
  15015. for (int index = 0; index < AC_QUANTITY; index++)
  15016. {
  15017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15018. {
  15019. 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
  15020. }
  15021. } // END OF FOR AC_QUANTITY
  15022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15023. }
  15024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15029. }
  15030. //2.10====================================== Voltage L3 ====================================================
  15031. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15032. {
  15033. // AC 3 phase L3 volatge
  15034. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15035. {
  15036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15037. {
  15038. tempIndex = 2;
  15039. }
  15040. else
  15041. {
  15042. tempIndex = gun_index;
  15043. }
  15044. for (int index = 0; index < AC_QUANTITY; index++)
  15045. {
  15046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15047. {
  15048. 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
  15049. }
  15050. } // END OF FOR AC_QUANTITY
  15051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15052. }
  15053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15058. }
  15059. //====================== Start SoC ================================
  15060. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15061. {
  15062. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15063. 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))
  15064. {
  15065. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15066. {
  15067. tempIndex = ((gun_index==2) ? 1: 0);
  15068. }
  15069. else
  15070. {
  15071. tempIndex = gun_index;
  15072. }
  15073. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15074. {
  15075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15076. {
  15077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15078. {
  15079. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15080. }
  15081. }
  15082. }
  15083. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15084. {
  15085. for (int index = 0; index < CCS_QUANTITY; index++)
  15086. {
  15087. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15088. {
  15089. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15090. }
  15091. }
  15092. }
  15093. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15094. {
  15095. for (int index = 0; index < GB_QUANTITY; index++)
  15096. {
  15097. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15098. {
  15099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15100. }
  15101. }
  15102. }
  15103. else if(gunType[gun_index] == GUN_TYPE_DO)
  15104. {
  15105. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15106. {
  15107. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15108. {
  15109. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15110. }
  15111. }
  15112. }
  15113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15119. } // END FOR DC CASE
  15120. }
  15121. //======================================== Message create ==============================================
  15122. json_object *StopTransaction = json_object_new_object();
  15123. json_object *transactionDatas = json_object_new_array();
  15124. json_object *sampledValues = json_object_new_array();
  15125. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15126. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15127. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15128. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15129. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15130. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15131. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15132. {
  15133. json_object *transactionData = json_object_new_object();
  15134. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15135. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15136. {
  15137. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15138. {
  15139. json_object *sampledValue = json_object_new_object();
  15140. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15141. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15142. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15143. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15144. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15145. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15146. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15147. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15148. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15149. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15150. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15151. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15152. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15153. json_object_array_add(sampledValues, sampledValue);
  15154. }
  15155. }
  15156. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15157. json_object_array_add(transactionDatas, transactionData);
  15158. }
  15159. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15160. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15161. ,MESSAGE_TYPE_CALL
  15162. ,guid
  15163. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15164. json_object_put(StopTransaction);
  15165. // Check File "TempStopTransaction" Exist
  15166. if((access(TempStopTransaction,F_OK))!=-1)
  15167. {
  15168. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15169. fclose(fopen(TempStopTransaction, "w"));
  15170. }
  15171. else
  15172. {
  15173. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15174. FILE *log = fopen(TempStopTransaction, "w+");
  15175. if(log == NULL)
  15176. {
  15177. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15178. return ;
  15179. }
  15180. else
  15181. {
  15182. fclose(log);
  15183. }
  15184. }
  15185. //Add TempStopTransaction | Update TempStopTransaction
  15186. // open file for writing
  15187. FILE *outfile;
  15188. outfile = fopen (TempStopTransaction, "a");
  15189. //DEBUG_INFO("data = %s\n", queuedata);
  15190. fputs(queuedata, outfile);
  15191. fputs("\n", outfile);
  15192. fclose (outfile);
  15193. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15194. }
  15195. void checkTempStopTransaction(int gun_index)
  15196. {
  15197. FILE *fptr1;
  15198. char ch;
  15199. char str[QUEUE_MESSAGE_LENGTH]={0};
  15200. char guid[37]={0};
  15201. char tempdata[65]={0};
  15202. char connectorStr[2]={0};
  15203. char TempStopTransaction[256];
  15204. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15205. fptr1 = fopen(TempStopTransaction, "r");
  15206. //TempStopTransaction格式: 槍號,StopTransaction封包
  15207. if (!fptr1)
  15208. {
  15209. //printf(" File not found or unable to open the input file!!\n");
  15210. return ;
  15211. }
  15212. ch=fgetc(fptr1);
  15213. //printf(" Now the content of the file %s is : \n",fname);
  15214. rewind(fptr1);
  15215. if(ch!=EOF)
  15216. {
  15217. // copy all contents to the temporary file except the specific line
  15218. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15219. {
  15220. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15221. if(str[0]=='\0')
  15222. {
  15223. break;
  15224. }
  15225. //TempStopTransaction格式: 槍號,StopTransaction封包
  15226. strncpy(connectorStr, str, 1);
  15227. if(atoi(connectorStr) != (gun_index+1))
  15228. {
  15229. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15230. fclose(fptr1);
  15231. return ;
  15232. }
  15233. //random_uuid(guid);
  15234. strncpy(guid, str+6, 36); //copy guid
  15235. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15236. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15237. {
  15238. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15239. }
  15240. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15241. OCPP_insert_transaction_msg(NO, str);
  15242. memset(str,0,ARRAY_SIZE(str));
  15243. }
  15244. }
  15245. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15246. fclose(fptr1);
  15247. remove(TempStopTransaction); // remove the original file
  15248. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15249. }
  15250. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15251. {
  15252. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15253. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15254. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15255. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15256. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15257. }
  15258. int GetWebSocketPingInterval(void)
  15259. {
  15260. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15261. }
  15262. int GetServerSign(void)
  15263. {
  15264. return server_sign;
  15265. }
  15266. uint8_t GetOcppSecurityProfile()
  15267. {
  15268. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15269. }
  15270. void GetOcppChargerBoxId(uint8_t *data)
  15271. {
  15272. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  15273. }
  15274. void GetOcppSecurityPassword(uint8_t *data)
  15275. {
  15276. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15277. }
  15278. void SetOcppVersion(uint8_t *version)
  15279. {
  15280. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15281. DEBUG_INFO("ocpp version: %s\n", version);
  15282. if(strstr((char*)version, "ocpp1.6") != NULL)
  15283. {
  15284. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15285. }
  15286. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15287. {
  15288. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15289. system("pkill OcppBackend");
  15290. }
  15291. }
  15292. void SetServerSign(int value)
  15293. {
  15294. server_sign = value;
  15295. }
  15296. int GetBootNotificationInterval(void)
  15297. {
  15298. return BootNotificationInterval;
  15299. }
  15300. int GetInternetConn(void)
  15301. {
  15302. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15303. }
  15304. int isConnectorInitMode(int gun_index)
  15305. {
  15306. int tempIndex = 0;
  15307. int result = TRUE;
  15308. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15309. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15310. {
  15311. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15312. {
  15313. tempIndex = ((gun_index==2) ? 1: 0);
  15314. }
  15315. else
  15316. {
  15317. tempIndex = gun_index;
  15318. }
  15319. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15320. {
  15321. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15322. {
  15323. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15324. } //end of the same index
  15325. }//end of for CHAdeMO_QUANTITY
  15326. }
  15327. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15328. {
  15329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15330. {
  15331. tempIndex = ((gun_index==2) ? 1: 0);
  15332. }
  15333. else
  15334. {
  15335. tempIndex = gun_index;
  15336. }
  15337. for (int index = 0; index < CCS_QUANTITY; index++)
  15338. {
  15339. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15340. {
  15341. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15342. } //end of the same index
  15343. } // end of for CCS_QUANTITY
  15344. }
  15345. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15346. {
  15347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15348. {
  15349. tempIndex = ((gun_index==2) ? 1: 0);
  15350. }
  15351. else
  15352. {
  15353. tempIndex = gun_index;
  15354. }
  15355. for (int index = 0; index < GB_QUANTITY; index++)
  15356. {
  15357. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15358. {
  15359. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15360. } //end of the same index
  15361. } // end of for GB_QUANTITY
  15362. }
  15363. else if(gunType[gun_index] == GUN_TYPE_DO)
  15364. {
  15365. tempIndex = gun_index;
  15366. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15367. {
  15368. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15369. {
  15370. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15371. } //end of the same index
  15372. }
  15373. }
  15374. else
  15375. {
  15376. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15377. {
  15378. tempIndex = 2;
  15379. }
  15380. else
  15381. {
  15382. tempIndex = gun_index;
  15383. }
  15384. for (int index = 0; index < AC_QUANTITY; index++)
  15385. {
  15386. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15387. {
  15388. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15389. }//end of the same index
  15390. }//end of for AC_QUANTITY
  15391. }
  15392. return result;
  15393. }
  15394. void refreshProcDogTimer()
  15395. {
  15396. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15397. }
  15398. void InitialSystemValue(void)
  15399. {
  15400. int connectorIndex = 0;
  15401. //int valueASCII = 0;
  15402. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15403. gunTotalNumber=0;
  15404. SystemInitial = 0;
  15405. localversion=0;
  15406. BootNotificationInterval = 0;
  15407. authorizeRetryTimes = 0;
  15408. GunStatusInterval = 10;
  15409. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15410. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15411. //Hear Beat
  15412. HeartBeatWithNOResponse = 0;
  15413. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15414. FirstHeartBeat = 0;
  15415. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15416. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15417. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15418. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15419. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15420. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15421. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15422. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15423. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15424. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15425. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15426. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15427. memset(gunType, 0, ARRAY_SIZE(gunType));
  15428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15429. {
  15430. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15431. {
  15432. // DO series
  15433. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15434. {
  15435. SystemInitial = SystemInitial + 1;
  15436. gunTotalNumber = gunTotalNumber + 1;
  15437. gunType[connectorIndex] = GUN_TYPE_DO;
  15438. connectorIndex = connectorIndex + 1;
  15439. }
  15440. }
  15441. else
  15442. {
  15443. // DM, DW, DS series
  15444. //check connector / socket type (index: 8, 9, 10)
  15445. for(int index=7; index <10 ; index++)
  15446. {
  15447. if(index != 8)
  15448. {
  15449. // DC Connector
  15450. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15451. {
  15452. SystemInitial = SystemInitial + 1;
  15453. gunTotalNumber = gunTotalNumber + 1;
  15454. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15455. connectorIndex = connectorIndex + 1;
  15456. }
  15457. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15458. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15459. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15460. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15461. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15462. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15463. {
  15464. SystemInitial = SystemInitial + 1;
  15465. gunTotalNumber = gunTotalNumber + 1;
  15466. gunType[connectorIndex] = GUN_TYPE_CCS;
  15467. connectorIndex = connectorIndex + 1;
  15468. }
  15469. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15470. {
  15471. SystemInitial = SystemInitial + 1;
  15472. gunTotalNumber = gunTotalNumber + 1;
  15473. gunType[connectorIndex] = GUN_TYPE_GBT;
  15474. connectorIndex = connectorIndex + 1;
  15475. }
  15476. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15477. {
  15478. SystemInitial = SystemInitial + 1;
  15479. gunTotalNumber = gunTotalNumber + 1;
  15480. gunType[connectorIndex] = GUN_TYPE_DO;
  15481. connectorIndex = connectorIndex + 1;
  15482. }
  15483. }
  15484. else
  15485. {
  15486. // AC Connector
  15487. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15488. {
  15489. SystemInitial = SystemInitial + 1;
  15490. gunTotalNumber = gunTotalNumber + 1;
  15491. gunType[connectorIndex] = GUN_TYPE_AC;
  15492. connectorIndex = connectorIndex + 1;
  15493. }
  15494. }
  15495. }
  15496. }
  15497. //DEBUG_INFO("DC ...\n");
  15498. }
  15499. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15500. {
  15501. //check connector / socket type (index: 8, 9, 10)
  15502. for(int index=7; index <10 ; index++)
  15503. {
  15504. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15505. {
  15506. SystemInitial = SystemInitial + 1;
  15507. gunTotalNumber = gunTotalNumber + 1;
  15508. gunType[connectorIndex] = GUN_TYPE_AC;
  15509. connectorIndex = connectorIndex + 1;
  15510. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15511. }
  15512. }
  15513. }
  15514. //Status && ConnectorPlugIn Setting
  15515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15516. {
  15517. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15518. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15519. }
  15520. for (int index = 0; index < CCS_QUANTITY; index++)
  15521. {
  15522. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15523. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15524. }
  15525. for (int index = 0; index < GB_QUANTITY; index++)
  15526. {
  15527. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15528. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15529. }
  15530. for (int index = 0; index < AC_QUANTITY; index++)
  15531. {
  15532. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15533. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15534. }
  15535. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15536. {
  15537. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15538. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15539. }
  15540. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15541. {
  15542. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15543. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15544. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15545. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15546. }
  15547. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15548. clientTime.Heartbeat=time((time_t*)NULL);
  15549. sleep(1);
  15550. }
  15551. void LWS_Send(char * str)
  15552. {
  15553. //=====================================================
  15554. // Check InternetConn 0: disconnected, 1: connected
  15555. //====================================================
  15556. if(GetOcppConnStatus() == 0)
  15557. {
  15558. DEBUG_INFO("offline now !!!\n");
  15559. return;
  15560. }
  15561. pthread_mutex_lock(&lock_send);
  15562. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15563. sprintf((char *)SendBuffer, "%s", str);
  15564. SendBufLen = strlen(str);
  15565. pthread_mutex_unlock(&lock_send);
  15566. lws_callback_on_writable(wsi_client);
  15567. //lws_service(context, 0);
  15568. //sleep(1);
  15569. }
  15570. void LWS_SendNow(char * str)
  15571. {
  15572. //=====================================================
  15573. // Check InternetConn 0: disconnected, 1: connected
  15574. //====================================================
  15575. if(GetOcppConnStatus() == 0)
  15576. {
  15577. DEBUG_INFO("offline now !!!\n");
  15578. return;
  15579. }
  15580. pthread_mutex_lock(&lock_send);
  15581. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15582. sprintf((char *)SendBuffer, "%s", str);
  15583. SendBufLen = strlen(str);
  15584. pthread_mutex_unlock(&lock_send);
  15585. lws_callback_on_writable(wsi_client);
  15586. lws_service(context, 0);
  15587. //sleep(1);
  15588. }