MessageHandler.c 839 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347
  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: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {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 locallistVersion=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 ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct StructOCPPMeterValue
  92. {
  93. unsigned char TimeStamp[28];
  94. struct StructSampledValue SampledValue[10];
  95. };
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // TTIA routine
  356. //=========================================
  357. int sendTTIAInfo(uint8_t gun_index)
  358. {
  359. static int sn = 0;
  360. int result = FAIL;
  361. struct hostent *server;
  362. int udp_socket_fd;
  363. struct sockaddr_in dest_addr = {0};
  364. uint8_t tx_buf[80] = {0};
  365. uint8_t logBuf[256]= {0};
  366. uint8_t tx_len, tempIndex, socStart, socEnd;
  367. uint16_t PresentChargedEnergy;
  368. struct tm tmStart, tmEnd;
  369. DEBUG_INFO("sendTTIAInfo...\n");
  370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  371. {
  372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  373. {
  374. tempIndex = ((gun_index==2) ? 1: 0);
  375. }
  376. else
  377. {
  378. tempIndex = gun_index;
  379. }
  380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  381. {
  382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  383. {
  384. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  385. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  386. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  387. }
  388. }
  389. }
  390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  391. {
  392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  393. {
  394. tempIndex = ((gun_index==2) ? 1: 0);
  395. }
  396. else
  397. {
  398. tempIndex = gun_index;
  399. }
  400. for (int index = 0; index < CCS_QUANTITY; index++)
  401. {
  402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  403. {
  404. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  405. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  406. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  407. }
  408. }
  409. }
  410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < GB_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_DO)
  431. {
  432. tempIndex = gun_index;
  433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  434. {
  435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  436. {
  437. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  438. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  439. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  440. }
  441. }
  442. }
  443. else
  444. {
  445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  446. {
  447. tempIndex = 2;
  448. }
  449. else
  450. {
  451. tempIndex = gun_index;
  452. }
  453. for (int index = 0; index < AC_QUANTITY; index++)
  454. {
  455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  456. {
  457. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  458. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  459. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  460. }
  461. }// END
  462. }
  463. // Message assembly
  464. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  465. tx_buf[4] = 0x02; // Protocol Version
  466. tx_buf[5] = 0xb0; // Message ID
  467. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  468. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  469. tx_buf[8] = 0x00; // CarID low byte
  470. tx_buf[9] = 0x00; // CarID high byte
  471. tx_buf[10] = 0x00; // ID Storage
  472. tx_buf[11] = 0x00; // Driver lowest byte
  473. tx_buf[12] = 0x00; // Driver 2nd byte
  474. tx_buf[13] = 0x00; // Driver 3rd byte
  475. tx_buf[14] = 0x00; // Driver highest byte
  476. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  477. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  478. tx_buf[17] = 0x00; // Reserve
  479. tx_buf[18] = 60 & 0xff; // Payload length low byte
  480. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  481. // EVSE provider
  482. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  483. // EVSE provider
  484. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  485. // EVSE id
  486. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  487. // Connector id
  488. tx_buf[37] = gun_index;
  489. // EVSE station
  490. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  491. // Vehicle SN
  492. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  493. // Mileage
  494. tx_buf[61] = 0x00; // lowest byte
  495. tx_buf[62] = 0x00; // 2nd byte
  496. tx_buf[63] = 0x00; // highest byte
  497. // Start date time 6 bytes
  498. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%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))
  499. {
  500. tx_buf[64] = (tmStart.tm_year-2000);
  501. tx_buf[65] = tmStart.tm_mon;
  502. tx_buf[66] = tmStart.tm_mday;
  503. tx_buf[67] = tmStart.tm_hour;
  504. tx_buf[68] = tmStart.tm_min;
  505. tx_buf[69] = tmStart.tm_sec;
  506. }
  507. // Stop date time 6 bytes
  508. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  509. {
  510. tx_buf[70] = (tmEnd.tm_year-2000);
  511. tx_buf[71] = tmEnd.tm_mon;
  512. tx_buf[72] = tmEnd.tm_mday;
  513. tx_buf[73] = tmEnd.tm_hour;
  514. tx_buf[74] = tmEnd.tm_min;
  515. tx_buf[75] = tmEnd.tm_sec;
  516. }
  517. // Session energy 2 bytes
  518. tx_buf[76] = PresentChargedEnergy & 0xff;
  519. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  520. // Start SOC 1 byte
  521. tx_buf[78] = socStart;
  522. // Stop SOC 1 byte
  523. tx_buf[79] = socEnd;
  524. // Open socket
  525. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  526. if(udp_socket_fd == -1)
  527. {
  528. DEBUG_ERROR("UDP socket create failed!\n");
  529. }
  530. else
  531. {
  532. // Get server DNS entry
  533. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  534. if (server == NULL)
  535. {
  536. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  537. }
  538. else
  539. {
  540. // Build the server's Internet address
  541. bzero((char *) &dest_addr, sizeof(dest_addr));
  542. dest_addr.sin_family = AF_INET;
  543. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  544. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  545. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  546. {
  547. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  548. {
  549. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  550. }
  551. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  552. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  553. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  554. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  555. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  556. DEBUG_TTIA_INFO("---------- Header ----------\n");
  557. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  558. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  559. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  560. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  561. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  562. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  563. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  564. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  565. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  566. DEBUG_TTIA_INFO("Len: 0x3C\n");
  567. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  568. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  569. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  570. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  571. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  572. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  573. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  574. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  575. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  576. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  577. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  578. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  579. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  580. DEBUG_TTIA_INFO("=========================================\n");
  581. sn++;
  582. result = PASS;
  583. }
  584. else
  585. {
  586. DEBUG_ERROR("UDP sent out fail.\n");
  587. }
  588. }
  589. }
  590. return result;
  591. }
  592. //=========================================
  593. // Save configuration
  594. //=========================================
  595. int runShellCmd(const char*cmd)
  596. {
  597. int result = FAIL;
  598. char buf[256];
  599. FILE *fp;
  600. fp = popen(cmd, "r");
  601. if(fp != NULL)
  602. {
  603. while(fgets(buf, sizeof(buf), fp) != NULL)
  604. {
  605. DEBUG_INFO("%s\n", buf);
  606. }
  607. result = PASS;
  608. }
  609. pclose(fp);
  610. return result;
  611. }
  612. int StoreUsrConfigData(struct SysConfigData *UsrData)
  613. {
  614. int result = PASS;
  615. int fd,wrd;
  616. unsigned int i,Chk;
  617. unsigned char *ptr, *BufTmp;
  618. int MtdBlockSize = 0x300000;
  619. Chk=0;
  620. ptr=(unsigned char *)UsrData;
  621. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  622. {
  623. memset(BufTmp,0,MtdBlockSize);
  624. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  625. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  626. Chk+=*(BufTmp+i);
  627. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  628. // Output configuration to file.
  629. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  630. if (fd < 0)
  631. {
  632. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  633. free(BufTmp);
  634. return 0;
  635. }
  636. wrd=write(fd, BufTmp, MtdBlockSize);
  637. close(fd);
  638. if(wrd<MtdBlockSize)
  639. {
  640. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  641. free(BufTmp);
  642. return 0;
  643. }
  644. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  645. DEBUG_INFO("Erase /dev/mtd10.\n");
  646. runShellCmd("flash_erase /dev/mtd10 0 0");
  647. DEBUG_INFO("Write /dev/mtd10.\n");
  648. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  649. DEBUG_INFO("Erase /dev/mtd11.\n");
  650. runShellCmd("flash_erase /dev/mtd11 0 0");
  651. DEBUG_INFO("Write /dev/mtd11.\n");
  652. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  653. system("rm -f /mnt/EvseConfig.bin");
  654. DEBUG_INFO("EvseConfig write to flash OK\n");
  655. }
  656. else
  657. {
  658. DEBUG_ERROR("alloc BlockSize NG\r\n");
  659. result = FAIL;
  660. }
  661. if(BufTmp!=NULL)
  662. free(BufTmp);
  663. return result;
  664. }
  665. //=========================================
  666. // Sqlite3 related function
  667. //=========================================
  668. static int selectSqlCount = 0;
  669. static int callback(void *data, int argc, char **argv, char **azColName){
  670. int i;
  671. //printf("%s: ", (const char*)data);
  672. selectSqlCount = argc;
  673. for(i = 0; i<argc; i++){
  674. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  675. }
  676. //printf("\n");
  677. return 0;
  678. }
  679. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  680. //int i;
  681. //printf("%s:\n", (const char*)data);
  682. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  683. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  684. return 0;
  685. }
  686. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  687. //printf("%s:\n", (const char*)data);
  688. //idTag
  689. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  690. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  691. //parentIdTag
  692. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  693. //expir_date
  694. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  695. //status
  696. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  697. //version
  698. if(columenCount > 5)
  699. idTagQuery.listVersionInt = atoi(columnValue[5]);
  700. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  701. return 0;
  702. }
  703. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  704. {
  705. // localversion = argv[5] ? atoi(argv[5]) : 0;
  706. // printf("localversion=%d\n", localversion);
  707. return 0;
  708. }
  709. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  710. {
  711. for (int i = 0; i < n_columns; i++)
  712. {
  713. DEBUG_INFO("%s\t", col_values[i]);
  714. }
  715. DEBUG_INFO("\n");
  716. return 0;
  717. }
  718. int OCPP_cleanLocalCache()
  719. {
  720. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  721. char *errMsg = 0;
  722. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  723. if (SQLITE_OK != rc)
  724. {
  725. DEBUG_INFO("SQL error: %s\n",errMsg);
  726. return FALSE;
  727. }
  728. return TRUE;
  729. }
  730. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  731. {
  732. int isSuccess = TRUE;
  733. int ret = 0;
  734. //const char* data = "Callback function called";
  735. char sql[300];
  736. char zErrMsg[200];
  737. memset(sql, 0, 300);
  738. memset(zErrMsg, 0, 200);
  739. 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);
  740. //* Execute SQL statement */
  741. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  742. if( ret != SQLITE_OK )
  743. {
  744. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  745. isSuccess = FALSE;
  746. }
  747. return isSuccess;
  748. }
  749. void OCPP_getIdTagFromLocalCache(char idTag[])
  750. {
  751. int rc = 0;
  752. char sql[100];
  753. char zErrMsg[100];
  754. memset(sql, 0, 100);
  755. memset(zErrMsg, 0, 100);
  756. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  757. memset(&idTagQuery, 0, sizeof(idTagQuery));
  758. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  759. /* Execute SQL statement */
  760. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  761. if( rc != SQLITE_OK )
  762. {
  763. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  764. }
  765. }
  766. void OCPP_getListVerion()
  767. {
  768. int rc = 0;
  769. // const char* data = "Callback function called";
  770. char sql[100];
  771. char zErrMsg[100];
  772. memset(sql, 0, 100);
  773. memset(zErrMsg, 0, 100);
  774. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  775. /* Execute SQL statement */
  776. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  777. if( rc != SQLITE_OK )
  778. {
  779. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  780. }
  781. }
  782. void OCPP_get_TableAuthlocalAllData(void)
  783. {
  784. int rc = 0;
  785. char sql[100];
  786. char zErrMsg[100];
  787. memset(sql, 0, 100);
  788. memset(zErrMsg, 0, 100);
  789. sprintf(sql,"select * from ocpp_auth_local ");
  790. /* Execute SQL statement */
  791. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  792. if( rc != SQLITE_OK )
  793. {
  794. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  795. }
  796. //return ver;
  797. }
  798. int OCPP_cleanLocalList()
  799. {
  800. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  801. char *errMsg = 0;
  802. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  803. if (SQLITE_OK != rc)
  804. {
  805. DEBUG_INFO("%s\n",errMsg);
  806. return FALSE;
  807. }
  808. return TRUE;
  809. }
  810. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  811. {
  812. int isSuccess = FALSE;
  813. int ret = 0;
  814. //const char* data = "Callback function called";
  815. char sql[300];
  816. char zErrMsg[200];
  817. memset(sql, 0, 300);
  818. memset(zErrMsg, 0, 200);
  819. 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);
  820. //* Execute SQL statement */
  821. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  822. if( ret != SQLITE_OK )
  823. {
  824. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  825. return isSuccess;
  826. }
  827. memset(sql, 0, 300);
  828. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  829. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  830. if( ret != SQLITE_OK )
  831. {
  832. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  833. return isSuccess;
  834. }
  835. isSuccess = TRUE;
  836. return isSuccess;
  837. }
  838. void OCPP_getIdTagFromLocalList(char idTag[])
  839. {
  840. int rc = 0;
  841. // const char* data = "Callback function called";
  842. char sql[100];
  843. char zErrMsg[100];
  844. memset(sql, 0, 100);
  845. memset(zErrMsg, 0, 100);
  846. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  847. memset(&idTagQuery, 0, sizeof(idTagQuery));
  848. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  849. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  850. /* Execute SQL statement */
  851. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  852. if( rc != SQLITE_OK )
  853. {
  854. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  855. }
  856. //return ver;
  857. }
  858. void OCPP_deleteIdTagFromLocalList(char idTag[])
  859. {
  860. //int ver = 0;
  861. //int isSuccess = FALSE;
  862. int rc = 0;
  863. char sql[100];
  864. char zErrMsg[100];
  865. memset(sql, 0, 100);
  866. memset(zErrMsg, 0, 100);
  867. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  868. //* Execute SQL statement */
  869. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  870. if( rc != SQLITE_OK )
  871. {
  872. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  873. }
  874. }
  875. int getCurrentYear()
  876. {
  877. int result = 0;
  878. time_t CurrentTime;
  879. struct tm *tm;
  880. CurrentTime = time(NULL);
  881. tm=localtime(&CurrentTime);
  882. result = (tm->tm_year + 1900);
  883. return result;
  884. }
  885. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  886. {
  887. int result = PASS;
  888. char* errMsg = NULL;
  889. char sqlStr[8192];
  890. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  891. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  892. {
  893. result = FAIL;
  894. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  895. }
  896. 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));
  897. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  898. {
  899. result = FAIL;
  900. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  901. }
  902. return result;
  903. }
  904. //==========================================
  905. // Check time passed since today
  906. //==========================================
  907. long long DiffTimebWithNow(struct timeb ST)
  908. {
  909. //return milli-second
  910. struct timeb ET;
  911. long long StartTime,StopTime;
  912. ftime(&ET);
  913. StartTime=(long long)ST.time;
  914. StopTime=(long long)ET.time;
  915. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  916. }
  917. int getTimePassSinceToday(uint8_t gun_index)
  918. {
  919. int result = -1;
  920. static time_t lastTime[4];
  921. time_t t;
  922. struct tm *tmStartToday;
  923. struct timeb tbStartToday;
  924. t=time(NULL);
  925. if(difftime(t, lastTime[gun_index])>0)
  926. {
  927. tmStartToday=localtime(&t);
  928. tmStartToday->tm_hour = 0;
  929. tmStartToday->tm_min = 0;
  930. tmStartToday->tm_sec = 0;
  931. tbStartToday.time = mktime(tmStartToday);
  932. tbStartToday.millitm = 0;
  933. result = DiffTimebWithNow(tbStartToday)/1000;
  934. lastTime[gun_index] = t;
  935. }
  936. return result;
  937. }
  938. void getNowDatetime(uint8_t *data)
  939. {
  940. time_t t = time(NULL);
  941. struct tm tm = *localtime(&t);
  942. 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);
  943. }
  944. int syncDateTimeRTC(uint8_t *data)
  945. {
  946. struct ParsingResult
  947. {
  948. int result;
  949. int scanedElement;
  950. int year;
  951. int month;
  952. int mday;
  953. int hour;
  954. int min;
  955. int sec;
  956. int tz_hour;
  957. int tz_min;
  958. float minSec;
  959. }result;
  960. struct tm tmOrg;
  961. struct tm *tmTarget;
  962. struct timeb tbTarget;
  963. char buf[128];
  964. memset(&result, 0x00, sizeof(struct ParsingResult));
  965. result.result = PASS;
  966. if(strstr((char*)data, ".") != NULL)
  967. {
  968. // Original data with mini second
  969. if(strstr((char*)data, "Z") != NULL)
  970. {
  971. // Original data with Z
  972. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  973. &result.year,
  974. &result.month,
  975. &result.mday,
  976. &result.hour,
  977. &result.min,
  978. &result.sec,
  979. &result.minSec);
  980. }
  981. else
  982. {
  983. // Original data without Z
  984. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  985. &result.year,
  986. &result.month,
  987. &result.mday,
  988. &result.hour,
  989. &result.min,
  990. &result.sec,
  991. &result.minSec,
  992. &result.tz_hour,
  993. &result.tz_min);
  994. }
  995. }
  996. else
  997. {
  998. // Original data without mini second
  999. if(strstr((char*)data, "Z") != NULL)
  1000. {
  1001. // Original data with Z
  1002. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1003. &result.year,
  1004. &result.month,
  1005. &result.mday,
  1006. &result.hour,
  1007. &result.min,
  1008. &result.sec);
  1009. }
  1010. else
  1011. {
  1012. // Original data without Z
  1013. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1014. &result.year,
  1015. &result.month,
  1016. &result.mday,
  1017. &result.hour,
  1018. &result.min,
  1019. &result.sec,
  1020. &result.tz_hour,
  1021. &result.tz_min);
  1022. }
  1023. }
  1024. tmOrg.tm_year = result.year - 1900;
  1025. tmOrg.tm_mon = result.month - 1;
  1026. tmOrg.tm_mday = result.mday;
  1027. tmOrg.tm_hour = result.hour;
  1028. tmOrg.tm_min = result.min;
  1029. tmOrg.tm_sec = result.sec;
  1030. tmOrg.tm_gmtoff = 0;
  1031. tbTarget.time = mktime(&tmOrg);
  1032. tbTarget.timezone = 0;
  1033. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1034. tmTarget = gmtime(&tbTarget.time);
  1035. 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);
  1036. //DEBUG_INFO(" org date time: %s\n", data);
  1037. //DEBUG_INFO("parse date time: %s\n", buf);
  1038. system(buf);
  1039. system("/sbin/hwclock -w --systohc");
  1040. if(result.scanedElement < 6)
  1041. result.result = FAIL;
  1042. return result.result;
  1043. }
  1044. //==========================================
  1045. // GetCompositeSchedule logic related function
  1046. //==========================================
  1047. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1048. {
  1049. //return milli-second
  1050. unsigned int StartTime,StopTime;
  1051. StartTime=(unsigned int)ST.time;
  1052. StopTime=(unsigned int)ET.time;
  1053. return (StopTime-StartTime);
  1054. }
  1055. int DiffTimebWithNowSec(struct timeb ST)
  1056. {
  1057. //return milli-second
  1058. struct timeb ET;
  1059. unsigned int StartTime,StopTime;
  1060. ftime(&ET);
  1061. StartTime=(unsigned int)ST.time;
  1062. StopTime=(unsigned int)ET.time;
  1063. return (StopTime-StartTime);
  1064. }
  1065. int getStartStop(uint8_t *start, uint8_t *stop)
  1066. {
  1067. int result = -1;
  1068. struct tm tmStart;
  1069. struct timeb tbStart;
  1070. struct tm tmStop;
  1071. struct timeb tbStop;
  1072. 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) &&
  1073. (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))
  1074. {
  1075. //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);
  1076. //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);
  1077. tmStart.tm_year -= 1900;
  1078. tmStart.tm_mon -= 1;
  1079. tbStart.time = mktime(&tmStart);
  1080. tbStart.millitm = 0;
  1081. tmStop.tm_year -= 1900;
  1082. tmStop.tm_mon -= 1;
  1083. tbStop.time = mktime(&tmStop);
  1084. tbStop.millitm = 0;
  1085. result = DiffTimebSec(tbStart, tbStop);
  1086. //DEBUG_INFO("getStartStop(): %d\n", result);
  1087. }
  1088. else
  1089. {
  1090. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1091. }
  1092. return result;
  1093. }
  1094. int isOvertNow(uint8_t *start)
  1095. {
  1096. int result = NO;
  1097. struct ParsingResult
  1098. {
  1099. int result;
  1100. int scanedElement;
  1101. int year;
  1102. int month;
  1103. int mday;
  1104. int hour;
  1105. int min;
  1106. int sec;
  1107. int tz_hour;
  1108. int tz_min;
  1109. float minSec;
  1110. }parsingResult;
  1111. struct tm tmStart;
  1112. struct timeb tbStart;
  1113. if(strstr((char*)start, ".") != NULL)
  1114. {
  1115. // Original data with mini second
  1116. if(strstr((char*)start, "Z") != NULL)
  1117. {
  1118. // Original data with Z
  1119. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1120. &parsingResult.year,
  1121. &parsingResult.month,
  1122. &parsingResult.mday,
  1123. &parsingResult.hour,
  1124. &parsingResult.min,
  1125. &parsingResult.sec,
  1126. &parsingResult.minSec);
  1127. }
  1128. else
  1129. {
  1130. // Original data without Z
  1131. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1132. &parsingResult.year,
  1133. &parsingResult.month,
  1134. &parsingResult.mday,
  1135. &parsingResult.hour,
  1136. &parsingResult.min,
  1137. &parsingResult.sec,
  1138. &parsingResult.minSec,
  1139. &parsingResult.tz_hour,
  1140. &parsingResult.tz_min);
  1141. }
  1142. }
  1143. else
  1144. {
  1145. // Original data without mini second
  1146. if(strstr((char*)start, "Z") != NULL)
  1147. {
  1148. // Original data with Z
  1149. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1150. &parsingResult.year,
  1151. &parsingResult.month,
  1152. &parsingResult.mday,
  1153. &parsingResult.hour,
  1154. &parsingResult.min,
  1155. &parsingResult.sec);
  1156. }
  1157. else
  1158. {
  1159. // Original data without Z
  1160. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1161. &parsingResult.year,
  1162. &parsingResult.month,
  1163. &parsingResult.mday,
  1164. &parsingResult.hour,
  1165. &parsingResult.min,
  1166. &parsingResult.sec,
  1167. &parsingResult.tz_hour,
  1168. &parsingResult.tz_min);
  1169. }
  1170. }
  1171. if(parsingResult.scanedElement >= 6)
  1172. {
  1173. tmStart.tm_year = parsingResult.year - 1900;
  1174. tmStart.tm_mon = parsingResult.month - 1;
  1175. tmStart.tm_mday = parsingResult.mday;
  1176. tmStart.tm_hour = parsingResult.hour;
  1177. tmStart.tm_min = parsingResult.min;
  1178. tmStart.tm_sec = parsingResult.sec;
  1179. tmStart.tm_gmtoff = 0;
  1180. tbStart.time = mktime(&tmStart);
  1181. tbStart.timezone = 0;
  1182. tbStart.millitm = 0;
  1183. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1184. if(DiffTimebWithNowSec(tbStart) <= 0)
  1185. result = NO;
  1186. else
  1187. result = YES;
  1188. }
  1189. else
  1190. {
  1191. DEBUG_WARN("Start date parsing error.\n");
  1192. }
  1193. return result;
  1194. }
  1195. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1196. {
  1197. int result = -1;
  1198. struct tm tmStart;
  1199. struct timeb tbStart;
  1200. struct tm tmStop;
  1201. struct timeb tbStop;
  1202. 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) &&
  1203. (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))
  1204. {
  1205. tmStart.tm_year -= 1900;
  1206. tmStart.tm_mon -= 1;
  1207. tbStart.time = mktime(&tmStart);
  1208. tbStart.millitm = 0;
  1209. tmStop.tm_year -= 1900;
  1210. tmStop.tm_mon -= 1;
  1211. tbStop.time = mktime(&tmStop);
  1212. tbStop.millitm = 0;
  1213. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1214. }
  1215. return result;
  1216. }
  1217. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1218. {
  1219. FILE *fp;
  1220. char profileFileName[128];
  1221. char *line = NULL;
  1222. size_t len = 0;
  1223. time_t CurrentTime;
  1224. struct tm *tmComposite;
  1225. struct StructChargingProfile maxProfile;
  1226. uint8_t limitMax=0;
  1227. int compositePeriodIdx = 0;
  1228. CurrentTime = time(NULL);
  1229. tmComposite=localtime(&CurrentTime);
  1230. 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);
  1231. if(isUnitA)
  1232. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1233. else
  1234. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1235. compositeProfile->ChargingSchedule.Duration = durationReq;
  1236. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1237. {
  1238. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1239. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1240. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1241. }
  1242. compositeProfile->ChargingProfileId = 0;
  1243. compositeProfile->StackLevel = 99 ;
  1244. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1245. maxProfile.ChargingProfileId = -1;
  1246. maxProfile.ChargingSchedule.Duration = -1;
  1247. system("rm -f /tmp/*.json");
  1248. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1249. // Search max profile
  1250. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1251. if((access(profileFileName, F_OK))!=-1)
  1252. {
  1253. fp = fopen(profileFileName, "r");
  1254. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1255. {
  1256. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1257. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1258. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1259. }
  1260. maxProfile.ChargingProfileId = -1;
  1261. maxProfile.StackLevel = -1;
  1262. while(getline(&line, &len, fp) != -1)
  1263. {
  1264. json_object *obj = NULL;
  1265. obj = json_tokener_parse(line);
  1266. if(is_error(obj))
  1267. {
  1268. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1269. }
  1270. else
  1271. {
  1272. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1273. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1274. )
  1275. {
  1276. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1277. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1278. )
  1279. {
  1280. struct tm tmFrom, tmTo;
  1281. struct timeb tbFrom, tbTo;
  1282. 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) &&
  1283. (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))
  1284. {
  1285. tmFrom.tm_year -= 1900;
  1286. tmFrom.tm_mon -= 1;
  1287. tbFrom.time = mktime(&tmFrom);
  1288. tmTo.tm_year -= 1900;
  1289. tmTo.tm_mon -= 1;
  1290. tbTo.time = mktime(&tmTo);
  1291. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1292. {
  1293. if(maxProfile.ChargingProfileId == -1)
  1294. DEBUG_INFO("MaxProfile found.\n");
  1295. else
  1296. DEBUG_INFO("MaxProfile updated.\n");
  1297. // Required item
  1298. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1299. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1300. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1301. if(isUnitA)
  1302. {
  1303. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1304. 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++)
  1305. {
  1306. 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"));
  1307. 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?
  1308. 3:
  1309. 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")));
  1310. 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")));
  1311. }
  1312. }
  1313. else
  1314. {
  1315. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1316. 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++)
  1317. {
  1318. 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"));
  1319. 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?
  1320. 3:
  1321. 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")));
  1322. 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));
  1323. }
  1324. }
  1325. // Optional item
  1326. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1327. {
  1328. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1329. }
  1330. else
  1331. {
  1332. sprintf((char*)maxProfile.ValidFrom, " ");
  1333. }
  1334. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1335. {
  1336. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1337. }
  1338. else
  1339. {
  1340. sprintf((char*)maxProfile.ValidTo, " ");
  1341. }
  1342. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1343. {
  1344. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1345. }
  1346. else
  1347. {
  1348. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1349. }
  1350. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1351. {
  1352. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1353. }
  1354. else
  1355. {
  1356. maxProfile.TransactionId = -1;
  1357. }
  1358. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1359. {
  1360. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1361. }
  1362. else
  1363. {
  1364. maxProfile.ChargingSchedule.Duration = 86400;
  1365. }
  1366. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1367. {
  1368. 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")));
  1369. }
  1370. else
  1371. {
  1372. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1373. }
  1374. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1375. {
  1376. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1377. }
  1378. else
  1379. {
  1380. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1381. }
  1382. }
  1383. }
  1384. }
  1385. else
  1386. {
  1387. if(maxProfile.ChargingProfileId == -1)
  1388. DEBUG_INFO("MaxProfile found.\n");
  1389. else
  1390. DEBUG_INFO("MaxProfile updated.\n");
  1391. // Required item
  1392. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1393. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1394. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1395. if(isUnitA)
  1396. {
  1397. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1398. 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++)
  1399. {
  1400. 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"));
  1401. 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?
  1402. 3:
  1403. 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")));
  1404. 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")));
  1405. }
  1406. }
  1407. else
  1408. {
  1409. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1410. 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++)
  1411. {
  1412. 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"));
  1413. 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?
  1414. 3:
  1415. 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")));
  1416. 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));
  1417. }
  1418. }
  1419. // Optional item
  1420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1421. {
  1422. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1423. }
  1424. else
  1425. {
  1426. sprintf((char*)maxProfile.ValidFrom, " ");
  1427. }
  1428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1429. {
  1430. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1431. }
  1432. else
  1433. {
  1434. sprintf((char*)maxProfile.ValidTo, " ");
  1435. }
  1436. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1437. {
  1438. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1439. }
  1440. else
  1441. {
  1442. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1443. }
  1444. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1445. {
  1446. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1447. }
  1448. else
  1449. {
  1450. maxProfile.TransactionId = -1;
  1451. }
  1452. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1453. {
  1454. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1455. }
  1456. else
  1457. {
  1458. maxProfile.ChargingSchedule.Duration = 86400;
  1459. }
  1460. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1461. {
  1462. 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")));
  1463. }
  1464. else
  1465. {
  1466. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1467. }
  1468. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1469. {
  1470. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1471. }
  1472. else
  1473. {
  1474. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. json_object_put(obj);
  1480. }
  1481. fclose(fp);
  1482. /*
  1483. if(maxProfile.ChargingProfileId !=-1)
  1484. {
  1485. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1486. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1487. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1488. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1489. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1490. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1491. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1492. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1493. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1494. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1495. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1497. {
  1498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1499. {
  1500. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1501. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1502. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1503. }
  1504. }
  1505. }
  1506. else
  1507. DEBUG_INFO("MaxProfile not found.\n");
  1508. DEBUG_INFO("------------------------------------\n");*/
  1509. }
  1510. if(maxProfile.ChargingProfileId != -1)
  1511. {
  1512. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1513. {
  1514. if(maxProfile.ChargingSchedule.Duration != -1)
  1515. {
  1516. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1517. 0:
  1518. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1519. }
  1520. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1521. {
  1522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1523. {
  1524. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1525. 0:
  1526. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1527. if(idxPeriod > 0)
  1528. {
  1529. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1530. {
  1531. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1532. }
  1533. }
  1534. }
  1535. }
  1536. }
  1537. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1538. {
  1539. if(maxProfile.ChargingSchedule.Duration != -1)
  1540. {
  1541. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1542. }
  1543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1544. {
  1545. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1546. {
  1547. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1548. if(idxPeriod > 0)
  1549. {
  1550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1551. {
  1552. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1553. }
  1554. }
  1555. }
  1556. }
  1557. }
  1558. else
  1559. {
  1560. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1561. {
  1562. if(maxProfile.ChargingSchedule.Duration != -1)
  1563. {
  1564. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1565. 0:
  1566. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1567. }
  1568. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1569. {
  1570. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1571. {
  1572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1573. 0:
  1574. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1575. if(idxPeriod > 0)
  1576. {
  1577. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1578. {
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. if(maxProfile.ChargingSchedule.Duration != -1)
  1588. {
  1589. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1590. 0:
  1591. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1592. }
  1593. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1594. {
  1595. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1596. {
  1597. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1598. 0:
  1599. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1600. if(idxPeriod > 0)
  1601. {
  1602. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1603. {
  1604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. }
  1611. /*
  1612. DEBUG_INFO("MaxProfile after align.\n");
  1613. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1614. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1615. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1616. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1617. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1618. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1619. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1620. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1621. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1622. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1623. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1625. {
  1626. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1627. {
  1628. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1629. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1630. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1631. }
  1632. }
  1633. DEBUG_INFO("------------------------------------\n");*/
  1634. }
  1635. // Find each profile period quantity
  1636. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1637. {
  1638. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1639. limitMax = idx+1;
  1640. }
  1641. if(maxProfile.ChargingProfileId != -1)
  1642. {
  1643. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1644. {
  1645. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1646. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1647. (maxProfile.ChargingSchedule.Duration > 0))
  1648. {
  1649. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1650. {
  1651. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1652. compositePeriodIdx++;
  1653. }
  1654. else
  1655. {
  1656. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1657. }
  1658. }
  1659. }
  1660. }
  1661. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1662. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1663. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1664. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1665. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1666. {
  1667. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1668. {
  1669. compositeProfile->ChargingProfileId = 1;
  1670. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1671. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1672. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1673. }
  1674. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1675. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1676. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1677. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1678. }
  1679. if(line)
  1680. free(line);
  1681. }
  1682. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1683. {
  1684. FILE *fp;
  1685. char profileFileName[128];
  1686. char *line = NULL;
  1687. size_t len = 0;
  1688. time_t CurrentTime;
  1689. struct tm *tmComposite;
  1690. struct StructChargingProfile maxProfile;
  1691. struct StructChargingProfile defaultTxProfile;
  1692. struct StructChargingProfile txProfile;
  1693. struct StructChargingSchedulePeriod tmpPeriod;
  1694. uint8_t limitMax=0;
  1695. uint8_t limitDef=0;
  1696. uint8_t limitTx=0;
  1697. int compositePeriodIdx = 0;
  1698. CurrentTime = time(NULL);
  1699. tmComposite=localtime(&CurrentTime);
  1700. 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);
  1701. if(isUnitA)
  1702. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1703. else
  1704. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1705. compositeProfile->ChargingSchedule.Duration = durationReq;
  1706. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1707. {
  1708. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1709. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1710. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1711. }
  1712. compositeProfile->ChargingProfileId = 0;
  1713. compositeProfile->StackLevel = 99 ;
  1714. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1715. maxProfile.ChargingProfileId = -1;
  1716. defaultTxProfile.ChargingProfileId = -1;
  1717. txProfile.ChargingProfileId = -1;
  1718. maxProfile.ChargingSchedule.Duration = -1;
  1719. defaultTxProfile.ChargingSchedule.Duration = -1;
  1720. txProfile.ChargingSchedule.Duration = -1;
  1721. system("rm -f /tmp/*.json");
  1722. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1723. /*
  1724. * Search valid charging profile
  1725. */
  1726. //DEBUG_INFO("====================================\n");
  1727. // Search tx profile
  1728. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1729. if((access(profileFileName, F_OK))!=-1)
  1730. {
  1731. fp = fopen(profileFileName, "r");
  1732. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1733. {
  1734. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1735. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1736. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1737. }
  1738. txProfile.ChargingProfileId = -1;
  1739. txProfile.StackLevel = -1;
  1740. while(getline(&line, &len, fp) != -1)
  1741. {
  1742. json_object *obj = NULL;
  1743. obj = json_tokener_parse(line);
  1744. if(is_error(obj))
  1745. {
  1746. DEBUG_ERROR("Parse txProfile from file error.\n");
  1747. }
  1748. else
  1749. {
  1750. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1751. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1752. )
  1753. {
  1754. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1755. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1756. )
  1757. {
  1758. struct tm tmFrom, tmTo;
  1759. struct timeb tbFrom, tbTo;
  1760. 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) &&
  1761. (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))
  1762. {
  1763. tmFrom.tm_year -= 1900;
  1764. tmFrom.tm_mon -= 1;
  1765. tbFrom.time = mktime(&tmFrom);
  1766. tmTo.tm_year -= 1900;
  1767. tmTo.tm_mon -= 1;
  1768. tbTo.time = mktime(&tmTo);
  1769. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1770. {
  1771. if(txProfile.ChargingProfileId == -1)
  1772. DEBUG_INFO("TxProfile found.\n");
  1773. else
  1774. DEBUG_INFO("TxProfile updated.\n");
  1775. // Required item
  1776. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1777. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1778. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1779. if(isUnitA)
  1780. {
  1781. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1782. 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++)
  1783. {
  1784. 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"));
  1785. 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?
  1786. 3:
  1787. 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")));
  1788. 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")));
  1789. }
  1790. }
  1791. else
  1792. {
  1793. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1794. 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++)
  1795. {
  1796. 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"));
  1797. 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?
  1798. 3:
  1799. 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")));
  1800. 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));
  1801. }
  1802. }
  1803. // Optional item
  1804. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1805. {
  1806. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1807. }
  1808. else
  1809. {
  1810. sprintf((char*)txProfile.ValidFrom, " ");
  1811. }
  1812. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1813. {
  1814. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1815. }
  1816. else
  1817. {
  1818. sprintf((char*)txProfile.ValidTo, " ");
  1819. }
  1820. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1821. {
  1822. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1823. }
  1824. else
  1825. {
  1826. sprintf((char*)txProfile.RecurrencyKind, " ");
  1827. }
  1828. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1829. {
  1830. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1831. }
  1832. else
  1833. {
  1834. txProfile.TransactionId = -1;
  1835. }
  1836. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1837. {
  1838. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1839. }
  1840. else
  1841. {
  1842. txProfile.ChargingSchedule.Duration = 86400;
  1843. }
  1844. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1845. {
  1846. 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")));
  1847. }
  1848. else
  1849. {
  1850. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1851. }
  1852. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1853. {
  1854. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1855. }
  1856. else
  1857. {
  1858. txProfile.ChargingSchedule.MinChargingRate = -1;
  1859. }
  1860. }
  1861. }
  1862. }
  1863. else
  1864. {
  1865. if(txProfile.ChargingProfileId == -1)
  1866. DEBUG_INFO("TxProfile found.\n");
  1867. else
  1868. DEBUG_INFO("TxProfile updated.\n");
  1869. // Required item
  1870. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1871. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1872. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1873. if(isUnitA)
  1874. {
  1875. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1876. 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++)
  1877. {
  1878. 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"));
  1879. 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?
  1880. 3:
  1881. 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")));
  1882. 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")));
  1883. }
  1884. }
  1885. else
  1886. {
  1887. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1888. 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++)
  1889. {
  1890. 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"));
  1891. 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?
  1892. 3:
  1893. 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")));
  1894. 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));
  1895. }
  1896. }
  1897. // Optional item
  1898. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1899. {
  1900. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1901. }
  1902. else
  1903. {
  1904. sprintf((char*)txProfile.ValidFrom, " ");
  1905. }
  1906. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1907. {
  1908. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1909. }
  1910. else
  1911. {
  1912. sprintf((char*)txProfile.ValidTo, " ");
  1913. }
  1914. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1915. {
  1916. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1917. }
  1918. else
  1919. {
  1920. sprintf((char*)txProfile.RecurrencyKind, " ");
  1921. }
  1922. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1923. {
  1924. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1925. }
  1926. else
  1927. {
  1928. txProfile.TransactionId = -1;
  1929. }
  1930. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1931. {
  1932. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1933. }
  1934. else
  1935. {
  1936. txProfile.ChargingSchedule.Duration = 86400;
  1937. }
  1938. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1939. {
  1940. 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")));
  1941. }
  1942. else
  1943. {
  1944. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1945. }
  1946. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1947. {
  1948. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1949. }
  1950. else
  1951. {
  1952. txProfile.ChargingSchedule.MinChargingRate = -1;
  1953. }
  1954. }
  1955. }
  1956. }
  1957. json_object_put(obj);
  1958. }
  1959. fclose(fp);
  1960. /*
  1961. if(txProfile.ChargingProfileId != -1)
  1962. {
  1963. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1964. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1965. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1966. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1967. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1968. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1969. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1970. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1971. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1972. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1973. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1974. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1975. {
  1976. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1977. {
  1978. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1979. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1980. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1981. }
  1982. }
  1983. }
  1984. else
  1985. DEBUG_INFO("TxProfile not found.\n");*/
  1986. }
  1987. // Search default tx profile
  1988. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1989. if((access(profileFileName, F_OK))==-1)
  1990. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1991. if((access(profileFileName, F_OK))!=-1)
  1992. {
  1993. fp = fopen(profileFileName, "r");
  1994. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1995. {
  1996. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1997. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1998. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1999. }
  2000. defaultTxProfile.ChargingProfileId = -1;
  2001. defaultTxProfile.StackLevel = -1;
  2002. while(getline(&line, &len, fp) != -1)
  2003. {
  2004. json_object *obj = NULL;
  2005. obj = json_tokener_parse(line);
  2006. if(is_error(obj))
  2007. {
  2008. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2009. }
  2010. else
  2011. {
  2012. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2013. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2014. )
  2015. {
  2016. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2017. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2018. )
  2019. {
  2020. struct tm tmFrom, tmTo;
  2021. struct timeb tbFrom, tbTo;
  2022. 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) &&
  2023. (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))
  2024. {
  2025. tmFrom.tm_year -= 1900;
  2026. tmFrom.tm_mon -= 1;
  2027. tbFrom.time = mktime(&tmFrom);
  2028. tmTo.tm_year -= 1900;
  2029. tmTo.tm_mon -= 1;
  2030. tbTo.time = mktime(&tmTo);
  2031. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2032. {
  2033. if(defaultTxProfile.ChargingProfileId == -1)
  2034. DEBUG_INFO("TxDefaultProfile found.\n");
  2035. else
  2036. DEBUG_INFO("TxDefaultProfile updated.\n");
  2037. // Required item
  2038. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2039. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2040. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2041. if(isUnitA)
  2042. {
  2043. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2044. 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++)
  2045. {
  2046. 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"));
  2047. 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?
  2048. 3:
  2049. 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")));
  2050. 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")));
  2051. }
  2052. }
  2053. else
  2054. {
  2055. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2056. 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++)
  2057. {
  2058. 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"));
  2059. 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?
  2060. 3:
  2061. 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")));
  2062. 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));
  2063. }
  2064. }
  2065. // Optional item
  2066. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2067. {
  2068. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2069. }
  2070. else
  2071. {
  2072. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2073. }
  2074. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2075. {
  2076. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2077. }
  2078. else
  2079. {
  2080. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2081. }
  2082. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2083. {
  2084. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2085. }
  2086. else
  2087. {
  2088. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2089. }
  2090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2091. {
  2092. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2093. }
  2094. else
  2095. {
  2096. defaultTxProfile.TransactionId = -1;
  2097. }
  2098. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2099. {
  2100. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2101. }
  2102. else
  2103. {
  2104. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2105. }
  2106. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2107. {
  2108. 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")));
  2109. }
  2110. else
  2111. {
  2112. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2113. }
  2114. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2115. {
  2116. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2117. }
  2118. else
  2119. {
  2120. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2121. }
  2122. }
  2123. }
  2124. }
  2125. else
  2126. {
  2127. if(defaultTxProfile.ChargingProfileId == -1)
  2128. DEBUG_INFO("TxDefaultProfile found.\n");
  2129. else
  2130. DEBUG_INFO("TxDefaultProfile updated.\n");
  2131. // Required item
  2132. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2133. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2134. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2135. if(isUnitA)
  2136. {
  2137. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2138. 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++)
  2139. {
  2140. 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"));
  2141. 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?
  2142. 3:
  2143. 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")));
  2144. 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")));
  2145. }
  2146. }
  2147. else
  2148. {
  2149. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2150. 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++)
  2151. {
  2152. 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"));
  2153. 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?
  2154. 3:
  2155. 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")));
  2156. 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));
  2157. }
  2158. }
  2159. // Optional item
  2160. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2161. {
  2162. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2163. }
  2164. else
  2165. {
  2166. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2167. }
  2168. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2169. {
  2170. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2171. }
  2172. else
  2173. {
  2174. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2175. }
  2176. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2177. {
  2178. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2179. }
  2180. else
  2181. {
  2182. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2183. }
  2184. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2185. {
  2186. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2187. }
  2188. else
  2189. {
  2190. defaultTxProfile.TransactionId = -1;
  2191. }
  2192. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2193. {
  2194. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2195. }
  2196. else
  2197. {
  2198. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2199. }
  2200. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2201. {
  2202. 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")));
  2203. }
  2204. else
  2205. {
  2206. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2207. }
  2208. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2209. {
  2210. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2211. }
  2212. else
  2213. {
  2214. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2215. }
  2216. }
  2217. }
  2218. }
  2219. json_object_put(obj);
  2220. }
  2221. fclose(fp);
  2222. /*
  2223. if(defaultTxProfile.ChargingProfileId != -1)
  2224. {
  2225. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2226. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2227. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2228. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2229. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2230. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2231. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2232. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2233. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2234. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2235. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2236. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2237. {
  2238. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2239. {
  2240. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2241. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2242. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2243. }
  2244. }
  2245. }
  2246. else
  2247. DEBUG_INFO("TxDefaultProfile not found.\n");
  2248. DEBUG_INFO("------------------------------------\n");*/
  2249. }
  2250. // Search max profile
  2251. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2252. if((access(profileFileName, F_OK))!=-1)
  2253. {
  2254. fp = fopen(profileFileName, "r");
  2255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2256. {
  2257. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2258. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2259. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2260. }
  2261. maxProfile.ChargingProfileId = -1;
  2262. maxProfile.StackLevel = -1;
  2263. while(getline(&line, &len, fp) != -1)
  2264. {
  2265. json_object *obj = NULL;
  2266. obj = json_tokener_parse(line);
  2267. if(is_error(obj))
  2268. {
  2269. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2270. }
  2271. else
  2272. {
  2273. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2274. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2275. )
  2276. {
  2277. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2278. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2279. )
  2280. {
  2281. struct tm tmFrom, tmTo;
  2282. struct timeb tbFrom, tbTo;
  2283. 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) &&
  2284. (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))
  2285. {
  2286. tmFrom.tm_year -= 1900;
  2287. tmFrom.tm_mon -= 1;
  2288. tbFrom.time = mktime(&tmFrom);
  2289. tmTo.tm_year -= 1900;
  2290. tmTo.tm_mon -= 1;
  2291. tbTo.time = mktime(&tmTo);
  2292. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2293. {
  2294. if(maxProfile.ChargingProfileId == -1)
  2295. DEBUG_INFO("MaxProfile found.\n");
  2296. else
  2297. DEBUG_INFO("MaxProfile updated.\n");
  2298. // Required item
  2299. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2300. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2301. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2302. if(isUnitA)
  2303. {
  2304. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2305. 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++)
  2306. {
  2307. 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"));
  2308. 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?
  2309. 3:
  2310. 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")));
  2311. 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")));
  2312. }
  2313. }
  2314. else
  2315. {
  2316. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2317. 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++)
  2318. {
  2319. 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"));
  2320. 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?
  2321. 3:
  2322. 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")));
  2323. 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));
  2324. }
  2325. }
  2326. // Optional item
  2327. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2328. {
  2329. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2330. }
  2331. else
  2332. {
  2333. sprintf((char*)maxProfile.ValidFrom, " ");
  2334. }
  2335. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2336. {
  2337. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2338. }
  2339. else
  2340. {
  2341. sprintf((char*)maxProfile.ValidTo, " ");
  2342. }
  2343. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2344. {
  2345. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2346. }
  2347. else
  2348. {
  2349. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2350. }
  2351. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2352. {
  2353. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2354. }
  2355. else
  2356. {
  2357. maxProfile.TransactionId = -1;
  2358. }
  2359. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2360. {
  2361. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2362. }
  2363. else
  2364. {
  2365. maxProfile.ChargingSchedule.Duration = 86400;
  2366. }
  2367. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2368. {
  2369. 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")));
  2370. }
  2371. else
  2372. {
  2373. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2374. }
  2375. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2376. {
  2377. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2378. }
  2379. else
  2380. {
  2381. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2382. }
  2383. }
  2384. }
  2385. }
  2386. else
  2387. {
  2388. if(maxProfile.ChargingProfileId == -1)
  2389. DEBUG_INFO("MaxProfile found.\n");
  2390. else
  2391. DEBUG_INFO("MaxProfile updated.\n");
  2392. // Required item
  2393. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2394. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2395. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2396. if(isUnitA)
  2397. {
  2398. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2399. 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++)
  2400. {
  2401. 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"));
  2402. 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?
  2403. 3:
  2404. 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")));
  2405. 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")));
  2406. }
  2407. }
  2408. else
  2409. {
  2410. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2411. 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++)
  2412. {
  2413. 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"));
  2414. 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?
  2415. 3:
  2416. 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")));
  2417. 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));
  2418. }
  2419. }
  2420. // Optional item
  2421. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2422. {
  2423. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2424. }
  2425. else
  2426. {
  2427. sprintf((char*)maxProfile.ValidFrom, " ");
  2428. }
  2429. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2430. {
  2431. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2432. }
  2433. else
  2434. {
  2435. sprintf((char*)maxProfile.ValidTo, " ");
  2436. }
  2437. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2438. {
  2439. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2440. }
  2441. else
  2442. {
  2443. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2444. }
  2445. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2446. {
  2447. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2448. }
  2449. else
  2450. {
  2451. maxProfile.TransactionId = -1;
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2454. {
  2455. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2456. }
  2457. else
  2458. {
  2459. maxProfile.ChargingSchedule.Duration = 86400;
  2460. }
  2461. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2462. {
  2463. 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")));
  2464. }
  2465. else
  2466. {
  2467. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2468. }
  2469. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2470. {
  2471. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2472. }
  2473. else
  2474. {
  2475. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2476. }
  2477. }
  2478. }
  2479. }
  2480. json_object_put(obj);
  2481. }
  2482. fclose(fp);
  2483. /*
  2484. if(maxProfile.ChargingProfileId !=-1)
  2485. {
  2486. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2487. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2488. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2489. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2490. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2491. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2492. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2493. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2494. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2495. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2496. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2497. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2498. {
  2499. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2500. {
  2501. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2502. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2503. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2504. }
  2505. }
  2506. }
  2507. else
  2508. DEBUG_INFO("MaxProfile not found.\n");
  2509. DEBUG_INFO("------------------------------------\n");*/
  2510. }
  2511. /*
  2512. * Align found profile start schedule & periods
  2513. */
  2514. //DEBUG_INFO("====================================\n");
  2515. /*
  2516. // For local test usage, force modify found profile start schedule info
  2517. 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);
  2518. 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);
  2519. 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);
  2520. */
  2521. if(txProfile.ChargingProfileId != -1)
  2522. {
  2523. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2524. {
  2525. if(txProfile.ChargingSchedule.Duration != -1)
  2526. {
  2527. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2528. 0:
  2529. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2530. }
  2531. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2532. {
  2533. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2534. {
  2535. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2536. 0:
  2537. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2538. if(idxPeriod > 0)
  2539. {
  2540. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2541. {
  2542. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2543. }
  2544. }
  2545. }
  2546. }
  2547. }
  2548. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2549. {
  2550. if(txProfile.ChargingSchedule.Duration != -1)
  2551. {
  2552. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2553. 0:
  2554. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2555. }
  2556. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2557. {
  2558. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2559. {
  2560. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2561. 0:
  2562. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2563. if(idxPeriod > 0)
  2564. {
  2565. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2566. {
  2567. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2568. }
  2569. }
  2570. }
  2571. }
  2572. }
  2573. else
  2574. {
  2575. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2576. {
  2577. if(txProfile.ChargingSchedule.Duration != -1)
  2578. {
  2579. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2580. 0:
  2581. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2582. }
  2583. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2584. {
  2585. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2586. {
  2587. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2588. 0:
  2589. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2590. if(idxPeriod > 0)
  2591. {
  2592. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2593. {
  2594. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2595. }
  2596. }
  2597. }
  2598. }
  2599. }
  2600. else
  2601. {
  2602. if(txProfile.ChargingSchedule.Duration != -1)
  2603. {
  2604. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2605. 0:
  2606. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2607. }
  2608. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2609. {
  2610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2611. {
  2612. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2613. 0:
  2614. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2615. if(idxPeriod > 0)
  2616. {
  2617. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2618. {
  2619. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. }
  2626. /*
  2627. DEBUG_INFO("txProfile after align.\n");
  2628. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2629. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2630. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2631. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2632. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2633. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2634. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2635. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2636. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2637. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2638. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2639. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2640. {
  2641. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2642. {
  2643. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2644. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2645. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2646. }
  2647. }*/
  2648. }
  2649. if(defaultTxProfile.ChargingProfileId != -1)
  2650. {
  2651. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2652. {
  2653. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2654. {
  2655. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2656. 0:
  2657. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2658. }
  2659. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2660. {
  2661. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2662. {
  2663. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2664. 0:
  2665. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2666. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2667. {
  2668. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2669. }
  2670. if(idxPeriod > 0)
  2671. {
  2672. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2673. {
  2674. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2681. {
  2682. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2683. {
  2684. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2685. 0:
  2686. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2687. }
  2688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2689. {
  2690. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2691. {
  2692. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2693. 0:
  2694. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2695. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2696. {
  2697. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2698. }
  2699. if(idxPeriod > 0)
  2700. {
  2701. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2702. {
  2703. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2704. }
  2705. }
  2706. }
  2707. }
  2708. }
  2709. else
  2710. {
  2711. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2712. {
  2713. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2714. {
  2715. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2716. 0:
  2717. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2718. }
  2719. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2720. {
  2721. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2722. {
  2723. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2724. 0:
  2725. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2726. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2727. {
  2728. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2729. }
  2730. if(idxPeriod > 0)
  2731. {
  2732. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2733. {
  2734. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2735. }
  2736. }
  2737. }
  2738. }
  2739. }
  2740. else
  2741. {
  2742. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2743. {
  2744. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2745. 0:
  2746. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2747. }
  2748. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2749. {
  2750. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2751. {
  2752. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2753. 0:
  2754. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2755. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2756. {
  2757. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2758. }
  2759. if(idxPeriod > 0)
  2760. {
  2761. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2762. {
  2763. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2764. }
  2765. }
  2766. }
  2767. }
  2768. }
  2769. }
  2770. /*
  2771. DEBUG_INFO("defaultTxProfile after align.\n");
  2772. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2773. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2774. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2775. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2776. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2777. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2778. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2779. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2780. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2781. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2782. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2783. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2784. {
  2785. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2786. {
  2787. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2788. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2789. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2790. }
  2791. }
  2792. DEBUG_INFO("------------------------------------\n");*/
  2793. }
  2794. if(maxProfile.ChargingProfileId != -1)
  2795. {
  2796. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2797. {
  2798. if(maxProfile.ChargingSchedule.Duration != -1)
  2799. {
  2800. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2801. 0:
  2802. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2803. }
  2804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2805. {
  2806. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2807. {
  2808. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2809. 0:
  2810. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2811. if(idxPeriod > 0)
  2812. {
  2813. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2814. {
  2815. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2822. {
  2823. if(maxProfile.ChargingSchedule.Duration != -1)
  2824. {
  2825. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2826. 0:
  2827. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2828. }
  2829. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2830. {
  2831. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2832. {
  2833. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2834. 0:
  2835. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2836. if(idxPeriod > 0)
  2837. {
  2838. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2839. {
  2840. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2841. }
  2842. }
  2843. }
  2844. }
  2845. }
  2846. else
  2847. {
  2848. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2849. {
  2850. if(maxProfile.ChargingSchedule.Duration != -1)
  2851. {
  2852. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2853. 0:
  2854. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2855. }
  2856. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2857. {
  2858. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2859. {
  2860. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2861. 0:
  2862. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2863. if(idxPeriod > 0)
  2864. {
  2865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2866. {
  2867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2868. }
  2869. }
  2870. }
  2871. }
  2872. }
  2873. else
  2874. {
  2875. if(maxProfile.ChargingSchedule.Duration != -1)
  2876. {
  2877. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2878. 0:
  2879. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2880. }
  2881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2882. {
  2883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2884. {
  2885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2886. 0:
  2887. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2888. if(idxPeriod > 0)
  2889. {
  2890. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2891. {
  2892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2893. }
  2894. }
  2895. }
  2896. }
  2897. }
  2898. }
  2899. /*
  2900. DEBUG_INFO("MaxProfile after align.\n");
  2901. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2902. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2903. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2904. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2905. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2906. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2907. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2908. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2909. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2910. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2911. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2912. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2913. {
  2914. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2915. {
  2916. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2917. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2918. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2919. }
  2920. }
  2921. DEBUG_INFO("------------------------------------\n");*/
  2922. }
  2923. /*
  2924. * Merge to conposite schedule
  2925. */
  2926. //DEBUG_INFO("====================================\n");
  2927. // Find each profile period quantity
  2928. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2929. {
  2930. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2931. limitMax = idx+1;
  2932. }
  2933. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2934. {
  2935. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2936. limitDef = idx+1;
  2937. }
  2938. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2939. {
  2940. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2941. limitTx = idx+1;
  2942. }
  2943. // TxProfile found, composite schedule based on it
  2944. if(txProfile.ChargingProfileId != -1)
  2945. {
  2946. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2947. {
  2948. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2949. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2950. (txProfile.ChargingSchedule.Duration > 0))
  2951. {
  2952. if(maxProfile.ChargingProfileId != -1)
  2953. {
  2954. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2955. {
  2956. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2957. {
  2958. if((maxProfile.ChargingSchedule.Duration > 0))
  2959. {
  2960. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2961. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2962. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2963. }
  2964. else
  2965. {
  2966. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2967. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2968. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2969. }
  2970. }
  2971. if(idxMaxPeriod == (limitMax-1))
  2972. {
  2973. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2974. {
  2975. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2976. {
  2977. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2978. compositePeriodIdx++;
  2979. }
  2980. else
  2981. {
  2982. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2983. }
  2984. }
  2985. }
  2986. }
  2987. }
  2988. else
  2989. {
  2990. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2991. {
  2992. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2993. compositePeriodIdx++;
  2994. }
  2995. else
  2996. {
  2997. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2998. }
  2999. }
  3000. }
  3001. if(idxTxPeriod == (limitTx-1))
  3002. {
  3003. if(defaultTxProfile.ChargingProfileId != -1)
  3004. {
  3005. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3006. {
  3007. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3008. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3009. (defaultTxProfile.ChargingSchedule.Duration>0))
  3010. {
  3011. if(maxProfile.ChargingProfileId != -1)
  3012. {
  3013. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3014. {
  3015. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3016. {
  3017. if((maxProfile.ChargingSchedule.Duration > 0))
  3018. {
  3019. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3020. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3021. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3022. }
  3023. else
  3024. {
  3025. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3026. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3027. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3028. }
  3029. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3030. {
  3031. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3032. {
  3033. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3034. compositePeriodIdx++;
  3035. }
  3036. else
  3037. {
  3038. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3039. }
  3040. }
  3041. // Delete duplicate period
  3042. if(compositePeriodIdx > 1)
  3043. {
  3044. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3045. {
  3046. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3047. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3048. compositePeriodIdx -= 1;
  3049. }
  3050. }
  3051. }
  3052. else
  3053. break;
  3054. }
  3055. }
  3056. else
  3057. {
  3058. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3059. {
  3060. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3061. compositePeriodIdx++;
  3062. }
  3063. else
  3064. {
  3065. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3066. }
  3067. }
  3068. }
  3069. }
  3070. }
  3071. }
  3072. }
  3073. }
  3074. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3075. else if(defaultTxProfile.ChargingProfileId != -1)
  3076. {
  3077. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3078. {
  3079. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3080. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3081. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3082. {
  3083. if(maxProfile.ChargingProfileId != -1)
  3084. {
  3085. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3086. {
  3087. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3088. {
  3089. if((maxProfile.ChargingSchedule.Duration > 0))
  3090. {
  3091. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3092. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3093. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3094. }
  3095. else
  3096. {
  3097. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3098. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3099. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3100. }
  3101. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3102. {
  3103. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3104. {
  3105. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3106. compositePeriodIdx++;
  3107. }
  3108. else
  3109. {
  3110. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3111. }
  3112. }
  3113. // Delete duplicate period
  3114. if(compositePeriodIdx > 1)
  3115. {
  3116. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3117. {
  3118. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3119. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3120. compositePeriodIdx -= 1;
  3121. }
  3122. }
  3123. }
  3124. else
  3125. break;
  3126. }
  3127. }
  3128. else
  3129. {
  3130. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3131. {
  3132. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3133. compositePeriodIdx++;
  3134. }
  3135. else
  3136. {
  3137. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3138. }
  3139. }
  3140. }
  3141. }
  3142. }
  3143. // Fill other period by MaxProfile
  3144. if(maxProfile.ChargingProfileId != -1)
  3145. {
  3146. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3147. {
  3148. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3149. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3150. (maxProfile.ChargingSchedule.Duration > 0))
  3151. {
  3152. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3153. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3154. {
  3155. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3156. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3157. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3158. }
  3159. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3160. {
  3161. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3162. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3163. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3164. }
  3165. if(tmpPeriod.Limit != -1)
  3166. {
  3167. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3168. {
  3169. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3170. {
  3171. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3172. compositePeriodIdx++;
  3173. }
  3174. else
  3175. {
  3176. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3177. }
  3178. }
  3179. // Delete duplicate period
  3180. if(compositePeriodIdx > 1)
  3181. {
  3182. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3183. {
  3184. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3185. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3186. compositePeriodIdx -= 1;
  3187. }
  3188. }
  3189. }
  3190. }
  3191. }
  3192. }
  3193. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3194. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3195. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3196. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3197. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3198. {
  3199. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3200. {
  3201. compositeProfile->ChargingProfileId = 1;
  3202. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3203. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3204. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3205. }
  3206. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3207. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3208. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3209. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3210. }
  3211. if(line)
  3212. free(line);
  3213. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3214. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3215. }
  3216. //==========================================
  3217. // Init all share memory
  3218. //==========================================
  3219. int InitShareMemory()
  3220. {
  3221. int result = PASS;
  3222. int MeterSMId;
  3223. //creat ShmSysConfigAndInfo
  3224. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3225. {
  3226. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3227. result = FAIL;
  3228. }
  3229. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3230. {
  3231. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3232. result = FAIL;
  3233. }
  3234. else
  3235. {}
  3236. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3237. {
  3238. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3239. result = FAIL;
  3240. }
  3241. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3242. {
  3243. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3244. result = FAIL;
  3245. }
  3246. else
  3247. {}
  3248. //creat ShmPsuData
  3249. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3250. {
  3251. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3252. result = FAIL;
  3253. }
  3254. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3255. {
  3256. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3257. result = FAIL;
  3258. }
  3259. else
  3260. {}
  3261. //creat ShmOCPP16Data
  3262. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3263. {
  3264. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3265. result = FAIL;
  3266. }
  3267. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3268. {
  3269. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3270. result = FAIL;
  3271. }
  3272. else
  3273. {}
  3274. /****************************** For Initial Settings************************************************/
  3275. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3276. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3277. // allocate Configuration memory address
  3278. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3279. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3280. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3281. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3282. //offline MeterValue Interval
  3283. TempMeterValueInterval = 0;
  3284. return result;
  3285. }
  3286. int ProcessShareMemory()
  3287. {
  3288. if(InitShareMemory() == FAIL)
  3289. {
  3290. DEBUG_ERROR("InitShareMemory NG\n");
  3291. if(ShmStatusCodeData!=NULL)
  3292. {
  3293. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3294. }
  3295. sleep(5);
  3296. return FAIL;
  3297. }
  3298. return PASS;
  3299. }
  3300. void CheckSystemValue(void)
  3301. {
  3302. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3303. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3304. char filenmae[100]={0};
  3305. char str[100]={0};
  3306. int tempIndex = 0;
  3307. //===============================
  3308. // send Heartbeat
  3309. //===============================
  3310. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3311. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3312. {
  3313. clientTime.Heartbeat=time((time_t*)NULL);
  3314. if(server_sign == TRUE)
  3315. {
  3316. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3317. }
  3318. else
  3319. {
  3320. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3321. }
  3322. }
  3323. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3324. {
  3325. //parameter for test
  3326. sendHeartbeatRequest(0);
  3327. //==============================================
  3328. // Reset Waiting Time
  3329. //==============================================
  3330. HeartBeatWithNOResponse += 1;
  3331. }
  3332. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3333. {
  3334. //==========================================
  3335. // csu trigger DataTransferReq
  3336. //==========================================
  3337. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3338. {
  3339. sendDataTransferRequest(gun_index);
  3340. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3341. }
  3342. //===============================
  3343. // CSU Trigger Authorize Request
  3344. //===============================
  3345. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3346. {
  3347. sendAuthorizeRequest(0);
  3348. authorizeRetryTimes = authorizeRetryTimes + 1;
  3349. if(authorizeRetryTimes < 3)
  3350. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3351. }
  3352. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3353. {
  3354. authorizeRetryTimes = 0;
  3355. SetOcppConnStatus(FALSE);
  3356. server_sign = FALSE;
  3357. }
  3358. 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))
  3359. {
  3360. sendAuthorizeRequest(0);
  3361. }
  3362. //==============================================
  3363. // Charger start transaction
  3364. //==============================================
  3365. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3366. {
  3367. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3368. sendStartTransactionRequest(gun_index);
  3369. clientTime.StartTransaction = time((time_t*)NULL);
  3370. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3371. storeTempStopTransaction(gun_index);
  3372. }
  3373. //==============================================
  3374. // Charger stop transaction
  3375. //==============================================
  3376. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3377. {
  3378. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3379. sendStopTransactionRequest(gun_index);
  3380. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3381. clientTime.StopTransaction = time((time_t*)NULL);
  3382. }
  3383. //==============================================
  3384. // Charger status report
  3385. //==============================================
  3386. //--- Check Mode Change ---//
  3387. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3388. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3389. {
  3390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3391. {
  3392. tempIndex = ((gun_index==2) ? 1: 0);
  3393. }
  3394. else
  3395. {
  3396. tempIndex = gun_index;
  3397. }
  3398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3399. {
  3400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3401. {
  3402. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3403. {
  3404. // Sent unplug message for California pricing logic
  3405. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3406. {
  3407. uint8_t ts[20];
  3408. getNowDatetime(ts);
  3409. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3410. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3411. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3412. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3413. }
  3414. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3415. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3416. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3417. }
  3418. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3419. {
  3420. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3421. if((access(filenmae,F_OK))!=-1)
  3422. {
  3423. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3424. sprintf(str,"rm -f %s",filenmae);
  3425. system(str);
  3426. }
  3427. }
  3428. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3429. #if 1 // for TempStopTransaction
  3430. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3431. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3432. {
  3433. checkTempStopTransaction(gun_index);
  3434. }
  3435. #endif
  3436. }
  3437. }
  3438. }
  3439. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3440. {
  3441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3442. {
  3443. tempIndex = ((gun_index==2) ? 1: 0);
  3444. }
  3445. else
  3446. {
  3447. tempIndex = gun_index;
  3448. }
  3449. for (int index = 0; index < CCS_QUANTITY; index++)
  3450. {
  3451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3452. {
  3453. 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]*/ )
  3454. {
  3455. // Sent unplug message for California pricing logic
  3456. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3457. {
  3458. uint8_t ts[20];
  3459. getNowDatetime(ts);
  3460. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3461. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3462. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3463. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3464. }
  3465. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3466. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3467. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3468. }
  3469. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3470. {
  3471. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3472. if((access(filenmae,F_OK))!=-1)
  3473. {
  3474. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3475. sprintf(str,"rm -f %s",filenmae);
  3476. system(str);
  3477. }
  3478. }
  3479. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3480. #if 1 // for TempStopTransaction
  3481. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3482. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3483. {
  3484. checkTempStopTransaction(gun_index);
  3485. }
  3486. #endif
  3487. }
  3488. }
  3489. }
  3490. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3491. {
  3492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3493. {
  3494. tempIndex = ((gun_index==2) ? 1: 0);
  3495. }
  3496. else
  3497. {
  3498. tempIndex = gun_index;
  3499. }
  3500. for (int index = 0; index < GB_QUANTITY; index++)
  3501. {
  3502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3503. {
  3504. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3505. {
  3506. // Sent unplug message for California pricing logic
  3507. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3508. {
  3509. uint8_t ts[20];
  3510. getNowDatetime(ts);
  3511. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3512. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3513. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3514. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3515. }
  3516. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3517. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3518. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3519. }
  3520. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3521. {
  3522. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3523. if((access(filenmae,F_OK))!=-1)
  3524. {
  3525. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3526. sprintf(str,"rm -f %s",filenmae);
  3527. system(str);
  3528. }
  3529. }
  3530. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3531. #if 1 // for TempStopTransaction
  3532. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3533. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3534. {
  3535. checkTempStopTransaction(gun_index);
  3536. }
  3537. #endif
  3538. }
  3539. }
  3540. }
  3541. else if(gunType[gun_index] == GUN_TYPE_DO)
  3542. {
  3543. tempIndex = gun_index;
  3544. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3545. {
  3546. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3547. {
  3548. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3549. {
  3550. // Sent unplug message for California pricing logic
  3551. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3552. {
  3553. uint8_t ts[20];
  3554. getNowDatetime(ts);
  3555. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3556. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3557. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3558. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3559. }
  3560. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3561. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3562. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3563. }
  3564. 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
  3565. {
  3566. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3567. if((access(filenmae,F_OK))!=-1)
  3568. {
  3569. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3570. sprintf(str,"rm -f %s",filenmae);
  3571. system(str);
  3572. }
  3573. }
  3574. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3575. #if 1 // for TempStopTransaction
  3576. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3577. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3578. {
  3579. checkTempStopTransaction(gun_index);
  3580. }
  3581. #endif
  3582. }
  3583. }
  3584. }
  3585. else
  3586. {
  3587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3588. {
  3589. tempIndex = 2;
  3590. }
  3591. else
  3592. {
  3593. tempIndex = gun_index;
  3594. }
  3595. for (int index = 0; index < AC_QUANTITY; index++)
  3596. {
  3597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3598. {
  3599. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3600. {
  3601. // Sent unplug message for California pricing logic
  3602. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3603. {
  3604. uint8_t ts[20];
  3605. getNowDatetime(ts);
  3606. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3607. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3608. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3609. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3610. }
  3611. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3612. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3613. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3614. }
  3615. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3616. {
  3617. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3618. if((access(filenmae,F_OK))!=-1)
  3619. {
  3620. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3621. sprintf(str,"rm -f %s",filenmae);
  3622. system(str);
  3623. }
  3624. }
  3625. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3626. #if 1 // for TempStopTransaction
  3627. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3628. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3629. {
  3630. checkTempStopTransaction(gun_index);
  3631. }
  3632. #endif
  3633. }
  3634. }// END
  3635. }
  3636. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3637. (
  3638. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3639. )
  3640. )
  3641. {
  3642. if(SystemInitial > 0)
  3643. SystemInitial -= 1;
  3644. sendStatusNotificationRequest(gun_index);
  3645. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3646. }
  3647. //==============================================
  3648. // CSU Trigger Smart Charging Profilw
  3649. //==============================================
  3650. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3651. {
  3652. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3653. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3654. }
  3655. //==============================================
  3656. // Meter report
  3657. //==============================================
  3658. // Trigger MeterValue
  3659. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3660. {
  3661. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3662. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3663. }
  3664. // ClockAlign MeterValue
  3665. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3666. {
  3667. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3668. {
  3669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3670. {
  3671. tempIndex = ((gun_index==2) ? 1: 0);
  3672. }
  3673. else
  3674. {
  3675. tempIndex = gun_index;
  3676. }
  3677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3678. {
  3679. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3680. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3681. {
  3682. reqClockAlignMeter[gun_index] = 1;
  3683. }
  3684. }// End for CHAdeMO
  3685. }
  3686. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3687. {
  3688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3689. {
  3690. tempIndex = ((gun_index==2) ? 1: 0);
  3691. }
  3692. else
  3693. {
  3694. tempIndex = gun_index;
  3695. }
  3696. for (int index = 0; index < CCS_QUANTITY; index++)
  3697. {
  3698. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3699. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3700. {
  3701. reqClockAlignMeter[gun_index] = 1;
  3702. }
  3703. } // End for CCS
  3704. }
  3705. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((gun_index==2) ? 1: 0);
  3710. }
  3711. else
  3712. {
  3713. tempIndex = gun_index;
  3714. }
  3715. for (int index = 0; index < GB_QUANTITY; index++)
  3716. {
  3717. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3718. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3719. {
  3720. reqClockAlignMeter[gun_index] = 1;
  3721. }
  3722. }// End for GB
  3723. }
  3724. else if(gunType[gun_index] == GUN_TYPE_DO)
  3725. {
  3726. tempIndex = gun_index;
  3727. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3728. {
  3729. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3730. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3731. {
  3732. reqClockAlignMeter[gun_index] = 1;
  3733. }
  3734. }
  3735. }
  3736. else
  3737. {
  3738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3739. {
  3740. tempIndex = 2;
  3741. }
  3742. else
  3743. {
  3744. tempIndex = gun_index;
  3745. }
  3746. for (int index = 0; index < AC_QUANTITY; index++)
  3747. {
  3748. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3749. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3750. {
  3751. reqClockAlignMeter[gun_index] = 1;
  3752. }
  3753. }//End for AC
  3754. }
  3755. if(reqClockAlignMeter[gun_index] == 1)
  3756. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3757. }
  3758. // Sample period MeterValue
  3759. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3760. {
  3761. //check Transaction active
  3762. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3763. {
  3764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3765. {
  3766. tempIndex = ((gun_index==2) ? 1: 0);
  3767. }
  3768. else
  3769. {
  3770. tempIndex = gun_index;
  3771. }
  3772. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3773. {
  3774. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3775. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3776. {
  3777. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3778. {
  3779. reqSampleMeter[gun_index] = 1;
  3780. }
  3781. }
  3782. }// End for CHAdeMO
  3783. }
  3784. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3785. {
  3786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3787. {
  3788. tempIndex = ((gun_index==2) ? 1: 0);
  3789. }
  3790. else
  3791. {
  3792. tempIndex = gun_index;
  3793. }
  3794. for (int index = 0; index < CCS_QUANTITY; index++)
  3795. {
  3796. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3797. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3798. {
  3799. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3800. {
  3801. reqSampleMeter[gun_index] = 1;
  3802. }
  3803. }
  3804. } // End for CCS
  3805. }
  3806. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3807. {
  3808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3809. {
  3810. tempIndex = ((gun_index==2) ? 1: 0);
  3811. }
  3812. else
  3813. {
  3814. tempIndex = gun_index;
  3815. }
  3816. for (int index = 0; index < GB_QUANTITY; index++)
  3817. {
  3818. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3819. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3820. {
  3821. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3822. {
  3823. reqSampleMeter[gun_index] = 1;
  3824. }
  3825. }
  3826. }// End for GB
  3827. }
  3828. else if(gunType[gun_index] == GUN_TYPE_DO)
  3829. {
  3830. tempIndex = gun_index;
  3831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3832. {
  3833. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3834. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3835. {
  3836. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3837. {
  3838. reqSampleMeter[gun_index] = 1;
  3839. }
  3840. }
  3841. }
  3842. }
  3843. else
  3844. {
  3845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3846. {
  3847. tempIndex = 2;
  3848. }
  3849. else
  3850. {
  3851. tempIndex = gun_index;
  3852. }
  3853. for (int index = 0; index < AC_QUANTITY; index++)
  3854. {
  3855. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3856. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3857. {
  3858. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3859. {
  3860. reqSampleMeter[gun_index] = 1;
  3861. }
  3862. }
  3863. }//End for AC
  3864. }
  3865. if(reqSampleMeter[gun_index] == 1)
  3866. {
  3867. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3868. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3869. storeTempStopTransaction(gun_index);
  3870. }
  3871. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3872. }
  3873. //==============================================
  3874. // Check Connector reserved
  3875. //==============================================
  3876. //===============================
  3877. // Check if Reserve is expired
  3878. //===============================
  3879. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3880. {
  3881. double diff_t;
  3882. struct tm tp;
  3883. // current time
  3884. time_t t = time(NULL);
  3885. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3886. tp.tm_isdst = -1;
  3887. time_t utc = mktime(&tp);
  3888. diff_t = difftime(utc, t);
  3889. if(diff_t <= 0)
  3890. {
  3891. DEBUG_INFO("reserve expired.\n");
  3892. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3893. }
  3894. }//END OF Check if Reserve is expired
  3895. //==========================================
  3896. // csu trigger FirmwareStatusNotificationReq
  3897. //==========================================
  3898. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3899. {
  3900. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3901. }
  3902. //==========================================
  3903. // csu trigger DiagnosticsStatusNotificationReq
  3904. //==========================================
  3905. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3906. {
  3907. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3908. }
  3909. //==========================================
  3910. // csu trigger CancelReservationConf
  3911. //==========================================
  3912. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3913. {
  3914. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3915. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3916. }
  3917. //==========================================
  3918. // csu trigger ChangeAvailabilityConf
  3919. //==========================================
  3920. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3921. {
  3922. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3923. }
  3924. //==========================================
  3925. // csu trigger UnlockConnectorConf
  3926. //==========================================
  3927. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3928. {
  3929. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3930. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3931. }
  3932. //==========================================
  3933. // csu trigger ReserveNowConf
  3934. //==========================================
  3935. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3936. {
  3937. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3938. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3939. }
  3940. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3941. {
  3942. sendSignCertificateRequest();
  3943. }
  3944. }
  3945. }
  3946. //==========================================
  3947. // send request routine
  3948. //==========================================
  3949. int sendAuthorizeRequest(int gun_index)
  3950. {
  3951. mtrace();
  3952. int result = FAIL;
  3953. char message[100]={0};
  3954. char guid[37];
  3955. char tempdata[65]={0};
  3956. DEBUG_INFO("sendAuthorizeRequest...\n");
  3957. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3958. //Local Authorize
  3959. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3960. {
  3961. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3962. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3963. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3964. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3965. result = PASS;
  3966. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3967. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3968. authorizeRetryTimes = 0;
  3969. return result;
  3970. }
  3971. 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))||
  3972. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3973. {
  3974. // Query from cache
  3975. DEBUG_INFO("Authorize from cache.\n");
  3976. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3977. // Query from list
  3978. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3979. {
  3980. DEBUG_INFO("Authorize from list.\n");
  3981. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3982. }
  3983. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3984. {
  3985. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3986. {
  3987. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3988. }
  3989. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3990. {
  3991. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3992. }
  3993. if(!GetOcppConnStatus())
  3994. {
  3995. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3996. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3997. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3998. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3999. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4000. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4001. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4002. authorizeRetryTimes = 0;
  4003. return result;
  4004. }
  4005. }
  4006. else
  4007. {
  4008. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4009. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4010. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4011. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4012. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4013. else
  4014. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4015. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4016. result = PASS;
  4017. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4018. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4019. authorizeRetryTimes = 0;
  4020. return result;
  4021. }
  4022. }
  4023. //initialize struct Authorize
  4024. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4025. //get data from shared memory
  4026. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4027. random_uuid(guid);
  4028. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4029. LWS_Send(message);
  4030. sprintf(tempdata, "Authorize,%d", gun_index);
  4031. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4032. {
  4033. result = PASS;
  4034. DEBUG_INFO("Authorize mapItem pass\n");
  4035. }
  4036. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4037. return result;
  4038. }
  4039. int sendBootNotificationRequest(void)
  4040. {
  4041. mtrace();
  4042. int result = FAIL;
  4043. char message[500]={0}, payload[700]={0};
  4044. char guid[37]={0};
  4045. char tempdata[65]={0};
  4046. // Fill BootNotification fields
  4047. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4048. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4049. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4050. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4051. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4052. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4053. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4054. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4055. ShmOCPP16Data->ChargeBoxId
  4056. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4057. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4058. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4059. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4060. ,ShmOCPP16Data->BootNotification.CpIccid
  4061. ,ShmOCPP16Data->BootNotification.CpImsi);
  4062. random_uuid(guid);
  4063. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4064. LWS_Send(message);
  4065. sprintf(tempdata, "BootNotification,0");
  4066. 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*/)
  4067. {
  4068. result = PASS;
  4069. }
  4070. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4071. strcpy(queuedata,message);
  4072. return result;
  4073. }
  4074. int sendDataTransferRequest(int gun_index)
  4075. {
  4076. mtrace();
  4077. char message[1000]={0};
  4078. char guid[37]={0};
  4079. char tempdata[65]={0};
  4080. int result = FAIL;
  4081. random_uuid(guid);
  4082. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4083. MESSAGE_TYPE_CALL,
  4084. guid,
  4085. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4086. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4087. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4088. LWS_Send(message);
  4089. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4090. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4091. {
  4092. result = PASS;
  4093. DEBUG_INFO("DataTransfer mapItem pass\n");
  4094. }
  4095. return result;
  4096. }
  4097. int sendDiagnosticsStatusNotificationRequest(char *status)
  4098. {
  4099. mtrace();
  4100. int result = FAIL;
  4101. char message[110]={0};
  4102. char guid[37]={0};
  4103. char tempdata[65]={0};
  4104. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4105. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4106. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4107. random_uuid(guid);
  4108. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4109. LWS_SendNow(message);
  4110. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4111. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4112. {
  4113. result = PASS;
  4114. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4115. }
  4116. //#ifdef SystemLogMessage
  4117. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4118. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4119. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4120. //#endif
  4121. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4122. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4123. //record status
  4124. if(strcmp(status,"Idle")==0)
  4125. {
  4126. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4127. }
  4128. else if(strcmp(status,"Uploaded")==0)
  4129. {
  4130. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4131. }
  4132. else if(strcmp(status,"UploadFailed")==0)
  4133. {
  4134. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4135. }
  4136. else if(strcmp(status,"Uploading")==0)
  4137. {
  4138. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4139. }
  4140. return result;
  4141. }
  4142. int sendFirmwareStatusNotificationRequest(char *status)
  4143. {
  4144. mtrace();
  4145. int result = FAIL;
  4146. char message[110]={0};
  4147. char guid[37]={0};
  4148. char tempdata[65]={0};
  4149. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4150. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4151. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4152. random_uuid(guid);
  4153. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4154. LWS_SendNow(message);
  4155. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4156. 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*/)
  4157. {
  4158. result = PASS;
  4159. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4160. }
  4161. //#ifdef SystemLogMessage
  4162. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4163. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4164. //#endif
  4165. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4166. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4167. //record status
  4168. if(strcmp(status,"Downloaded")==0)
  4169. {
  4170. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4171. }
  4172. else if(strcmp(status,"DownloadFailed")==0)
  4173. {
  4174. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4175. }
  4176. else if(strcmp(status,"Downloading")==0)
  4177. {
  4178. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4179. }
  4180. else if(strcmp(status,"Idle")==0)
  4181. {
  4182. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4183. }
  4184. else if(strcmp(status,"InstallationFailed")==0)
  4185. {
  4186. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4187. }
  4188. else if(strcmp(status,"Installing")==0)
  4189. {
  4190. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4191. }
  4192. else if(strcmp(status,"Installed")==0)
  4193. {
  4194. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4195. }
  4196. return result;
  4197. }
  4198. int sendHeartbeatRequest(int gun_index)
  4199. {
  4200. mtrace();
  4201. int result = FAIL;
  4202. char message[80]={0};
  4203. char guid[37]={0};
  4204. char tempdata[65]={0};
  4205. random_uuid(guid);
  4206. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4207. , MESSAGE_TYPE_CALL
  4208. , guid );
  4209. LWS_Send(message);
  4210. sprintf(tempdata, "Heartbeat,%d", 0);
  4211. 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*/)
  4212. {
  4213. result = PASS;
  4214. }
  4215. return result;
  4216. }
  4217. int sendStartTransactionRequest(int gun_index)
  4218. {
  4219. mtrace();
  4220. int result = FAIL;
  4221. char message[250]={0};
  4222. char guid[37]={0};
  4223. struct timeval tmnow;
  4224. struct tm *tm;
  4225. char buf[28];//, usec_buf[6];
  4226. char tempdata[65]={0};
  4227. int tempIndex = 0;
  4228. DEBUG_INFO("sendStartTransactionRequest...\n");
  4229. gettimeofday(&tmnow, NULL);
  4230. time_t t;
  4231. t = time(NULL);
  4232. /*UTC time and date*/
  4233. tm = gmtime(&t);
  4234. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4235. #if 0 // remove temporally
  4236. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4237. strcat(buf,".");
  4238. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4239. strcat(buf,usec_buf);
  4240. #endif
  4241. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4242. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4243. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4244. // clear StartTransaction Response
  4245. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4246. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4247. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4248. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4249. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4250. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4251. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4252. {
  4253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4254. {
  4255. tempIndex = ((gun_index==2) ? 1: 0);
  4256. }
  4257. else
  4258. {
  4259. tempIndex = gun_index;
  4260. }
  4261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4262. {
  4263. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4264. {
  4265. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4266. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4267. }
  4268. }
  4269. }
  4270. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4271. {
  4272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4273. {
  4274. tempIndex = ((gun_index==2) ? 1: 0);
  4275. }
  4276. else
  4277. {
  4278. tempIndex = gun_index;
  4279. }
  4280. for (int index = 0; index < CCS_QUANTITY; index++)
  4281. {
  4282. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4283. {
  4284. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4285. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4286. }
  4287. }
  4288. }
  4289. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4290. {
  4291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4292. {
  4293. tempIndex = ((gun_index==2) ? 1: 0);
  4294. }
  4295. else
  4296. {
  4297. tempIndex = gun_index;
  4298. }
  4299. for (int index = 0; index < GB_QUANTITY; index++)
  4300. {
  4301. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4302. {
  4303. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4304. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4305. }
  4306. }
  4307. }
  4308. else if(gunType[gun_index] == GUN_TYPE_DO)
  4309. {
  4310. tempIndex = gun_index;
  4311. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4312. {
  4313. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4314. {
  4315. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4316. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4317. }
  4318. }
  4319. }
  4320. else
  4321. {
  4322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4323. {
  4324. tempIndex = 2;
  4325. }
  4326. else
  4327. {
  4328. tempIndex = gun_index;
  4329. }
  4330. for (int index = 0; index < AC_QUANTITY; index++)
  4331. {
  4332. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4333. {
  4334. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4335. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4336. }
  4337. }
  4338. }
  4339. random_uuid(guid);
  4340. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4341. {
  4342. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4343. , gun_index +1
  4344. , MESSAGE_TYPE_CALL
  4345. , guid
  4346. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4347. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4348. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4349. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4350. }
  4351. else
  4352. {
  4353. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4354. , gun_index +1
  4355. , MESSAGE_TYPE_CALL
  4356. , guid
  4357. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4358. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4359. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4360. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4361. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4362. }
  4363. #if 1
  4364. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4365. 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*/)
  4366. {
  4367. result = PASS;
  4368. }
  4369. #endif
  4370. strcpy(queuedata, message);
  4371. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4372. OCPP_insert_transaction_msg(YES, queuedata);
  4373. return result;
  4374. }
  4375. int sendStatusNotificationRequest(int gun_index)
  4376. {
  4377. mtrace();
  4378. int result = FAIL;
  4379. char message[600]={0};
  4380. char guid[37];
  4381. int currentStatus = 0;
  4382. struct timeval tmnow;
  4383. struct tm *tm;
  4384. char buf[28];//, usec_buf[6];
  4385. char tempdata[65]={0};
  4386. int tempIndex = 0;
  4387. uint8_t isStateChanged = TRUE;
  4388. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4389. gettimeofday(&tmnow, NULL);
  4390. time_t t;
  4391. t = time(NULL);
  4392. /*UTC time and date*/
  4393. tm = gmtime(&t);
  4394. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4395. #if 0 // remove temporally
  4396. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4397. strcat(buf,".");
  4398. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4399. strcat(buf,usec_buf);
  4400. #endif
  4401. //printf("%s",buf);
  4402. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4403. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4404. // it's option
  4405. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4406. /*
  4407. enum _SYSTEM_STATUS
  4408. {
  4409. S_BOOTING = 0,
  4410. S_IDLE, = 1
  4411. S_AUTHORIZING, =2
  4412. S_REASSIGN_CHECK, =3
  4413. S_REASSIGN, =4
  4414. S_PRECHARGE, =5
  4415. S_PREPARING_FOR_EV, =6
  4416. S_PREPARING_FOR_EVSE, =7
  4417. S_CHARGING, =8
  4418. S_TERMINATING, =9
  4419. S_COMPLETE, =10
  4420. S_ALARM, =11
  4421. S_FAULT =12
  4422. }
  4423. */
  4424. //check Transaction active
  4425. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4426. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4427. {
  4428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4429. {
  4430. tempIndex = ((gun_index==2) ? 1: 0);
  4431. }
  4432. else
  4433. {
  4434. tempIndex = gun_index;
  4435. }
  4436. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4437. {
  4438. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4439. {
  4440. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4441. {
  4442. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4443. {
  4444. currentStatus = Preparing; //OCPP Status: Preparing
  4445. }
  4446. else
  4447. {
  4448. currentStatus = Available; //OCPP Status: Available
  4449. }
  4450. }
  4451. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4452. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4453. ) //S_PRECHARGE
  4454. {
  4455. currentStatus = Preparing; //OCPP Status: Preparing
  4456. }
  4457. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4458. {
  4459. currentStatus = Charging; //OCPP Status: Charging
  4460. }
  4461. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4462. {
  4463. currentStatus = Finishing; //OCPP Status: Finishing
  4464. }
  4465. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4466. {
  4467. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4468. }
  4469. 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
  4470. {
  4471. currentStatus = Unavailable; //OCPP Status: Unavailable
  4472. }
  4473. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4474. {
  4475. currentStatus = Faulted; //OCPP Status: Faulted
  4476. }
  4477. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4478. {
  4479. currentStatus = Reserved; //OCPP Status: Reserved
  4480. }
  4481. } //end of the same index
  4482. }//end of for CHAdeMO_QUANTITY
  4483. }
  4484. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4485. {
  4486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4487. {
  4488. tempIndex = ((gun_index==2) ? 1: 0);
  4489. }
  4490. else
  4491. {
  4492. tempIndex = gun_index;
  4493. }
  4494. for (int index = 0; index < CCS_QUANTITY; index++)
  4495. {
  4496. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4497. {
  4498. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4499. {
  4500. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4501. {
  4502. currentStatus = Preparing; //OCPP Status: Preparing
  4503. }
  4504. else
  4505. {
  4506. currentStatus = Available; //OCPP Status: Available
  4507. }
  4508. }
  4509. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4510. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4511. ) //S_PRECHARGE
  4512. {
  4513. currentStatus = Preparing; //OCPP Status: Preparing
  4514. }
  4515. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4516. {
  4517. currentStatus = Charging; //OCPP Status: Charging
  4518. }
  4519. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4520. {
  4521. currentStatus = Finishing; //OCPP Status: Finishing
  4522. }
  4523. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4524. {
  4525. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4526. }
  4527. 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
  4528. {
  4529. currentStatus = Unavailable; //OCPP Status : Unavailable
  4530. }
  4531. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4532. {
  4533. currentStatus = Faulted; //OCPP Status: Faulted
  4534. }
  4535. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4536. {
  4537. currentStatus = Reserved; //OCPP Status: Reserved
  4538. }
  4539. } //end of the same index
  4540. } // end of for CCS_QUANTITY
  4541. }
  4542. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4543. {
  4544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4545. {
  4546. tempIndex = ((gun_index==2) ? 1: 0);
  4547. }
  4548. else
  4549. {
  4550. tempIndex = gun_index;
  4551. }
  4552. for (int index = 0; index < GB_QUANTITY; index++)
  4553. {
  4554. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4555. {
  4556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4557. {
  4558. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4559. {
  4560. currentStatus = Preparing; //OCPP Status: Preparing
  4561. }
  4562. else
  4563. {
  4564. currentStatus = Available; //OCPP Status: Available
  4565. }
  4566. }
  4567. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4568. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4569. ) //S_PRECHARGE
  4570. {
  4571. currentStatus = Preparing; //OCPP Status: Preparing
  4572. }
  4573. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4574. {
  4575. currentStatus = Charging; //OCPP Status: Charging
  4576. }
  4577. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4578. {
  4579. currentStatus = Finishing; //OCPP Status: Finishing
  4580. }
  4581. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4582. {
  4583. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4584. }
  4585. 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
  4586. {
  4587. currentStatus = Unavailable; //OCPP Status: Unavailable
  4588. }
  4589. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4590. {
  4591. currentStatus = Faulted; //OCPP Status: Faulted
  4592. }
  4593. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4594. {
  4595. currentStatus = Reserved; //OCPP Status: Reserved
  4596. }
  4597. } //end of the same index
  4598. } // end of for GB_QUANTITY
  4599. }
  4600. else if(gunType[gun_index] == GUN_TYPE_DO)
  4601. {
  4602. tempIndex = gun_index;
  4603. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4604. {
  4605. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4606. {
  4607. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4608. {
  4609. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4610. {
  4611. currentStatus = Preparing; //OCPP Status: Preparing
  4612. }
  4613. else
  4614. {
  4615. currentStatus = Available; //OCPP Status: Available
  4616. }
  4617. }
  4618. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4619. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4620. ) //S_PRECHARGE
  4621. {
  4622. currentStatus = Preparing; //OCPP Status: Preparing
  4623. }
  4624. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4625. {
  4626. currentStatus = Charging; //OCPP Status: Charging
  4627. }
  4628. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4629. {
  4630. currentStatus = Finishing; //OCPP Status: Finishing
  4631. }
  4632. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4633. {
  4634. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4635. }
  4636. 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
  4637. {
  4638. currentStatus = Unavailable; //OCPP Status: Unavailable
  4639. }
  4640. 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
  4641. {
  4642. currentStatus = Faulted; //OCPP Status: Faulted
  4643. }
  4644. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4645. {
  4646. currentStatus = Reserved; //OCPP Status: Reserved
  4647. }
  4648. } //end of the same index
  4649. }
  4650. }
  4651. else
  4652. {
  4653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4654. {
  4655. tempIndex = 2;
  4656. }
  4657. else
  4658. {
  4659. tempIndex = gun_index;
  4660. }
  4661. for (int index = 0; index < AC_QUANTITY; index++)
  4662. {
  4663. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4664. {
  4665. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4666. {
  4667. 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))
  4668. {
  4669. currentStatus = Preparing; //OCPP Status: Preparing
  4670. }
  4671. else
  4672. {
  4673. currentStatus = Available; //OCPP Status: Available
  4674. }
  4675. }
  4676. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4677. {
  4678. currentStatus = Preparing; //OCPP Status: Preparing
  4679. }
  4680. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4681. {
  4682. currentStatus = Charging; //OCPP Status: Charging
  4683. }
  4684. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4685. {
  4686. currentStatus = Finishing; //OCPP Status: Finishing
  4687. }
  4688. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4689. {
  4690. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4691. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4692. else
  4693. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4694. }
  4695. 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
  4696. {
  4697. currentStatus = Unavailable; //OCPP Status: Unavailable
  4698. }
  4699. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4700. {
  4701. currentStatus = Faulted; //OCPP Status: Faulted
  4702. }
  4703. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4704. {
  4705. currentStatus = Reserved; //OCPP Status: Reserved
  4706. }
  4707. }//end of the same index
  4708. }//end of for AC_QUANTITY
  4709. }
  4710. //it's option
  4711. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4712. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4713. {
  4714. isStateChanged = FALSE;
  4715. }
  4716. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4717. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4718. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4719. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4720. random_uuid(guid);
  4721. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4722. , MESSAGE_TYPE_CALL
  4723. , guid
  4724. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4725. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4726. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4727. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4728. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4729. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4730. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4731. if((server_sign == TRUE) && isStateChanged)
  4732. {
  4733. LWS_Send(message);
  4734. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4735. 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*/)
  4736. {
  4737. //DEBUG_ERROR("statusNotification mapitem pass");
  4738. result = PASS;
  4739. }
  4740. }
  4741. else
  4742. {
  4743. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4744. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4745. result = PASS;
  4746. }
  4747. return result;
  4748. }
  4749. int sendStopTransactionRequest(int gun_index)
  4750. {
  4751. mtrace();
  4752. int result = FAIL;
  4753. //char message[1500]={0};
  4754. char guid[37]={0};
  4755. char tempdata[65]={0};
  4756. int tempIndex = 0;
  4757. char TempStopTransaction[256];
  4758. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4759. //int idx_sample=0;
  4760. DEBUG_INFO("sendStopTransactionRequest \n");
  4761. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4762. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4763. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4764. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4765. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4766. {
  4767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4768. {
  4769. tempIndex = ((gun_index==2) ? 1: 0);
  4770. }
  4771. else
  4772. {
  4773. tempIndex = gun_index;
  4774. }
  4775. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4776. {
  4777. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4778. {
  4779. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4780. }
  4781. }// END OF CHAdeMO_QUANTITY
  4782. }
  4783. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4784. {
  4785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4786. {
  4787. tempIndex = ((gun_index==2) ? 1: 0);
  4788. }
  4789. else
  4790. {
  4791. tempIndex = gun_index;
  4792. }
  4793. for (int index = 0; index < CCS_QUANTITY; index++)
  4794. {
  4795. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4796. {
  4797. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4798. }
  4799. }// END OF CCS_QUANTITY
  4800. }
  4801. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4802. {
  4803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4804. {
  4805. tempIndex = ((gun_index==2) ? 1: 0);
  4806. }
  4807. else
  4808. {
  4809. tempIndex = gun_index;
  4810. }
  4811. for (int index = 0; index < GB_QUANTITY; index++)
  4812. {
  4813. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4814. {
  4815. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4816. }
  4817. }// END OF GB_QUANTITY
  4818. }
  4819. else if(gunType[gun_index] == GUN_TYPE_DO)
  4820. {
  4821. tempIndex = gun_index;
  4822. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4823. {
  4824. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4825. {
  4826. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4827. }
  4828. }// END OF GB_QUANTITY
  4829. }
  4830. else
  4831. {
  4832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4833. {
  4834. tempIndex = 2;
  4835. }
  4836. else
  4837. {
  4838. tempIndex = gun_index;
  4839. }
  4840. for (int index = 0; index < AC_QUANTITY; index++)
  4841. {
  4842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4843. {
  4844. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4845. }
  4846. }// END OF AC_QUANTITY
  4847. }
  4848. //====================================== Stop Transaction Time =====================================================
  4849. struct timeval tmnow;
  4850. struct tm *tm;
  4851. char buf[28];//, usec_buf[6];
  4852. gettimeofday(&tmnow, NULL);
  4853. time_t t;
  4854. t = time(NULL);
  4855. /*UTC time and date*/
  4856. tm = gmtime(&t);
  4857. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4859. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4860. random_uuid(guid);
  4861. /***********************************transactionData******************************************************/
  4862. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4864. //=================================
  4865. // Transaction_Begin
  4866. //=================================
  4867. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4868. {
  4869. //============================================ Energy.Active.Import.Interval ================================
  4870. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4873. 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*/]);
  4874. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4875. 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))
  4876. {
  4877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4878. }
  4879. else
  4880. {
  4881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4882. }
  4883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4885. }
  4886. //=================================
  4887. // Transaction_End
  4888. //=================================
  4889. // ================================= Current.Import L1 ===============================================
  4890. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4891. {
  4892. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4894. {
  4895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4896. {
  4897. tempIndex = ((gun_index==2) ? 1: 0);
  4898. }
  4899. else
  4900. {
  4901. tempIndex = gun_index;
  4902. }
  4903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4904. {
  4905. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4906. {
  4907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4908. }
  4909. }// End of for CHAdeMO_QUANTITY
  4910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4911. }
  4912. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4913. {
  4914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4915. {
  4916. tempIndex = ((gun_index==2) ? 1: 0);
  4917. }
  4918. else
  4919. {
  4920. tempIndex = gun_index;
  4921. }
  4922. for (int index = 0; index < CCS_QUANTITY; index++)
  4923. {
  4924. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4925. {
  4926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4927. }
  4928. }// End of for CCS_QUANTITY
  4929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4930. }
  4931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4932. {
  4933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4934. {
  4935. tempIndex = ((gun_index==2) ? 1: 0);
  4936. }
  4937. else
  4938. {
  4939. tempIndex = gun_index;
  4940. }
  4941. for (int index = 0; index < GB_QUANTITY; index++)
  4942. {
  4943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4944. {
  4945. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4946. }
  4947. }// End of for GB_QUANTITY
  4948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4949. }
  4950. else if(gunType[gun_index] == GUN_TYPE_DO)
  4951. {
  4952. tempIndex = gun_index;
  4953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4954. {
  4955. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4956. {
  4957. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4958. }
  4959. }
  4960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4961. }
  4962. else
  4963. {
  4964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4965. {
  4966. tempIndex = 2;
  4967. }
  4968. else
  4969. {
  4970. tempIndex = gun_index;
  4971. }
  4972. for (int index = 0; index < AC_QUANTITY; index++)
  4973. {
  4974. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4975. {
  4976. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4977. }
  4978. }// End of for AC_QUANTITY
  4979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4980. }
  4981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4986. }
  4987. // ================================= Energy.Active.Import.Interval ==============================================
  4988. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4989. {
  4990. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4991. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4992. {
  4993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4994. {
  4995. tempIndex = ((gun_index==2) ? 1: 0);
  4996. }
  4997. else
  4998. {
  4999. tempIndex = gun_index;
  5000. }
  5001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5002. {
  5003. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5004. {
  5005. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5006. }
  5007. }// END OF CHAdeMO_QUANTITY
  5008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5009. }
  5010. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5011. {
  5012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5013. {
  5014. tempIndex = ((gun_index==2) ? 1: 0);
  5015. }
  5016. else
  5017. {
  5018. tempIndex = gun_index;
  5019. }
  5020. for (int index = 0; index < CCS_QUANTITY; index++)
  5021. {
  5022. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5023. {
  5024. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5025. }
  5026. }// END OF CCS_QUANTITY
  5027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5028. }
  5029. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5030. {
  5031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5032. {
  5033. tempIndex = ((gun_index==2) ? 1: 0);
  5034. }
  5035. else
  5036. {
  5037. tempIndex = gun_index;
  5038. }
  5039. for (int index = 0; index < GB_QUANTITY; index++)
  5040. {
  5041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5042. {
  5043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5044. }
  5045. }// END OF GB_QUANTITY
  5046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5047. }
  5048. else if(gunType[gun_index] == GUN_TYPE_DO)
  5049. {
  5050. tempIndex = gun_index;
  5051. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5052. {
  5053. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5054. {
  5055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5056. }
  5057. }
  5058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5059. }
  5060. else
  5061. {
  5062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5063. {
  5064. tempIndex = 2;
  5065. }
  5066. else
  5067. {
  5068. tempIndex = gun_index;
  5069. }
  5070. for (int index = 0; index < AC_QUANTITY; index++)
  5071. {
  5072. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5073. {
  5074. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5075. }
  5076. }// END OF AC_QUANTITY
  5077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5078. }
  5079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5084. }
  5085. //=================================== Power.Active.Import ==================================================
  5086. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5087. {
  5088. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5089. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5090. {
  5091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5092. {
  5093. tempIndex = ((gun_index==2) ? 1: 0);
  5094. }
  5095. else
  5096. {
  5097. tempIndex = gun_index;
  5098. }
  5099. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5100. {
  5101. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5102. {
  5103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5104. }
  5105. } // End for CHAdeMO_QUANTITY
  5106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5107. }
  5108. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5109. {
  5110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5111. {
  5112. tempIndex = ((gun_index==2) ? 1: 0);
  5113. }
  5114. else
  5115. {
  5116. tempIndex = gun_index;
  5117. }
  5118. for (int index = 0; index < CCS_QUANTITY; index++)
  5119. {
  5120. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5121. {
  5122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5123. }
  5124. } // END for CCS_QUANTITY
  5125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5126. }
  5127. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5128. {
  5129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5130. {
  5131. tempIndex = ((gun_index==2) ? 1: 0);
  5132. }
  5133. else
  5134. {
  5135. tempIndex = gun_index;
  5136. }
  5137. for (int index = 0; index < GB_QUANTITY; index++)
  5138. {
  5139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5140. {
  5141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5142. }
  5143. }// END for GB_QUANTITY
  5144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5145. }
  5146. else if(gunType[gun_index] == GUN_TYPE_DO)
  5147. {
  5148. tempIndex = gun_index;
  5149. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5150. {
  5151. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5152. {
  5153. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5154. }
  5155. }
  5156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5157. }
  5158. else
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5161. {
  5162. tempIndex = 2;
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < AC_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5173. }
  5174. } // END for AC_QUANTITY
  5175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5176. }
  5177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5182. }
  5183. //============================ Voltage L1 ====================================
  5184. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5185. {
  5186. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5187. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  5198. {
  5199. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5200. {
  5201. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5202. }
  5203. } // END OF FOR CHAdeMO_QUANTITY
  5204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5205. }
  5206. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5207. {
  5208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5209. {
  5210. tempIndex = ((gun_index==2) ? 1: 0);
  5211. }
  5212. else
  5213. {
  5214. tempIndex = gun_index;
  5215. }
  5216. for (int index = 0; index < CCS_QUANTITY; index++)
  5217. {
  5218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5219. {
  5220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5221. }
  5222. } // END OF FOR CCS_QUANTITY
  5223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5224. }
  5225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5226. {
  5227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5228. {
  5229. tempIndex = ((gun_index==2) ? 1: 0);
  5230. }
  5231. else
  5232. {
  5233. tempIndex = gun_index;
  5234. }
  5235. for (int index = 0; index < GB_QUANTITY; index++)
  5236. {
  5237. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5238. {
  5239. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5240. }
  5241. } // END OF FOR GB_QUANTITY
  5242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5243. }
  5244. else if(gunType[gun_index] == GUN_TYPE_DO)
  5245. {
  5246. tempIndex = gun_index;
  5247. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5248. {
  5249. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5250. {
  5251. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5252. }
  5253. }
  5254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5255. }
  5256. else
  5257. {
  5258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5259. {
  5260. tempIndex = 2;
  5261. }
  5262. else
  5263. {
  5264. tempIndex = gun_index;
  5265. }
  5266. for (int index = 0; index < AC_QUANTITY; index++)
  5267. {
  5268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5269. {
  5270. 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
  5271. }
  5272. } // END OF FOR AC_QUANTITY
  5273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5274. }
  5275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5280. }
  5281. //====================== End SoC ================================
  5282. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5283. {
  5284. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5285. 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))
  5286. {
  5287. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5288. {
  5289. tempIndex = ((gun_index==2) ? 1: 0);
  5290. }
  5291. else
  5292. {
  5293. tempIndex = gun_index;
  5294. }
  5295. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5296. {
  5297. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5298. {
  5299. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5300. {
  5301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5302. }
  5303. }
  5304. }
  5305. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5306. {
  5307. for (int index = 0; index < CCS_QUANTITY; index++)
  5308. {
  5309. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5310. {
  5311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5312. }
  5313. }
  5314. }
  5315. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5316. {
  5317. for (int index = 0; index < GB_QUANTITY; index++)
  5318. {
  5319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5320. {
  5321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5322. }
  5323. }
  5324. }
  5325. else if(gunType[gun_index] == GUN_TYPE_DO)
  5326. {
  5327. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5328. {
  5329. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5330. {
  5331. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5332. }
  5333. }
  5334. }
  5335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5341. } // END FOR DC CASE
  5342. }
  5343. // ================================= Current.Import L2 ===============================================
  5344. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5345. {
  5346. // AC 3 phse L2 current
  5347. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5348. {
  5349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5350. {
  5351. tempIndex = 2;
  5352. }
  5353. else
  5354. {
  5355. tempIndex = gun_index;
  5356. }
  5357. for (int index = 0; index < AC_QUANTITY; index++)
  5358. {
  5359. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5360. {
  5361. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5362. }
  5363. }// End of for AC_QUANTITY
  5364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5365. }
  5366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5371. }
  5372. // ================================= Current.Import L3 ===============================================
  5373. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5374. {
  5375. // AC 3 phse L3 current
  5376. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5377. {
  5378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5379. {
  5380. tempIndex = 2;
  5381. }
  5382. else
  5383. {
  5384. tempIndex = gun_index;
  5385. }
  5386. for (int index = 0; index < AC_QUANTITY; index++)
  5387. {
  5388. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5389. {
  5390. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5391. }
  5392. }// End of for AC_QUANTITY
  5393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5394. }
  5395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5400. }
  5401. //============================ Voltage L2 ====================================
  5402. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5403. {
  5404. // AC 3 phse L2 voltage
  5405. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5408. {
  5409. tempIndex = 2;
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < AC_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5418. {
  5419. 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
  5420. }
  5421. } // END OF FOR AC_QUANTITY
  5422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5423. }
  5424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5429. }
  5430. //============================ Voltage L3 ====================================
  5431. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5432. {
  5433. // AC 3 phse L3 voltage
  5434. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5435. {
  5436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5437. {
  5438. tempIndex = 2;
  5439. }
  5440. else
  5441. {
  5442. tempIndex = gun_index;
  5443. }
  5444. for (int index = 0; index < AC_QUANTITY; index++)
  5445. {
  5446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5447. {
  5448. 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
  5449. }
  5450. } // END OF FOR AC_QUANTITY
  5451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5452. }
  5453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5458. }
  5459. //====================== Start SoC ================================
  5460. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5461. {
  5462. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5463. 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))
  5464. {
  5465. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5466. {
  5467. tempIndex = ((gun_index==2) ? 1: 0);
  5468. }
  5469. else
  5470. {
  5471. tempIndex = gun_index;
  5472. }
  5473. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5474. {
  5475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5476. {
  5477. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5478. {
  5479. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5480. }
  5481. }
  5482. }
  5483. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5484. {
  5485. for (int index = 0; index < CCS_QUANTITY; index++)
  5486. {
  5487. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5488. {
  5489. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5490. }
  5491. }
  5492. }
  5493. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5494. {
  5495. for (int index = 0; index < GB_QUANTITY; index++)
  5496. {
  5497. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5498. {
  5499. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5500. }
  5501. }
  5502. }
  5503. else if(gunType[gun_index] == GUN_TYPE_DO)
  5504. {
  5505. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5506. {
  5507. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5508. {
  5509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5510. }
  5511. }
  5512. }
  5513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5519. } // END FOR DC CASE
  5520. }
  5521. //================================================ Message create ====================================================
  5522. json_object *StopTransaction = json_object_new_object();
  5523. json_object *transactionDatas = json_object_new_array();
  5524. json_object *sampledValues = json_object_new_array();
  5525. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5526. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5527. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5528. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5529. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5530. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5531. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5532. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5533. {
  5534. json_object *transactionData = json_object_new_object();
  5535. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5536. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5537. {
  5538. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5539. {
  5540. json_object *sampledValue = json_object_new_object();
  5541. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5542. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5543. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5544. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5545. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5546. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5547. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5548. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5549. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5550. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5551. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5552. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5553. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5554. json_object_array_add(sampledValues, sampledValue);
  5555. }
  5556. }
  5557. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5558. json_object_array_add(transactionDatas, transactionData);
  5559. }
  5560. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5561. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5562. ,MESSAGE_TYPE_CALL
  5563. ,guid
  5564. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5565. json_object_put(StopTransaction);
  5566. #if 1 // for TempStopTransaction
  5567. //Delete TempStopTransaction
  5568. if((access(TempStopTransaction,F_OK))!=-1)
  5569. {
  5570. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5571. }
  5572. #endif
  5573. #if 1
  5574. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5575. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5576. {
  5577. result = PASS;
  5578. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5579. }
  5580. #endif
  5581. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5582. OCPP_insert_transaction_msg(NO, queuedata);
  5583. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5584. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5585. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5586. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5587. {
  5588. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5589. }
  5590. //for test
  5591. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5592. return result;
  5593. }
  5594. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5595. {
  5596. mtrace();
  5597. int result = FAIL;
  5598. char guid[37]={0};
  5599. char tempdata[65]={0};
  5600. int tempIndex = 0;
  5601. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5602. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5603. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5604. //set value
  5605. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5606. 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) )?
  5607. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5608. -1);
  5609. random_uuid(guid);
  5610. //UTC Date time
  5611. struct timeval tmnow;
  5612. struct tm *tm;
  5613. char buf[28];//, usec_buf[6];
  5614. gettimeofday(&tmnow, NULL);
  5615. time_t t;
  5616. t = time(NULL);
  5617. /*UTC time and date*/
  5618. tm = gmtime(&t);
  5619. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5620. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5621. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5622. //********************************(1)Current.Import L1************************************************/
  5623. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5624. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5625. (dataType == ReadingContext_Trigger))
  5626. {
  5627. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5628. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5629. {
  5630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5631. {
  5632. tempIndex = ((gun_index==2) ? 1: 0);
  5633. }
  5634. else
  5635. {
  5636. tempIndex = gun_index;
  5637. }
  5638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5639. {
  5640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5641. {
  5642. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5643. }
  5644. }
  5645. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5646. }
  5647. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5648. {
  5649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5650. {
  5651. tempIndex = ((gun_index==2) ? 1: 0);
  5652. }
  5653. else
  5654. {
  5655. tempIndex = gun_index;
  5656. }
  5657. for (int index = 0; index < CCS_QUANTITY; index++)
  5658. {
  5659. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5660. {
  5661. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5662. }
  5663. }
  5664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5665. }
  5666. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5667. {
  5668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5669. {
  5670. tempIndex = ((gun_index==2) ? 1: 0);
  5671. }
  5672. else
  5673. {
  5674. tempIndex = gun_index;
  5675. }
  5676. for (int index = 0; index < GB_QUANTITY; index++)
  5677. {
  5678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5679. {
  5680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5681. }
  5682. }
  5683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5684. }
  5685. else if(gunType[gun_index] == GUN_TYPE_DO)
  5686. {
  5687. tempIndex = gun_index;
  5688. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5689. {
  5690. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5691. {
  5692. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5693. }
  5694. }
  5695. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5696. }
  5697. else
  5698. {
  5699. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5700. {
  5701. tempIndex = 2;
  5702. }
  5703. else
  5704. {
  5705. tempIndex = gun_index;
  5706. }
  5707. for (int index = 0; index < AC_QUANTITY; index++)
  5708. {
  5709. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5710. {
  5711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5712. }
  5713. }
  5714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5715. }
  5716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5718. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5719. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5720. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5721. }
  5722. //********************************(2)Energy.Active.Import.Register ************************************************/
  5723. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5724. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5725. (dataType == ReadingContext_Trigger))
  5726. {
  5727. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5728. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5729. {
  5730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5731. {
  5732. tempIndex = ((gun_index==2) ? 1: 0);
  5733. }
  5734. else
  5735. {
  5736. tempIndex = gun_index;
  5737. }
  5738. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5739. {
  5740. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5741. {
  5742. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5743. }
  5744. }
  5745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5746. }
  5747. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5748. {
  5749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5750. {
  5751. tempIndex = ((gun_index==2) ? 1: 0);
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. for (int index = 0; index < CCS_QUANTITY; index++)
  5758. {
  5759. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5760. {
  5761. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5762. }
  5763. }
  5764. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5765. }
  5766. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5767. {
  5768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5769. {
  5770. tempIndex = ((gun_index==2) ? 1: 0);
  5771. }
  5772. else
  5773. {
  5774. tempIndex = gun_index;
  5775. }
  5776. for (int index = 0; index < GB_QUANTITY; index++)
  5777. {
  5778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5779. {
  5780. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5781. }
  5782. }
  5783. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5784. }
  5785. else if(gunType[gun_index] == GUN_TYPE_DO)
  5786. {
  5787. tempIndex = gun_index;
  5788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5789. {
  5790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5791. {
  5792. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5793. }
  5794. }
  5795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5796. }
  5797. else
  5798. {
  5799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5800. {
  5801. tempIndex = 2;
  5802. }
  5803. else
  5804. {
  5805. tempIndex = gun_index;
  5806. }
  5807. for (int index = 0; index < AC_QUANTITY; index++)
  5808. {
  5809. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5810. {
  5811. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5812. }
  5813. }
  5814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5815. }
  5816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5818. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5819. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5821. }
  5822. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5823. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5824. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5825. (dataType == ReadingContext_Trigger))
  5826. {
  5827. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5828. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5829. {
  5830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5831. {
  5832. tempIndex = ((gun_index==2) ? 1: 0);
  5833. }
  5834. else
  5835. {
  5836. tempIndex = gun_index;
  5837. }
  5838. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5839. {
  5840. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5841. {
  5842. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5843. }
  5844. } // END OF FOR CHAdeMO_QUANTITY
  5845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5846. }
  5847. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5848. {
  5849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5850. {
  5851. tempIndex = ((gun_index==2) ? 1: 0);
  5852. }
  5853. else
  5854. {
  5855. tempIndex = gun_index;
  5856. }
  5857. for (int index = 0; index < CCS_QUANTITY; index++)
  5858. {
  5859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5860. {
  5861. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5862. }
  5863. } // END OF CCS_QUANTITY
  5864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5865. }
  5866. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5867. {
  5868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5869. {
  5870. tempIndex = ((gun_index==2) ? 1: 0);
  5871. }
  5872. else
  5873. {
  5874. tempIndex = gun_index;
  5875. }
  5876. for (int index = 0; index < GB_QUANTITY; index++)
  5877. {
  5878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5879. {
  5880. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5881. }
  5882. } // END OF GB_QUANTITY
  5883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5884. }
  5885. else if(gunType[gun_index] == GUN_TYPE_DO)
  5886. {
  5887. tempIndex = gun_index;
  5888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5889. {
  5890. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5891. {
  5892. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5893. }
  5894. }
  5895. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5896. }
  5897. else
  5898. {
  5899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5900. {
  5901. tempIndex = 2;
  5902. }
  5903. else
  5904. {
  5905. tempIndex = gun_index;
  5906. }
  5907. for (int index = 0; index < AC_QUANTITY; index++)
  5908. {
  5909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5910. {
  5911. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5912. }
  5913. }
  5914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5915. }
  5916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5921. }
  5922. //********************************(4)Power.Active.Import************************************************/
  5923. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5924. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5925. (dataType == ReadingContext_Trigger))
  5926. {
  5927. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5928. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5929. {
  5930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5931. {
  5932. tempIndex = ((gun_index==2) ? 1: 0);
  5933. }
  5934. else
  5935. {
  5936. tempIndex = gun_index;
  5937. }
  5938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5939. {
  5940. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5941. {
  5942. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5943. }
  5944. } // END OF FOR
  5945. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5946. }
  5947. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5948. {
  5949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5950. {
  5951. tempIndex = ((gun_index==2) ? 1: 0);
  5952. }
  5953. else
  5954. {
  5955. tempIndex = gun_index;
  5956. }
  5957. for (int index = 0; index < CCS_QUANTITY; index++)
  5958. {
  5959. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5960. {
  5961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5962. }
  5963. }
  5964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5965. }
  5966. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5967. {
  5968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5969. {
  5970. tempIndex = ((gun_index==2) ? 1: 0);
  5971. }
  5972. else
  5973. {
  5974. tempIndex = gun_index;
  5975. }
  5976. for (int index = 0; index < GB_QUANTITY; index++)
  5977. {
  5978. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5979. {
  5980. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5982. }
  5983. }
  5984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5985. }
  5986. else if(gunType[gun_index] == GUN_TYPE_DO)
  5987. {
  5988. tempIndex = gun_index;
  5989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5990. {
  5991. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5992. {
  5993. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5994. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5995. }
  5996. }
  5997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5998. }
  5999. else
  6000. {
  6001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6002. {
  6003. tempIndex = 2;
  6004. }
  6005. else
  6006. {
  6007. tempIndex = gun_index;
  6008. }
  6009. for (int index = 0; index < AC_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6012. {
  6013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6014. }
  6015. }
  6016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6017. }
  6018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6020. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6023. }
  6024. //***********************************************(5)VOLTAGE L1******************************************************/
  6025. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6026. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6027. (dataType == ReadingContext_Trigger))
  6028. {
  6029. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6030. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6031. {
  6032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6033. {
  6034. tempIndex = ((gun_index==2) ? 1: 0);
  6035. }
  6036. else
  6037. {
  6038. tempIndex = gun_index;
  6039. }
  6040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6045. }
  6046. }
  6047. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6048. }
  6049. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6050. {
  6051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6052. {
  6053. tempIndex = ((gun_index==2) ? 1: 0);
  6054. }
  6055. else
  6056. {
  6057. tempIndex = gun_index;
  6058. }
  6059. for (int index = 0; index < CCS_QUANTITY; index++)
  6060. {
  6061. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6062. {
  6063. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6064. }
  6065. }
  6066. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6067. }
  6068. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6069. {
  6070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6071. {
  6072. tempIndex = ((gun_index==2) ? 1: 0);
  6073. }
  6074. else
  6075. {
  6076. tempIndex = gun_index;
  6077. }
  6078. for (int index = 0; index < GB_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6081. {
  6082. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6083. }
  6084. }
  6085. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6086. }
  6087. else if(gunType[gun_index] == GUN_TYPE_DO)
  6088. {
  6089. tempIndex = gun_index;
  6090. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6093. {
  6094. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6095. }
  6096. }
  6097. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6098. }
  6099. else
  6100. {
  6101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6102. {
  6103. tempIndex = 2;
  6104. }
  6105. else
  6106. {
  6107. tempIndex = gun_index;
  6108. }
  6109. for (int index = 0; index < AC_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6112. {
  6113. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6114. }
  6115. }
  6116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6117. }
  6118. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6120. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6123. }
  6124. //***********************************************(6)SOC******************************************************/
  6125. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  6126. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  6127. (dataType == ReadingContext_Trigger))
  6128. {
  6129. 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))
  6130. {
  6131. //idx_sample=5;
  6132. //sampledValue = NULL;
  6133. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6134. {
  6135. tempIndex = ((gun_index==2) ? 1: 0);
  6136. }
  6137. else
  6138. {
  6139. tempIndex = gun_index;
  6140. }
  6141. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6142. {
  6143. //tempIndex = ((gun_index==2) ? 1: 0);
  6144. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6147. {
  6148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6149. }
  6150. }
  6151. }
  6152. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6153. {
  6154. //tempIndex = ((gun_index==2) ? 1: 0);
  6155. for (int index = 0; index < CCS_QUANTITY; index++)
  6156. {
  6157. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6158. {
  6159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6160. }
  6161. }
  6162. }
  6163. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6164. {
  6165. //tempIndex = ((gun_index==2) ? 1: 0);
  6166. for (int index = 0; index < GB_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6169. {
  6170. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6171. }
  6172. }
  6173. }
  6174. else if(gunType[gun_index] == GUN_TYPE_DO)
  6175. {
  6176. //tempIndex = ((gun_index==2) ? 1: 0);
  6177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6180. {
  6181. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6182. }
  6183. }
  6184. }
  6185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6190. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6191. }
  6192. }
  6193. //********************************(7)Current.Import L2************************************************/
  6194. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6195. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6196. (dataType == ReadingContext_Trigger))
  6197. {
  6198. // Only for AC 3 phase
  6199. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6200. {
  6201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6202. {
  6203. tempIndex = 2;
  6204. }
  6205. else
  6206. {
  6207. tempIndex = gun_index;
  6208. }
  6209. for (int index = 0; index < AC_QUANTITY; index++)
  6210. {
  6211. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6212. {
  6213. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6214. }
  6215. }
  6216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6217. }
  6218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6223. }
  6224. //********************************(8)Current.Import L3************************************************/
  6225. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6226. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6227. (dataType == ReadingContext_Trigger))
  6228. {
  6229. // Only for AC 3 phase
  6230. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6231. {
  6232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6233. {
  6234. tempIndex = 2;
  6235. }
  6236. else
  6237. {
  6238. tempIndex = gun_index;
  6239. }
  6240. for (int index = 0; index < AC_QUANTITY; index++)
  6241. {
  6242. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6243. {
  6244. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6245. }
  6246. }
  6247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6248. }
  6249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6253. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6254. }
  6255. //***********************************************(9)VOLTAGE L2******************************************************/
  6256. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6257. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6258. (dataType == ReadingContext_Trigger))
  6259. {
  6260. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6261. {
  6262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6263. {
  6264. tempIndex = 2;
  6265. }
  6266. else
  6267. {
  6268. tempIndex = gun_index;
  6269. }
  6270. for (int index = 0; index < AC_QUANTITY; index++)
  6271. {
  6272. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6273. {
  6274. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6275. }
  6276. }
  6277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6278. }
  6279. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6284. }
  6285. //***********************************************(10)VOLTAGE L3******************************************************/
  6286. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6287. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6288. (dataType == ReadingContext_Trigger))
  6289. {
  6290. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6291. {
  6292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6293. {
  6294. tempIndex = 2;
  6295. }
  6296. else
  6297. {
  6298. tempIndex = gun_index;
  6299. }
  6300. for (int index = 0; index < AC_QUANTITY; index++)
  6301. {
  6302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6303. {
  6304. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6305. }
  6306. }
  6307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6308. }
  6309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6314. }
  6315. // Message create ====================================================================================================
  6316. if(TRUE)
  6317. {
  6318. json_object *MeterValueReq = json_object_new_object();
  6319. json_object *MeterValues = json_object_new_array();
  6320. json_object *sampledValues = json_object_new_array();
  6321. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6322. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6323. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6324. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6325. {
  6326. json_object *MeterValue = json_object_new_object();
  6327. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6328. {
  6329. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6330. {
  6331. json_object *sampledValue = json_object_new_object();
  6332. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6333. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6334. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6335. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6336. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6337. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6338. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6339. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6340. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6341. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6342. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6343. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6344. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6345. json_object_array_add(sampledValues, sampledValue);
  6346. }
  6347. }
  6348. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6349. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6350. json_object_array_add(MeterValues, MeterValue);
  6351. }
  6352. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6353. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6354. ,gun_index + 1
  6355. ,MESSAGE_TYPE_CALL
  6356. ,guid
  6357. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6358. json_object_put(MeterValueReq);
  6359. }
  6360. // Put request guid to hash map
  6361. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6362. 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*/)
  6363. {
  6364. result = PASS;
  6365. //DEBUG_INFO("MeterValues mapitem pass\n");
  6366. }
  6367. if((dataType != ReadingContext_Trigger) &&
  6368. (dataType != ReadingContext_Sample_Clock) &&
  6369. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  6370. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6371. else
  6372. {
  6373. if(FirstHeartBeat)
  6374. LWS_Send(queuedata +2);
  6375. }
  6376. return result;
  6377. }
  6378. int sendLogStatusNotificationRequest(char *status)
  6379. {
  6380. mtrace();
  6381. int result = PASS;
  6382. char message[4096]={0};
  6383. char guid[37]={0};
  6384. char tempdata[128]={0};
  6385. json_object *LogStatusNotification = json_object_new_object();
  6386. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6387. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6388. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6389. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6390. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6391. random_uuid(guid);
  6392. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6393. json_object_put(LogStatusNotification);
  6394. LWS_Send(message);
  6395. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6396. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6397. {
  6398. result = PASS;
  6399. }
  6400. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6401. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6402. return result;
  6403. }
  6404. int sendSecurityEventNotificationRequest()
  6405. {
  6406. mtrace();
  6407. int result = PASS;
  6408. char message[4096]={0};
  6409. char guid[37]={0};
  6410. char tempdata[128]={0};
  6411. json_object *SecurityEventNotification = json_object_new_object();
  6412. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6413. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6414. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6415. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6416. random_uuid(guid);
  6417. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6418. json_object_put(SecurityEventNotification);
  6419. LWS_Send(message);
  6420. sprintf(tempdata, "SecurityEventNotification,0");
  6421. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6422. {
  6423. result = PASS;
  6424. }
  6425. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6426. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6427. return result;
  6428. }
  6429. int sendSignCertificateRequest()
  6430. {
  6431. mtrace();
  6432. int result = PASS;
  6433. char message[4096]={0};
  6434. char guid[37]={0};
  6435. char tempdata[128]={0};
  6436. json_object *SignCertificate = json_object_new_object();
  6437. DEBUG_INFO("sendSignCertificateRequest...\n");
  6438. // Read csr file content
  6439. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6440. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6441. char *line = NULL;
  6442. size_t len = 0;
  6443. while(getline(&line, &len, fp) != -1)
  6444. {
  6445. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6446. {
  6447. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6448. }
  6449. }
  6450. fclose(fp);
  6451. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6452. random_uuid(guid);
  6453. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6454. json_object_put(SignCertificate);
  6455. LWS_Send(message);
  6456. sprintf(tempdata, "SignCertificate,0");
  6457. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6458. {
  6459. result = PASS;
  6460. }
  6461. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6462. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6463. return result;
  6464. }
  6465. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6466. {
  6467. mtrace();
  6468. int result = PASS;
  6469. char message[110]={0};
  6470. char guid[37]={0};
  6471. char tempdata[65]={0};
  6472. json_object *FirmwareStatusNotification = json_object_new_object();
  6473. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6474. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6475. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6476. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6477. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6478. random_uuid(guid);
  6479. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6480. json_object_put(FirmwareStatusNotification);
  6481. LWS_Send(message);
  6482. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6483. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6484. {
  6485. result = PASS;
  6486. }
  6487. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6488. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6489. return result;
  6490. }
  6491. //==========================================
  6492. // send confirm routine
  6493. //==========================================
  6494. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6495. {
  6496. mtrace();
  6497. int result = FAIL;
  6498. char message[100]={0};
  6499. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6500. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6501. LWS_Send(message);
  6502. result = TRUE;
  6503. return result;
  6504. }
  6505. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6506. {
  6507. mtrace();
  6508. int result = FAIL;
  6509. char message[100]={0};
  6510. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6511. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6512. LWS_Send(message);
  6513. result = TRUE;
  6514. return result;
  6515. }
  6516. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6517. {
  6518. mtrace();
  6519. int result = FAIL;
  6520. char message[100]={0};
  6521. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6522. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6523. LWS_Send(message);
  6524. result = TRUE;
  6525. return result;
  6526. }
  6527. int sendClearCacheConfirmation(char *uuid,char *payload)
  6528. {
  6529. mtrace();
  6530. int result = FAIL;
  6531. char message[500]={0};
  6532. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6533. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6534. LWS_Send(message);
  6535. return result;
  6536. }
  6537. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6538. {
  6539. mtrace();
  6540. int result = FAIL;
  6541. char message[500]={0};
  6542. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6543. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6544. LWS_Send(message);
  6545. return result;
  6546. }
  6547. int sendDataTransferConfirmation(char *uuid,char *payload)
  6548. {
  6549. mtrace();
  6550. char statusStr[20]={0};
  6551. char dataStr[10]={0};
  6552. char sstr[20]={0};
  6553. int c = 0;
  6554. char *loc;
  6555. int result = FAIL;
  6556. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6557. /**********************status**************************/
  6558. loc = strstr(payload, "status");
  6559. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6560. c = 0;
  6561. while (loc[3+strlen("status")+c] != '\"')
  6562. {
  6563. sstr[c] = loc[3+strlen("status")+c];
  6564. c++;
  6565. }
  6566. sstr[c] = '\0';
  6567. strcpy(statusStr, sstr);
  6568. /**********************data**************************/
  6569. loc = strstr(payload, "data");
  6570. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6571. c = 0;
  6572. while (loc[3+strlen("data")+c] != '\"')
  6573. {
  6574. sstr[c] = loc[3+strlen("data")+c];
  6575. c++;
  6576. }
  6577. sstr[c] = '\0';
  6578. strcpy(dataStr, sstr);
  6579. return result;
  6580. }
  6581. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6582. {
  6583. mtrace();
  6584. int result = FAIL;
  6585. char message[1000]={0};
  6586. int CompositeScheduleIndex = 0;
  6587. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6588. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6589. if(nPeriod == 0)
  6590. {
  6591. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6592. {
  6593. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6594. ,MESSAGE_TYPE_CALLRESULT
  6595. ,uuid
  6596. ,payload
  6597. ,connectorIdInt);
  6598. }
  6599. else
  6600. {
  6601. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6602. ,MESSAGE_TYPE_CALLRESULT
  6603. ,uuid
  6604. ,payload
  6605. ,connectorIdInt
  6606. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6607. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6608. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6609. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6610. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6611. }
  6612. }
  6613. else
  6614. {
  6615. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6616. ,MESSAGE_TYPE_CALLRESULT
  6617. ,uuid
  6618. ,payload
  6619. ,connectorIdInt
  6620. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6621. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6622. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6623. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6624. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6625. {
  6626. if (idx_sample == 0)
  6627. {
  6628. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6629. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6630. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6631. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6632. }
  6633. else
  6634. {
  6635. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6636. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6637. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6638. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6639. }
  6640. }
  6641. sprintf(message + strlen(message), "]}}]");
  6642. }
  6643. LWS_Send(message);
  6644. result = TRUE;
  6645. return result;
  6646. }
  6647. int sendGetConfigurationConfirmation(char *uuid)
  6648. {
  6649. mtrace();
  6650. int result = FAIL;
  6651. int MaxKeySupported = 0;
  6652. int sentConfigurationNumber= 0;
  6653. int sentunConfigurationNumber= 0;
  6654. char message[4000]={0};
  6655. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6656. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6657. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6658. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6659. ,MESSAGE_TYPE_CALLRESULT
  6660. ,uuid );
  6661. //configuration key
  6662. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6663. {
  6664. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6665. {
  6666. if (sentConfigurationNumber == 0)
  6667. {
  6668. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6669. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6670. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6671. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6672. }
  6673. else
  6674. {
  6675. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6676. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6677. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6678. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6679. }
  6680. sentConfigurationNumber = sentConfigurationNumber + 1;
  6681. }
  6682. }
  6683. sprintf(message + strlen(message), "]");
  6684. if(UnknownKeynum != 0)
  6685. {
  6686. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6687. //unkown key
  6688. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6689. {
  6690. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6691. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6692. if(sentunConfigurationNumber == 0)
  6693. {
  6694. sprintf(message + strlen(message), "\"%s\""
  6695. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6696. }
  6697. else
  6698. {
  6699. sprintf(message + strlen(message), ",\"%s\""
  6700. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6701. }
  6702. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6703. }
  6704. sprintf(message + strlen(message), "]");
  6705. }
  6706. sprintf(message + strlen(message), "}]");
  6707. LWS_Send(message);
  6708. return result;
  6709. }
  6710. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6711. {
  6712. mtrace();
  6713. int result = FAIL;
  6714. char message[400]={0};
  6715. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6716. if(strcmp(payload,"")==0)
  6717. {
  6718. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6719. }
  6720. else
  6721. {
  6722. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6723. }
  6724. LWS_Send(message);
  6725. result = TRUE;
  6726. return result;
  6727. }
  6728. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6729. {
  6730. mtrace();
  6731. int result = FAIL;
  6732. char message[80]={0};
  6733. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6734. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6735. LWS_Send(message);
  6736. result = TRUE;
  6737. return result;
  6738. }
  6739. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6740. {
  6741. mtrace();
  6742. int result = FAIL;
  6743. char message[80]={0};
  6744. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6745. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6746. LWS_Send(message);
  6747. result = TRUE;
  6748. return result;
  6749. }
  6750. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6751. {
  6752. mtrace();
  6753. int result = FAIL;
  6754. char message[80]={0};
  6755. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6756. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6757. LWS_Send(message);
  6758. result = TRUE;
  6759. return result;
  6760. }
  6761. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6762. {
  6763. mtrace();
  6764. int result = FAIL;
  6765. char message[80]={0};
  6766. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6767. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6768. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6769. LWS_Send(message);
  6770. result = TRUE;
  6771. return result;
  6772. }
  6773. int sendResetConfirmation(char *uuid,char *payload)
  6774. {
  6775. mtrace();
  6776. int result = FAIL;
  6777. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6778. char message[80]={0};
  6779. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6780. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6781. LWS_Send(message);
  6782. result = TRUE;
  6783. return result;
  6784. }
  6785. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6786. {
  6787. mtrace();
  6788. int result = FAIL;
  6789. char message[500]={0};
  6790. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6791. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6792. LWS_Send(message);
  6793. result = TRUE;
  6794. return result;
  6795. }
  6796. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6797. {
  6798. mtrace();
  6799. int result = FAIL;
  6800. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6801. char message[80]={0};
  6802. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6803. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6804. LWS_Send(message);
  6805. result = TRUE;
  6806. return result;
  6807. }
  6808. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6809. {
  6810. mtrace();
  6811. int result = FAIL;
  6812. char message[80]={0};
  6813. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6814. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6815. LWS_Send(message);
  6816. result = TRUE;
  6817. return result;
  6818. }
  6819. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6820. {
  6821. mtrace();
  6822. int result = FAIL;
  6823. char message[80]={0};
  6824. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6825. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6826. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6827. LWS_Send(message);
  6828. result = TRUE;
  6829. return result;
  6830. }
  6831. int sendUpdateFirmwareConfirmation(char *uuid)
  6832. {
  6833. mtrace();
  6834. int result = FAIL;
  6835. char message[60]={0};
  6836. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6837. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6838. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6839. LWS_Send(message);
  6840. result = TRUE;
  6841. return result;
  6842. }
  6843. int sendCertificateSignedConfirmation(char *uuid)
  6844. {
  6845. mtrace();
  6846. int result = PASS;
  6847. char message[4096]={0};
  6848. json_object *CertificateSigned = json_object_new_object();
  6849. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6850. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6851. sprintf(message,"[%d,\"%s\",%s]"
  6852. ,MESSAGE_TYPE_CALLRESULT
  6853. ,uuid
  6854. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6855. json_object_put(CertificateSigned);
  6856. LWS_Send(message);
  6857. return result;
  6858. }
  6859. int sendDeleteCertificateConfirmation(char *uuid)
  6860. {
  6861. mtrace();
  6862. int result = PASS;
  6863. char message[4096]={0};
  6864. json_object *DeleteCertificate = json_object_new_object();
  6865. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6866. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6867. sprintf(message,"[%d,\"%s\",%s]"
  6868. ,MESSAGE_TYPE_CALLRESULT
  6869. ,uuid
  6870. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6871. json_object_put(DeleteCertificate);
  6872. LWS_Send(message);
  6873. return result;
  6874. }
  6875. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6876. {
  6877. mtrace();
  6878. int result = PASS;
  6879. char message[4096]={0};
  6880. json_object *ExtendedTriggerMessage = json_object_new_object();
  6881. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6882. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6883. sprintf(message,"[%d,\"%s\",%s]"
  6884. ,MESSAGE_TYPE_CALLRESULT
  6885. ,uuid
  6886. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6887. json_object_put(ExtendedTriggerMessage);
  6888. LWS_Send(message);
  6889. return result;
  6890. }
  6891. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6892. {
  6893. mtrace();
  6894. int result = PASS;
  6895. char message[4096]={0};
  6896. json_object *GetInstalledCertificateIds = json_object_new_object();
  6897. json_object *certificateHashDataDatas = json_object_new_array();
  6898. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6899. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6900. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6901. {
  6902. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6903. {
  6904. json_object *certificateHashData = json_object_new_object();
  6905. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6906. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6907. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6908. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6909. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6910. }
  6911. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6912. }
  6913. else
  6914. {
  6915. json_object_put(certificateHashDataDatas);
  6916. }
  6917. sprintf(message,"[%d,\"%s\",%s]"
  6918. ,MESSAGE_TYPE_CALLRESULT
  6919. ,uuid
  6920. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6921. json_object_put(GetInstalledCertificateIds);
  6922. LWS_Send(message);
  6923. return result;
  6924. }
  6925. int sendGetLogConfirmation(char *uuid)
  6926. {
  6927. mtrace();
  6928. int result = PASS;
  6929. char message[4096]={0};
  6930. json_object *GetLog = json_object_new_object();
  6931. DEBUG_INFO("sendGetLogConfirmation...\n");
  6932. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6933. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6934. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6935. sprintf(message,"[%d,\"%s\",%s]"
  6936. ,MESSAGE_TYPE_CALLRESULT
  6937. ,uuid
  6938. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6939. json_object_put(GetLog);
  6940. LWS_Send(message);
  6941. return result;
  6942. }
  6943. int sendInstallCertificateConfirmation(char *uuid)
  6944. {
  6945. mtrace();
  6946. int result = PASS;
  6947. char message[4096]={0};
  6948. json_object *InstallCertificate = json_object_new_object();
  6949. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6950. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6951. sprintf(message,"[%d,\"%s\",%s]"
  6952. ,MESSAGE_TYPE_CALLRESULT
  6953. ,uuid
  6954. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6955. json_object_put(InstallCertificate);
  6956. LWS_Send(message);
  6957. return result;
  6958. }
  6959. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6960. {
  6961. mtrace();
  6962. int result = PASS;
  6963. char message[4096]={0};
  6964. json_object *SignedUpdateFirmware = json_object_new_object();
  6965. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6966. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6967. sprintf(message,"[%d,\"%s\",%s]"
  6968. ,MESSAGE_TYPE_CALLRESULT
  6969. ,uuid
  6970. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6971. json_object_put(SignedUpdateFirmware);
  6972. LWS_Send(message);
  6973. return result;
  6974. }
  6975. int sendUnknownConfirmation(char *uuid)
  6976. {
  6977. mtrace();
  6978. int result = PASS;
  6979. char message[256]={0};
  6980. DEBUG_INFO("sendUnknownConfirmation...\n");
  6981. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6982. LWS_Send(message);
  6983. return result;
  6984. }
  6985. //==========================================
  6986. // Handle server request routine Start
  6987. //==========================================
  6988. int handleCancelReservationRequest(char *uuid, char *payload)
  6989. {
  6990. mtrace();
  6991. int result = FAIL;
  6992. int gunNO = 0;
  6993. int reservationIdInt = -1;
  6994. char comfirmstr[20];
  6995. DEBUG_INFO("handleCancelReservationRequest...\n");
  6996. json_object *CancelReservation;
  6997. CancelReservation = json_tokener_parse(payload);
  6998. if(!is_error(CancelReservation))
  6999. {
  7000. // Required data
  7001. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7002. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7003. }
  7004. json_object_put(CancelReservation);
  7005. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7006. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7007. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7008. if(reservationIdInt != -1)
  7009. {
  7010. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7011. //check Transaction active
  7012. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7013. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7014. {
  7015. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7016. {
  7017. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7018. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7019. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7020. {
  7021. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7022. }
  7023. else
  7024. {
  7025. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7026. }
  7027. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7028. goto end;
  7029. }
  7030. }
  7031. for (int index = 0; index < CCS_QUANTITY; index++)
  7032. {
  7033. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7034. {
  7035. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7036. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7037. if(gunType[2] == GUN_TYPE_CCS)
  7038. {
  7039. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7040. }
  7041. else
  7042. {
  7043. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7044. }
  7045. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7046. goto end;
  7047. }
  7048. }
  7049. for (int index = 0; index < GB_QUANTITY; index++)
  7050. {
  7051. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7052. {
  7053. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7054. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7055. if(gunType[2] == GUN_TYPE_GBT)
  7056. {
  7057. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7058. }
  7059. else
  7060. {
  7061. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7062. }
  7063. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7064. goto end;
  7065. }
  7066. }
  7067. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7068. {
  7069. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7070. {
  7071. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7072. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7073. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7074. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7075. goto end;
  7076. }
  7077. }
  7078. for (int index = 0; index < AC_QUANTITY; index++)
  7079. {
  7080. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7081. {
  7082. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7083. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7084. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7085. {
  7086. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7087. }
  7088. else
  7089. {
  7090. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7091. }
  7092. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7093. goto end;
  7094. }
  7095. }
  7096. }
  7097. //The reservationId does NOT match the reservationId
  7098. sendCancelReservationConfirmation(uuid, comfirmstr);
  7099. end:
  7100. // Fill in ocpp packet uuid
  7101. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7102. return result;
  7103. }
  7104. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7105. {
  7106. mtrace();
  7107. int result = FAIL;
  7108. int gunIndex = 0;
  7109. char typeStr[16]={0};
  7110. char comfirmstr[20];
  7111. int specificId = FALSE;
  7112. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7113. json_object *ChangeAvailability;
  7114. ChangeAvailability = json_tokener_parse(payload);
  7115. if(!is_error(ChangeAvailability))
  7116. {
  7117. // Required data
  7118. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7119. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7120. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7121. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7122. }
  7123. json_object_put(ChangeAvailability);
  7124. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7125. {
  7126. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7127. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7128. }
  7129. else if(gunIndex == 0)
  7130. {
  7131. for(int i=0; i < gunTotalNumber; i++)
  7132. {
  7133. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7134. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7135. }
  7136. }
  7137. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7138. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7139. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7140. {
  7141. specificId = TRUE;
  7142. }
  7143. if(specificId == FALSE)
  7144. goto end;
  7145. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7146. {
  7147. //----------------------gunIndex is 0 ------------------------------------------------//
  7148. if(gunIndex == 0)
  7149. {
  7150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7151. {
  7152. for(int i=0; i < gunTotalNumber; i++)
  7153. {
  7154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7155. {
  7156. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7157. {
  7158. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7159. {
  7160. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7161. goto end;
  7162. }
  7163. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7164. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7165. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7166. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7167. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7168. {
  7169. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7170. goto end;
  7171. }
  7172. }
  7173. }//END FOR CHAdeMO_QUANTITY
  7174. for (int index = 0; index < CCS_QUANTITY; index++)
  7175. {
  7176. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7177. {
  7178. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7179. {
  7180. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7181. goto end;
  7182. }
  7183. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7184. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7185. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7186. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7187. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7188. {
  7189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7190. goto end;
  7191. }
  7192. }
  7193. }//END FOR CCS_QUANTITY
  7194. for (int index = 0; index < GB_QUANTITY; index++)
  7195. {
  7196. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7197. {
  7198. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7199. {
  7200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7201. goto end;
  7202. }
  7203. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7204. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7205. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7206. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7207. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7208. {
  7209. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7210. goto end;
  7211. }
  7212. }
  7213. }// END FOR GB_QUANTITY
  7214. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7215. {
  7216. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7217. {
  7218. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7219. {
  7220. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7221. goto end;
  7222. }
  7223. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7224. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7225. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7226. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7227. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7228. {
  7229. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7230. goto end;
  7231. }
  7232. }
  7233. }// END FOR GENERAL_GUN_QUANTITY
  7234. for (int index = 0; index < AC_QUANTITY; index++)
  7235. {
  7236. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7237. {
  7238. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7239. {
  7240. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7241. goto end;
  7242. }
  7243. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7244. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7245. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7246. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7247. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7248. {
  7249. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7250. goto end;
  7251. }
  7252. }
  7253. }//END FOR AC_QUANTITY
  7254. }// END FOR gunTotalNumber
  7255. }
  7256. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7257. {
  7258. for(int i=0; i < gunTotalNumber; i++)
  7259. {
  7260. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7261. {
  7262. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7263. goto end;
  7264. }
  7265. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7266. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7267. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7268. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7269. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7270. {
  7271. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7272. goto end;
  7273. }
  7274. }
  7275. }
  7276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7277. goto end;
  7278. }
  7279. //----------------------gunIndex is not 0 ------------------------------------------------//
  7280. //check Transaction active
  7281. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7282. {
  7283. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7284. {
  7285. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7286. {
  7287. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7288. goto end;
  7289. }
  7290. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7291. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7292. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7293. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7294. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7295. {
  7296. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7297. goto end;
  7298. }
  7299. else
  7300. {
  7301. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7303. goto end;
  7304. }
  7305. }
  7306. }//END FOR CHAdeMO_QUANTITY
  7307. for (int index = 0; index < CCS_QUANTITY; index++)
  7308. {
  7309. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7310. {
  7311. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7312. {
  7313. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7314. goto end;
  7315. }
  7316. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7317. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7318. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7319. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7320. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7321. {
  7322. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7323. goto end;
  7324. }
  7325. else
  7326. {
  7327. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7329. goto end;
  7330. }
  7331. }
  7332. }//END FOR CCS_QUANTITY
  7333. for (int index = 0; index < GB_QUANTITY; index++)
  7334. {
  7335. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7336. {
  7337. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7338. {
  7339. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7340. goto end;
  7341. }
  7342. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7343. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7344. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7345. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7346. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7347. {
  7348. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7349. goto end;
  7350. }
  7351. else
  7352. {
  7353. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7355. goto end;
  7356. }
  7357. }
  7358. }// END FOR GB_QUANTITY
  7359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7360. {
  7361. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7362. {
  7363. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7364. {
  7365. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7366. goto end;
  7367. }
  7368. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7369. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7370. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7371. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7372. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7373. {
  7374. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7375. goto end;
  7376. }
  7377. else
  7378. {
  7379. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7381. goto end;
  7382. }
  7383. }
  7384. }// END FOR GENERAL_GUN_QUANTITY
  7385. for (int index = 0; index < AC_QUANTITY; index++)
  7386. {
  7387. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7388. {
  7389. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7390. {
  7391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7392. goto end;
  7393. }
  7394. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7395. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7396. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7397. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7398. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7399. {
  7400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7401. goto end;
  7402. }
  7403. else
  7404. {
  7405. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7406. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7407. goto end;
  7408. }
  7409. }
  7410. }//END FOR AC_QUANTITY
  7411. }//END FOR AvailabilityTypeStr[Inoperative]
  7412. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7413. {
  7414. //----------------------gunIndex is 0 ------------------------------------------------//
  7415. if(gunIndex == 0)
  7416. {
  7417. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7418. {
  7419. for(int i=0; i < gunTotalNumber; i++)
  7420. {
  7421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7422. {
  7423. 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
  7424. {
  7425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7426. goto end;
  7427. }
  7428. }//END FOR CHAdeMO_QUANTITY
  7429. for (int index = 0; index < CCS_QUANTITY; index++)
  7430. {
  7431. 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
  7432. {
  7433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7434. goto end;
  7435. }
  7436. }//END FOR CCS_QUANTITY
  7437. for (int index = 0; index < GB_QUANTITY; index++)
  7438. {
  7439. 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
  7440. {
  7441. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7442. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7443. goto end;
  7444. }
  7445. }// END FOR GB_QUANTITY
  7446. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7447. {
  7448. 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
  7449. {
  7450. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7452. goto end;
  7453. }
  7454. }// END FOR GENERAL_GUN_QUANTITY
  7455. for (int index = 0; index < AC_QUANTITY; index++)
  7456. {
  7457. 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
  7458. {
  7459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7460. goto end;
  7461. }
  7462. }//END FOR CHAdeMO_QUANTITY
  7463. }// END FOR gunTotalNumber
  7464. }
  7465. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7466. {
  7467. for(int i=0; i < gunTotalNumber; i++)
  7468. {
  7469. for (int index = 0; index < AC_QUANTITY; index++)
  7470. {
  7471. 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
  7472. {
  7473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7474. goto end;
  7475. }
  7476. }//END FOR CHAdeMO_QUANTITY
  7477. } // END FOR gunTotalNumber
  7478. }
  7479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7480. goto end;
  7481. }
  7482. //----------------------gunIndex is not 0 ------------------------------------------------//
  7483. //check Transaction active
  7484. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7485. {
  7486. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7487. {
  7488. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7489. goto end;
  7490. }
  7491. }//END FOR CHAdeMO_QUANTITY
  7492. for (int index = 0; index < CCS_QUANTITY; index++)
  7493. {
  7494. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7495. {
  7496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7497. goto end;
  7498. }
  7499. }//END FOR CCS_QUANTITY
  7500. for (int index = 0; index < GB_QUANTITY; index++)
  7501. {
  7502. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7503. {
  7504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7505. goto end;
  7506. }
  7507. }// END FOR GB_QUANTITY
  7508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7509. {
  7510. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7511. {
  7512. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7513. goto end;
  7514. }
  7515. }// END FOR GENERAL_GUN_QUANTITY
  7516. for (int index = 0; index < AC_QUANTITY; index++)
  7517. {
  7518. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7519. {
  7520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7521. goto end;
  7522. }
  7523. }//END FOR AC_QUANTITY
  7524. }//END FOR AvailabilityTypeStr[Operative]
  7525. end:
  7526. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7527. {
  7528. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7529. }
  7530. else
  7531. {
  7532. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7533. }
  7534. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7535. {
  7536. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7537. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7538. }
  7539. else if(gunIndex == 0)
  7540. {
  7541. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7542. {
  7543. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7544. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7545. }
  7546. }
  7547. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7548. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7549. return result;
  7550. }
  7551. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7552. {
  7553. mtrace();
  7554. int result = FAIL;
  7555. char keystr[40]={0};
  7556. char valuestr[256]={0};
  7557. char comfirmstr[20]={0};
  7558. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7559. json_object *ChangeConfiguration;
  7560. ChangeConfiguration = json_tokener_parse(payload);
  7561. if(!is_error(ChangeConfiguration))
  7562. {
  7563. // Required data
  7564. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7565. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7566. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7567. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7568. }
  7569. json_object_put(ChangeConfiguration);
  7570. if((uuid==NULL) || (payload ==NULL) )
  7571. {
  7572. DEBUG_ERROR("Payload is null\n");
  7573. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7574. }
  7575. else
  7576. {
  7577. int status = setKeyValue(keystr, valuestr);
  7578. switch(status)
  7579. {
  7580. case ConfigurationStatus_Accepted:
  7581. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7582. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7583. StoreConfigurationTable();
  7584. break;
  7585. case RebootRequired:
  7586. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7587. StoreConfigurationTable();
  7588. break;
  7589. case NotSupported:
  7590. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7591. break;
  7592. case ConfigurationStatus_Rejected:
  7593. default:
  7594. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7595. break;
  7596. }
  7597. }
  7598. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7599. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7600. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7601. {
  7602. ChageWebSocketPingInterval(atoi(valuestr));
  7603. }
  7604. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7605. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7606. {
  7607. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7608. SetOcppConnStatus(FALSE);
  7609. }
  7610. return result;
  7611. }
  7612. int handleClearCacheRequest(char *uuid, char *payload)
  7613. {
  7614. mtrace();
  7615. int result = FAIL;
  7616. char comfirmstr[20];
  7617. char rmFileCmd[100]={0};
  7618. struct stat stats;
  7619. DEBUG_INFO("handleClearCacheRequest...\n");
  7620. stat("/Storage/OCPP", &stats);
  7621. // Check for directory existence
  7622. if (S_ISDIR(stats.st_mode) == 1)
  7623. {}
  7624. else
  7625. {
  7626. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7627. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7628. system(rmFileCmd);
  7629. }
  7630. if(OCPP_cleanLocalCache())
  7631. {
  7632. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7633. }
  7634. else
  7635. {
  7636. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7637. }
  7638. sendClearCacheConfirmation(uuid, comfirmstr);
  7639. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7640. return result;
  7641. }
  7642. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7643. {
  7644. mtrace();
  7645. int result = FAIL;
  7646. int resultRename;
  7647. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7648. char chargingProfilePurposeStr[26]={0};
  7649. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7650. char tempchargingProfilePurposeStr[26]={0};
  7651. char str[100]={0};
  7652. char fname[200]={0};
  7653. char comfirmstr[20]={0};
  7654. char word[1600]={0};
  7655. int clearflag = FALSE;
  7656. int chargingProfileIdIsNULL = FALSE;
  7657. int connectorIsNULL = FALSE;
  7658. int chargingProfilePurposeIsNULL = FALSE;
  7659. int stackLevelIsNULL = FALSE;
  7660. //int GotoEnd = FALSE;
  7661. FILE *fptr1, *fptr2;
  7662. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7663. int n_chargingProfile=0;
  7664. int isEmptyFile = FALSE;
  7665. char sLineWord[1600]={0};
  7666. char chargingProfiles[10][100]={0};
  7667. int ChargeProfileCount = 0;
  7668. int ch;
  7669. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7670. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7671. json_object *ClearChargingProfile;
  7672. ClearChargingProfile = json_tokener_parse(payload);
  7673. if(!is_error(ClearChargingProfile))
  7674. {
  7675. // Optional data
  7676. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7677. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7678. else
  7679. chargingProfileIdIsNULL = TRUE;
  7680. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7681. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7682. else
  7683. connectorIsNULL = TRUE;
  7684. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7685. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7686. else
  7687. chargingProfilePurposeIsNULL = TRUE;
  7688. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7689. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7690. else
  7691. stackLevelIsNULL = TRUE;
  7692. }
  7693. json_object_put(ClearChargingProfile);
  7694. if(connectorIsNULL == FALSE)
  7695. {
  7696. switch(connectorIdInt)
  7697. {
  7698. case 0:
  7699. if(chargingProfilePurposeIsNULL == TRUE)
  7700. {
  7701. int l = 0;
  7702. strcpy(fname, ChargePointMaxProfile_JSON);
  7703. if((access(fname,F_OK))!=-1)
  7704. {
  7705. strcpy(chargingProfiles[l], fname);
  7706. l = l + 1;
  7707. }
  7708. strcpy(fname, TxDefaultProfile_0_JSON);
  7709. if((access(fname,F_OK))!=-1)
  7710. {
  7711. strcpy(chargingProfiles[l], fname);
  7712. l = l + 1;
  7713. }
  7714. ChargeProfileCount = l;
  7715. }
  7716. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7717. {
  7718. strcpy(fname, ChargePointMaxProfile_JSON);
  7719. if((access(fname,F_OK))!=-1)
  7720. {
  7721. strcpy(chargingProfiles[0], fname);
  7722. ChargeProfileCount = 1;
  7723. }
  7724. }
  7725. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7726. {
  7727. strcpy(fname, TxDefaultProfile_0_JSON);
  7728. if((access(fname,F_OK))!=-1)
  7729. {
  7730. strcpy(chargingProfiles[0], fname);
  7731. ChargeProfileCount = 1;
  7732. }
  7733. }
  7734. break;
  7735. default:
  7736. if(chargingProfilePurposeIsNULL == TRUE)
  7737. {
  7738. int m = 0;
  7739. memset(fname, 0, ARRAY_SIZE(fname));
  7740. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7741. if((access(fname,F_OK))!=-1)
  7742. {
  7743. strcpy(chargingProfiles[m], fname);
  7744. m = m + 1;
  7745. }
  7746. memset(fname, 0, ARRAY_SIZE(fname));
  7747. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7748. if((access(fname,F_OK))!=-1)
  7749. {
  7750. strcpy(chargingProfiles[m], fname);
  7751. m = m + 1;
  7752. }
  7753. ChargeProfileCount = m;
  7754. }
  7755. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7756. {
  7757. //strcpy(fname, TxDefaultProfile_1_JSON);
  7758. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7759. if((access(fname,F_OK))!=-1)
  7760. {
  7761. strcpy(chargingProfiles[0], fname);
  7762. ChargeProfileCount = 1;
  7763. }
  7764. }
  7765. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7766. {
  7767. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7768. if((access(fname,F_OK))!=-1)
  7769. {
  7770. strcpy(chargingProfiles[0], fname);
  7771. ChargeProfileCount = 1;
  7772. }
  7773. //strcpy(fname, TxProfile_1_JSON);
  7774. }
  7775. //strcpy(fname, ChargePointMaxProfile_JSON );
  7776. break;
  7777. }
  7778. }
  7779. else // Check all Charging Profiles
  7780. {
  7781. int i = 0;
  7782. char fnametemp[200]={0};
  7783. ChargeProfileCount = 0;
  7784. //Check ChargePointMaxProfile.json exit
  7785. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7786. {
  7787. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7788. i = i + 1;
  7789. }
  7790. //Check TxDefaultProfile_0.json exit
  7791. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7792. {
  7793. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7794. i = i + 1;
  7795. }
  7796. //Check TxDefaultProfile_%d.json
  7797. for(int j=1; j <= gunTotalNumber; j++)
  7798. {
  7799. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7800. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7801. if((access(fnametemp,F_OK))!=-1)
  7802. {
  7803. strcpy(chargingProfiles[i], fnametemp);
  7804. i = i + 1;
  7805. }
  7806. }
  7807. //Check TxProfile_%d.json
  7808. for(int j=1; j <= gunTotalNumber; j++)
  7809. {
  7810. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7811. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7812. if((access(fnametemp,F_OK))!=-1)
  7813. {
  7814. strcpy(chargingProfiles[i], fnametemp);
  7815. i = i + 1;
  7816. }
  7817. }
  7818. ChargeProfileCount = i;
  7819. }// End connectorIsNULL is TRUE
  7820. if(ChargeProfileCount == 0)
  7821. {
  7822. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7823. goto end;
  7824. }
  7825. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7826. {
  7827. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7828. goto end;
  7829. }
  7830. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7831. {
  7832. memset(str, 0, ARRAY_SIZE(str));
  7833. // clear temp file
  7834. sprintf(str,"rm -f %s",temp);
  7835. system(str);
  7836. for(int k=0; k < ChargeProfileCount; k++)
  7837. {
  7838. memset(str, 0, ARRAY_SIZE(str));
  7839. //clear file in C
  7840. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7841. system(str);
  7842. }
  7843. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7844. goto end;
  7845. }
  7846. else if(connectorIsNULL == TRUE)
  7847. {
  7848. for(int k=0; k < ChargeProfileCount; k++)
  7849. {
  7850. fptr1 = fopen(chargingProfiles[k], "r");
  7851. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7852. //Check Charging Profile Count
  7853. while(fscanf(fptr1, "%s", word) != EOF)
  7854. {
  7855. //DEBUG_INFO("word=%s\n",word);
  7856. if(strstr(word, "chargingProfileId")!= NULL)
  7857. {
  7858. //DEBUG_INFO("test chargingProfileId \n");
  7859. n_chargingProfile = n_chargingProfile + 1;
  7860. //DEBUG_INFO("chargingProfileId Found\n");
  7861. }
  7862. }
  7863. rewind(fptr1);
  7864. //search Charging Profile Element
  7865. //int i= 0;
  7866. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7867. {
  7868. json_object *tmpProfilee;
  7869. tmpProfilee = json_tokener_parse(sLineWord);
  7870. if(!is_error(tmpProfilee))
  7871. {
  7872. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7873. {
  7874. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7875. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7876. }
  7877. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7878. {
  7879. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7880. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7881. }
  7882. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7883. {
  7884. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7885. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7886. }
  7887. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7888. {
  7889. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7890. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7891. }
  7892. }
  7893. json_object_put(tmpProfilee);
  7894. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7895. {
  7896. //------- not write to fptr2-------//
  7897. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7898. //clearflag = TRUE;
  7899. }
  7900. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7901. {
  7902. //------- not write to fptr2-------//
  7903. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7904. }
  7905. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7906. {
  7907. //------- not write to fptr2-------//
  7908. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7909. }
  7910. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7911. {
  7912. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7913. }
  7914. else
  7915. {
  7916. fprintf(fptr2, sLineWord);//writing data into file
  7917. }
  7918. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7919. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7920. if(clearflag == TRUE)
  7921. {
  7922. fclose(fptr1);
  7923. fclose(fptr2);
  7924. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7925. system(str);
  7926. // clear temp file
  7927. sprintf(str,"rm -f %s",temp);
  7928. system(str);
  7929. }
  7930. else
  7931. {
  7932. fclose(fptr1);
  7933. fclose(fptr2);
  7934. memset(str, 0, ARRAY_SIZE(str));
  7935. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7936. system(str);
  7937. resultRename = rename(temp, chargingProfiles[k]);
  7938. if(resultRename == 0)
  7939. {
  7940. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7941. }
  7942. else
  7943. {
  7944. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7945. }
  7946. if(comfirmstr[0]== 0)
  7947. {
  7948. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7949. }
  7950. //Check chargingProfile is empty file
  7951. /*------ Read the file ----------------*/
  7952. fptr1=fopen(chargingProfiles[k],"r");
  7953. ch=fgetc(fptr1);
  7954. rewind(fptr1);
  7955. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7956. if(ch!=EOF)
  7957. {
  7958. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7959. {
  7960. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7961. if(sLineWord[0]=='\0')
  7962. {
  7963. isEmptyFile = TRUE;
  7964. break;
  7965. }
  7966. else
  7967. {
  7968. isEmptyFile = FALSE;
  7969. break;
  7970. }
  7971. }
  7972. }
  7973. else
  7974. isEmptyFile = TRUE;
  7975. fclose(fptr1);
  7976. if(isEmptyFile == TRUE)
  7977. {
  7978. memset(str, 0, ARRAY_SIZE(str));
  7979. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7980. system(str);
  7981. }
  7982. }
  7983. }// End of while(int k=0; k < ChargePointCount; k++)
  7984. }
  7985. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7986. {
  7987. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7988. for(int k=0; k < ChargeProfileCount; k++)
  7989. {
  7990. fptr1 = fopen(chargingProfiles[k], "r");
  7991. fptr2 = fopen(temp, "w+");
  7992. //Check Charging Profile Count
  7993. while(fscanf(fptr1, "%s", word) != EOF)
  7994. {
  7995. //DEBUG_INFO("word=%s\n",word);
  7996. if(strstr(word, "chargingProfileId")!= NULL)
  7997. {
  7998. n_chargingProfile = n_chargingProfile + 1;
  7999. }
  8000. }
  8001. rewind(fptr1);
  8002. //search Charging Profile Element
  8003. //int i= 0;
  8004. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8005. {
  8006. json_object *tmpProfilee;
  8007. tmpProfilee = json_tokener_parse(sLineWord);
  8008. if(!is_error(tmpProfilee))
  8009. {
  8010. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8011. {
  8012. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8013. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8014. }
  8015. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8016. {
  8017. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8018. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8019. }
  8020. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8021. {
  8022. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8023. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8024. }
  8025. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8026. {
  8027. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8028. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8029. }
  8030. }
  8031. json_object_put(tmpProfilee);
  8032. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8033. {
  8034. //------- not write to fptr2-------//
  8035. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8036. //clearflag = TRUE;
  8037. }
  8038. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8039. {
  8040. //------- not write to fptr2-------//
  8041. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8042. }
  8043. else if(stackLevelIsNULL == TRUE)
  8044. {
  8045. //Clear Whole File
  8046. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8047. clearflag = TRUE;
  8048. break;
  8049. }
  8050. else
  8051. {
  8052. fprintf(fptr2, sLineWord);//writing data into file
  8053. }
  8054. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8055. }
  8056. if(clearflag == TRUE)
  8057. {
  8058. fclose(fptr1);
  8059. fclose(fptr2);
  8060. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8061. system(str);
  8062. // clear temp file
  8063. sprintf(str,"rm -f %s",temp);
  8064. system(str);
  8065. }
  8066. else
  8067. {
  8068. fclose(fptr1);
  8069. fclose(fptr2);
  8070. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8071. system(str);
  8072. resultRename = rename(temp, chargingProfiles[k]);
  8073. if(resultRename == 0)
  8074. {
  8075. DEBUG_INFO("File ChargingProfile renamed successfully");
  8076. }
  8077. else
  8078. {
  8079. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8080. }
  8081. if(comfirmstr[0]== 0)
  8082. {
  8083. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8084. }
  8085. //Check chargingProfile is empty file
  8086. /*------ Read the file ----------------*/
  8087. fptr1=fopen(chargingProfiles[k],"r");
  8088. ch=fgetc(fptr1);
  8089. rewind(fptr1);
  8090. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8091. if(ch!=EOF)
  8092. {
  8093. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8094. {
  8095. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8096. if(sLineWord[0]=='\0')
  8097. {
  8098. isEmptyFile = TRUE;
  8099. break;
  8100. }
  8101. else
  8102. {
  8103. isEmptyFile = FALSE;
  8104. break;
  8105. }
  8106. }
  8107. }
  8108. else
  8109. isEmptyFile = TRUE;
  8110. fclose(fptr1);
  8111. if(isEmptyFile == TRUE)
  8112. {
  8113. memset(str, 0, ARRAY_SIZE(str));
  8114. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8115. system(str);
  8116. }
  8117. /*------- End of reading ---------------*/
  8118. }
  8119. } // while(int k=0; k < ChargeProfileCount; k++)
  8120. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8121. end:
  8122. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8123. {
  8124. if(connectorIdInt == 0)
  8125. {
  8126. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8127. {
  8128. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8129. }
  8130. }
  8131. else
  8132. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8133. }
  8134. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8135. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8136. return result;
  8137. }
  8138. void createFirmwareVersionByDataTransfer(void)
  8139. {
  8140. json_object *FirmwareDataTransfer = json_object_new_object();
  8141. // AC & DC model
  8142. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8143. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8144. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8145. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8146. // DC model
  8147. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8148. {
  8149. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8150. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8151. (gunType[3] != GUN_TYPE_UNKNOWN))
  8152. {
  8153. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8154. }
  8155. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8156. {
  8157. // DS DM DW
  8158. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8159. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8160. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8161. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8162. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8163. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8164. }
  8165. else
  8166. {
  8167. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8168. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8169. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8170. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8171. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8172. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8173. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8174. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8175. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8176. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8177. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8178. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8179. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8180. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8181. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8182. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8183. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8184. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8185. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8186. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8187. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8188. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8189. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8190. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8191. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8192. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8193. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8194. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8195. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8196. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8197. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8198. }
  8199. }
  8200. // 4G model
  8201. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8202. {
  8203. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8204. }
  8205. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8206. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8207. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8208. json_object_put(FirmwareDataTransfer);
  8209. }
  8210. int handleDataTransferRequest(char *uuid, char *payload)
  8211. {
  8212. mtrace();
  8213. json_object *response = json_object_new_object();
  8214. int result = FAIL;
  8215. char tempvendorId[255]={0};
  8216. char tempmessageId[50]={0};
  8217. char tempdata[512]={0};
  8218. char message[2048]={0};
  8219. DEBUG_INFO("handleDataTransferRequest...\n");
  8220. if((uuid != NULL) && (payload != NULL))
  8221. {
  8222. json_object *DataTransfer;
  8223. DataTransfer = json_tokener_parse(payload);
  8224. if(!is_error(DataTransfer))
  8225. {
  8226. // Required data
  8227. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8228. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8229. // Optional data
  8230. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8231. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8232. if(json_object_object_get(DataTransfer, "data") != NULL)
  8233. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8234. result = PASS;
  8235. }
  8236. json_object_put(DataTransfer);
  8237. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8238. {
  8239. // Send all moudle firmware version on EVSE
  8240. createFirmwareVersionByDataTransfer();
  8241. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8242. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8243. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8244. json_object_put(response);
  8245. }
  8246. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8247. {
  8248. system("/usr/bin/run_tmate_restart.sh &");
  8249. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8250. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8251. json_object_put(response);
  8252. }
  8253. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8254. {
  8255. json_object *data;
  8256. data = json_tokener_parse(tempdata);
  8257. if(!is_error(data))
  8258. {
  8259. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8260. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8261. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8262. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8263. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8264. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8265. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8266. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8267. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8268. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8269. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8270. }
  8271. else
  8272. {
  8273. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8274. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8275. }
  8276. json_object_put(data);
  8277. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8278. json_object_put(response);
  8279. }
  8280. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8281. {
  8282. json_object *data;
  8283. data = json_tokener_parse(tempdata);
  8284. if(!is_error(data))
  8285. {
  8286. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8287. if(json_object_object_get(data, "idToken") != NULL)
  8288. {
  8289. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8290. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8291. }
  8292. if(json_object_object_get(data, "price") != NULL)
  8293. {
  8294. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8295. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8296. }
  8297. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8298. }
  8299. else
  8300. {
  8301. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8302. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8303. }
  8304. json_object_put(data);
  8305. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8306. json_object_put(response);
  8307. }
  8308. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8309. {
  8310. json_object *data;
  8311. data = json_tokener_parse(tempdata);
  8312. if(!is_error(data))
  8313. {
  8314. if(json_object_object_get(data, "txId") != NULL)
  8315. {
  8316. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8317. for(int idx = 0;idx<gunTotalNumber;idx++)
  8318. {
  8319. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8320. {
  8321. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8322. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8323. if(json_object_object_get(data, "description") != NULL)
  8324. {
  8325. // California pricing V1.0
  8326. DEBUG_INFO("California pricing V1.0\n");
  8327. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8328. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8329. }
  8330. else
  8331. {
  8332. // California pricing V1.1
  8333. DEBUG_INFO("California pricing V1.1\n");
  8334. if(json_object_object_get(data, "timestamp") != NULL)
  8335. {
  8336. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8337. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8338. }
  8339. if(json_object_object_get(data, "meterValue") != NULL)
  8340. {
  8341. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8342. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8343. }
  8344. if(json_object_object_get(data, "cost") != NULL)
  8345. {
  8346. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8347. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8348. }
  8349. if(json_object_object_get(data, "state") != NULL)
  8350. {
  8351. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8352. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8353. }
  8354. if(json_object_object_get(data, "chargingPrice") != NULL)
  8355. {
  8356. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8357. {
  8358. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8359. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8360. }
  8361. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8362. {
  8363. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8364. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8365. }
  8366. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8367. {
  8368. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8369. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8370. }
  8371. }
  8372. if(json_object_object_get(data, "idlePrice") != NULL)
  8373. {
  8374. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8375. {
  8376. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8377. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8378. }
  8379. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8380. {
  8381. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8382. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8383. }
  8384. }
  8385. if(json_object_object_get(data, "nextPeriod") != NULL)
  8386. {
  8387. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8388. {
  8389. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8390. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8391. }
  8392. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8393. {
  8394. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8395. {
  8396. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  8397. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  8398. }
  8399. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8400. {
  8401. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  8402. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  8403. }
  8404. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8405. {
  8406. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  8407. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  8408. }
  8409. }
  8410. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8411. {
  8412. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8413. {
  8414. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  8415. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  8416. }
  8417. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8418. {
  8419. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  8420. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  8421. }
  8422. }
  8423. }
  8424. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8425. {
  8426. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8427. {
  8428. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8429. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8430. }
  8431. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8432. {
  8433. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8434. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8435. }
  8436. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8437. {
  8438. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8439. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8440. }
  8441. }
  8442. }
  8443. }
  8444. }
  8445. }
  8446. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8447. }
  8448. else
  8449. {
  8450. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8451. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8452. }
  8453. json_object_put(data);
  8454. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8455. json_object_put(response);
  8456. }
  8457. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8458. {
  8459. json_object *data;
  8460. data = json_tokener_parse(tempdata);
  8461. if(!is_error(data))
  8462. {
  8463. if(json_object_object_get(data, "txId") != NULL)
  8464. {
  8465. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8466. for(int idx = 0;idx<gunTotalNumber;idx++)
  8467. {
  8468. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8469. {
  8470. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8471. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8472. if(json_object_object_get(data, "description") != NULL)
  8473. {
  8474. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8475. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8476. }
  8477. }
  8478. }
  8479. }
  8480. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8481. }
  8482. else
  8483. {
  8484. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8485. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8486. }
  8487. json_object_put(data);
  8488. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8489. json_object_put(response);
  8490. }
  8491. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8492. {
  8493. json_object *data;
  8494. data = json_tokener_parse(tempdata);
  8495. if(!is_error(data))
  8496. {
  8497. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8498. if(json_object_object_get(data, "Content_Type") != NULL)
  8499. {
  8500. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  8501. {
  8502. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8503. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8504. {
  8505. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8506. }
  8507. }
  8508. else
  8509. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8510. }
  8511. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8512. }
  8513. else
  8514. {
  8515. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8516. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8517. }
  8518. json_object_put(data);
  8519. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8520. json_object_put(response);
  8521. }
  8522. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8523. {
  8524. json_object *data;
  8525. data = json_tokener_parse(tempdata);
  8526. if(!is_error(data))
  8527. {
  8528. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8529. if(json_object_object_get(data, "Page_Index") != NULL)
  8530. {
  8531. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8532. }
  8533. if(json_object_object_get(data, "Duration") != NULL)
  8534. {
  8535. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8536. }
  8537. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8538. }
  8539. else
  8540. {
  8541. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8542. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8543. }
  8544. json_object_put(data);
  8545. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8546. json_object_put(response);
  8547. }
  8548. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8549. {
  8550. json_object *data;
  8551. data = json_tokener_parse(tempdata);
  8552. if(!is_error(data))
  8553. {
  8554. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8555. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8556. {
  8557. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8558. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8559. else
  8560. {
  8561. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8562. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8563. }
  8564. }
  8565. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8566. {
  8567. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8568. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8569. else
  8570. {
  8571. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8572. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8573. }
  8574. }
  8575. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8576. {
  8577. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8578. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8579. else
  8580. {
  8581. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8582. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8583. }
  8584. }
  8585. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8586. {
  8587. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8588. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8589. else
  8590. {
  8591. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8592. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8593. }
  8594. }
  8595. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8596. {
  8597. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8598. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8599. else
  8600. {
  8601. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8602. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8603. }
  8604. }
  8605. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8606. {
  8607. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8608. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8609. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8610. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8611. else
  8612. {
  8613. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8614. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8615. }
  8616. }
  8617. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8618. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8619. }
  8620. else
  8621. {
  8622. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8623. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8624. }
  8625. json_object_put(data);
  8626. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8627. json_object_put(response);
  8628. }
  8629. else
  8630. {
  8631. // Can not find valid message id
  8632. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8633. }
  8634. }
  8635. else
  8636. {
  8637. // Payload is null
  8638. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8639. }
  8640. LWS_Send(message);
  8641. return result;
  8642. }
  8643. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8644. {
  8645. mtrace();
  8646. int result = FAIL;
  8647. int connectorIdInt, durationInt;
  8648. char chargingRateUnitStr[4]={0};
  8649. char comfirmstr[20];
  8650. int confirmPeriods = 0;
  8651. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8652. json_object *GetCompositeSchedule;
  8653. GetCompositeSchedule = json_tokener_parse(payload);
  8654. if(!is_error(GetCompositeSchedule))
  8655. {
  8656. // Required data
  8657. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8658. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8659. else
  8660. connectorIdInt = -1;
  8661. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8662. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8663. else
  8664. durationInt = 86400;
  8665. // Optional data
  8666. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8667. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8668. }
  8669. json_object_put(GetCompositeSchedule);
  8670. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8671. if((connectorIdInt == 0) ||
  8672. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8673. {
  8674. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8675. struct StructChargingProfile tmpProfile[1];
  8676. if(strstr(chargingRateUnitStr, "W") != NULL)
  8677. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8678. else
  8679. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8680. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8681. {
  8682. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8683. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8684. }
  8685. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8686. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8687. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8688. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8689. {
  8690. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8691. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8692. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8693. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8694. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8695. {
  8696. confirmPeriods = idx;
  8697. break;
  8698. }
  8699. }
  8700. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8701. {
  8702. confirmPeriods += 1;
  8703. }
  8704. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8705. }
  8706. else
  8707. {
  8708. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8709. }
  8710. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8711. return result;
  8712. }
  8713. int handleGetConfigurationRequest(char *uuid, char *payload)
  8714. {
  8715. mtrace();
  8716. int result = FAIL;
  8717. int MaxKeySupported = 0;
  8718. int n_keys = 0;
  8719. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8720. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8721. json_object *GetConfiguration;
  8722. GetConfiguration = json_tokener_parse(payload);
  8723. if(!is_error(GetConfiguration))
  8724. {
  8725. // Optional data
  8726. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8727. {
  8728. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8729. {
  8730. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8731. n_keys = idx + 1;
  8732. }
  8733. }
  8734. }
  8735. json_object_put(GetConfiguration);
  8736. UnknownKeynum = 0;
  8737. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8738. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8739. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8740. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8741. if(n_keys != 0)
  8742. {
  8743. for(int i=0;i<n_keys;i++)
  8744. {
  8745. getKeyValue(requestKey[i]);
  8746. }
  8747. }
  8748. else
  8749. {
  8750. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8751. getKeyValue("");
  8752. }
  8753. processUnkownKey();
  8754. sendGetConfigurationConfirmation(uuid);
  8755. return result;
  8756. }
  8757. static char fnamePlusPath[100]={0};
  8758. static char fnamePWithNoPath[60]={0};
  8759. void checkUploadLog(void)
  8760. {
  8761. FILE *fp;
  8762. /* Open the command for reading. */
  8763. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8764. if (fp == NULL) {
  8765. DEBUG_WARN("Failed to run command\n" );
  8766. exit(1);
  8767. }
  8768. int ftppathlen = 0;
  8769. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8770. int i = 0;
  8771. /* Read the output a line at a time - output it. */
  8772. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8773. if(i==0)
  8774. {
  8775. ftppathlen = strlen(fnamePlusPath);
  8776. DEBUG_INFO("%s\n", fnamePlusPath);
  8777. fnamePlusPath[ftppathlen]='\0';
  8778. break;
  8779. }
  8780. i= i+1;
  8781. }
  8782. /* close */
  8783. pclose(fp);
  8784. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8785. {
  8786. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8787. {
  8788. fnamePlusPath[k]='\0';
  8789. }
  8790. }
  8791. i=1;
  8792. //char fname[60]={0};
  8793. while(i < ftppathlen)
  8794. {
  8795. int len=ftppathlen-i;
  8796. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8797. {
  8798. DEBUG_INFO("compare '/' all right\n");
  8799. break;
  8800. }
  8801. i=i+1;
  8802. }
  8803. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8804. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8805. fnamePWithNoPath[i+1] = '\0';
  8806. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8807. {
  8808. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8809. {
  8810. fnamePWithNoPath[j]='\0';
  8811. }
  8812. }
  8813. FILE* fp1 = fopen(fnamePlusPath, "r");
  8814. if (fp1)
  8815. {
  8816. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8817. // file exists
  8818. fclose(fp1);
  8819. }
  8820. else
  8821. {
  8822. // file doesn't exist
  8823. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8824. }
  8825. }
  8826. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8827. {
  8828. mtrace();
  8829. int result = FAIL;
  8830. time_t CurrentTime;
  8831. struct tm *tm;
  8832. pthread_t th_Status;
  8833. CurrentTime = time(NULL);
  8834. tm = localtime(&CurrentTime);
  8835. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  8836. 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);
  8837. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8838. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8839. return result;
  8840. }
  8841. void* GetDiagnosticsProcess(void* data)
  8842. {
  8843. pthread_detach(pthread_self());
  8844. mtrace();
  8845. int retriesInt=0, retryIntervalInt=0;
  8846. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8847. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  8848. int port=0;
  8849. int isSuccess = FALSE;
  8850. char cmdBuf[2048];
  8851. struct tm *tmNow;
  8852. time_t CurrentTime;
  8853. struct tm tmStart;
  8854. struct tm tmStop;
  8855. CurrentTime = time(NULL);
  8856. tmNow=localtime(&CurrentTime);
  8857. uint16_t targetYear, targetMonth;
  8858. json_object *GetDiagnostics;
  8859. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8860. GetDiagnostics = json_tokener_parse(data);
  8861. if(!is_error(GetDiagnostics))
  8862. {
  8863. // Required data
  8864. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8865. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8866. // Optional data
  8867. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8868. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8869. else
  8870. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8871. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8872. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8873. else
  8874. retryIntervalInt = 30;
  8875. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8876. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8877. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8878. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8879. }
  8880. json_object_put(GetDiagnostics);
  8881. // Pack log to compress file
  8882. 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) &&
  8883. (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))
  8884. {
  8885. // Pack system log
  8886. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8887. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8888. targetYear = tmStart.tm_year;
  8889. targetMonth = tmStart.tm_mon;
  8890. do
  8891. {
  8892. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8893. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8894. if(targetMonth+1>=13)
  8895. {
  8896. targetYear += 1;
  8897. targetMonth = 1;
  8898. }
  8899. else
  8900. {
  8901. targetMonth += 1;
  8902. }
  8903. }while((targetYear < (tmNow->tm_year+1900)) ||
  8904. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8905. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8906. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8907. system(cmdBuf);
  8908. // Pack charging & event log
  8909. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8910. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8911. targetYear = tmStart.tm_year;
  8912. targetMonth = tmStart.tm_mon;
  8913. do
  8914. {
  8915. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8916. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8917. if(targetMonth+1>=13)
  8918. {
  8919. targetYear += 1;
  8920. targetMonth = 1;
  8921. }
  8922. else
  8923. {
  8924. targetMonth += 1;
  8925. }
  8926. }while((targetYear < (tmNow->tm_year+1900)) ||
  8927. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8928. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8929. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8930. system(cmdBuf);
  8931. // Combine log file
  8932. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8933. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8934. }
  8935. else
  8936. {
  8937. system("exec /root/logPackTools 'log' 6");
  8938. }
  8939. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8940. system(cmdBuf);
  8941. checkUploadLog();
  8942. //****************location*******************/
  8943. if(strcmp(locationstr,"")==0)
  8944. {
  8945. DEBUG_INFO("location is <Empty>!\n");
  8946. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8947. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8948. goto end;
  8949. }
  8950. memset(protocol, 0, ARRAY_SIZE(protocol));
  8951. memset(user, 0, ARRAY_SIZE(user) );
  8952. memset(password, 0, ARRAY_SIZE(password));
  8953. memset(host, 0, ARRAY_SIZE(host));
  8954. memset(path, 0, ARRAY_SIZE(path));
  8955. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8956. memset(host1, 0, ARRAY_SIZE(host1));
  8957. memset(path1, 0, ARRAY_SIZE(path1));
  8958. /*location: ftp://user:password@host:port/path*/
  8959. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8960. if((access(fnamePlusPath,F_OK))!=-1)
  8961. {
  8962. DEBUG_INFO("fnamePlusPath exist.\n");
  8963. }
  8964. else
  8965. {
  8966. DEBUG_INFO("fnamePlusPath not exist!\n");
  8967. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8968. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8969. goto end;
  8970. }
  8971. if(strchr(locationstr,'@')==NULL)
  8972. {
  8973. sscanf(locationstr,
  8974. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8975. protocol, host, &port, path);
  8976. strcpy(user,"anonymous");
  8977. strcpy(password,"");
  8978. }
  8979. else
  8980. {
  8981. //DEBUG_INFO("pch=%s\n", pch);
  8982. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8983. protocol, user, password, host, &port, path);
  8984. }
  8985. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8986. {
  8987. DEBUG_INFO("protocol is not ftp/http ! \n");
  8988. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8989. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8990. goto end;
  8991. }
  8992. if(strncmp(locationstr,"http", 4) == 0)
  8993. {
  8994. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8995. sprintf(ftppath,"/%s", path);
  8996. do
  8997. {
  8998. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8999. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9000. sleep(3);
  9001. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9002. if(!isSuccess)
  9003. {
  9004. DEBUG_INFO("Diagnostics fail.\n");
  9005. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9006. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9007. sleep(retryIntervalInt);
  9008. }
  9009. else
  9010. {
  9011. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9012. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9013. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9014. }
  9015. retriesInt--;
  9016. }while((isSuccess == 0)&&(retriesInt >= 0));
  9017. }
  9018. else
  9019. {
  9020. sscanf(host,"%[^/]%s",host1, path1);
  9021. if(strlen(path) > 0)
  9022. sprintf(ftppath,"/%s", path);
  9023. else
  9024. sprintf(ftppath,"/%s", path1);
  9025. int ftppathlen=strlen(ftppath);
  9026. int i=1;
  9027. char filenametemp[50];
  9028. while(i < ftppathlen)
  9029. {
  9030. int len=ftppathlen-i;
  9031. if(ftppath[len]== 47) // '/' ascll code: 47
  9032. {
  9033. DEBUG_INFO("find '/' all right\n");
  9034. break;
  9035. }
  9036. i=i+1;
  9037. }
  9038. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9039. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9040. filenametemp[i+1] = 0;
  9041. if(port == 0)
  9042. port = 21;
  9043. do
  9044. {
  9045. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9046. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9047. sleep(3);
  9048. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9049. if(!isSuccess)
  9050. {
  9051. DEBUG_INFO("Diagnostics fail.\n");
  9052. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9053. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9054. sleep(retryIntervalInt);
  9055. }
  9056. else
  9057. {
  9058. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9059. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9060. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9061. }
  9062. retriesInt--;
  9063. }while((!isSuccess)&&(retriesInt >= 0));
  9064. }
  9065. end:
  9066. system("rm -f /mnt/*");
  9067. sleep(5);
  9068. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9069. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9070. pthread_exit(NULL);
  9071. }
  9072. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9073. {
  9074. mtrace();
  9075. int result = FAIL;
  9076. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9077. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9078. {
  9079. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9080. locallistVersion = -1;
  9081. }
  9082. else
  9083. {
  9084. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9085. OCPP_getListVerion();
  9086. }
  9087. //from db.OCPP_getListVerion
  9088. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9089. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9090. sendGetLocalListVersionConfirmation(uuid,"");
  9091. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9092. return result;
  9093. }
  9094. int handleRemoteStartRequest(char *uuid, char *payload)
  9095. {
  9096. mtrace();
  9097. int result = FAIL;
  9098. int connectorIdInt=-1;
  9099. int tempIndex = 0;
  9100. int connectorIdIsNULL, chargingProfileIsNULL;
  9101. char comfirmstr[20]={0};
  9102. char cmdBuf[512];
  9103. json_object *RemoteStartTransaction;
  9104. FILE *fp;
  9105. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9106. if(server_pending == TRUE)
  9107. {
  9108. return 0;
  9109. }
  9110. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9111. RemoteStartTransaction = json_tokener_parse(payload);
  9112. if(!is_error(RemoteStartTransaction))
  9113. {
  9114. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9115. {
  9116. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9117. }
  9118. else
  9119. {
  9120. connectorIdIsNULL = TRUE;
  9121. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9122. {
  9123. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9124. {
  9125. connectorIdIsNULL = FALSE;
  9126. connectorIdInt = (gun_index+1);
  9127. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9128. break;
  9129. }
  9130. }
  9131. }
  9132. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9133. {
  9134. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9135. // Required data
  9136. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9137. // Optional data
  9138. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9139. {
  9140. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9141. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9142. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9143. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9144. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9145. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9146. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9147. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9148. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9149. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9150. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9151. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9152. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9153. {
  9154. 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")));
  9155. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9156. 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"));
  9157. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9158. 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"));
  9159. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9160. 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")));
  9161. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9162. {
  9163. 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++)
  9164. {
  9165. 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"));
  9166. 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"));
  9167. 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)
  9168. 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"));
  9169. }
  9170. }
  9171. }
  9172. }
  9173. else
  9174. {
  9175. chargingProfileIsNULL = TRUE;
  9176. }
  9177. }
  9178. }
  9179. else
  9180. {
  9181. connectorIdIsNULL = TRUE;
  9182. }
  9183. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9184. {
  9185. DEBUG_WARN("Connector id is NULL\n.");
  9186. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9187. goto end;
  9188. }
  9189. /*
  9190. enum _SYSTEM_STATUS
  9191. {
  9192. S_BOOTING = 0,
  9193. S_IDLE, = 1
  9194. S_AUTHORIZING, = 2
  9195. S_REASSIGN_CHECK, = 3
  9196. S_REASSIGN, = 4
  9197. S_PRECHARGE, = 5
  9198. S_PREPARING_FOR_EV, = 6
  9199. S_PREPARING_FOR_EVSE, = 7
  9200. S_CHARGING, = 8
  9201. S_TERMINATING, = 9
  9202. S_COMPLETE, = 10
  9203. S_ALARM, = 11
  9204. S_FAULT = 12
  9205. }
  9206. */
  9207. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9208. {
  9209. //check Transaction active
  9210. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9211. {
  9212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9213. {
  9214. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9215. }
  9216. else
  9217. {
  9218. tempIndex = connectorIdInt -1;
  9219. }
  9220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9221. {
  9222. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9223. {
  9224. 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))
  9225. {
  9226. //Reserved
  9227. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9228. }
  9229. 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))
  9230. {
  9231. //Reserved
  9232. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9233. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9234. goto end;
  9235. }
  9236. else
  9237. {
  9238. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9239. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9240. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9241. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9242. {
  9243. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9244. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9245. goto end;
  9246. }
  9247. }//END FOR ELSE
  9248. }
  9249. }// END FOR CHAdeMO_QUANTITY
  9250. }
  9251. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9252. {
  9253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9254. {
  9255. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9256. }
  9257. else
  9258. {
  9259. tempIndex = connectorIdInt -1;
  9260. }
  9261. for (int index = 0; index < CCS_QUANTITY; index++)
  9262. {
  9263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9264. {
  9265. 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))
  9266. {
  9267. //Reserved
  9268. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9269. }
  9270. 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))
  9271. {
  9272. //Reserved
  9273. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9274. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9275. goto end;
  9276. }
  9277. else
  9278. {
  9279. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9280. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9281. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9282. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9283. {
  9284. DEBUG_WARN("CCS connector not allow start\n.");
  9285. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9286. goto end;
  9287. }
  9288. }// END FOR ELSE
  9289. }
  9290. }// END FOR CCS_QUANTITY
  9291. }
  9292. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9293. {
  9294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9295. {
  9296. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9297. }
  9298. else
  9299. {
  9300. tempIndex = connectorIdInt -1;
  9301. }
  9302. for (int index = 0; index < GB_QUANTITY; index++)
  9303. {
  9304. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9305. {
  9306. 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))
  9307. {
  9308. //Reserved
  9309. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9310. }
  9311. 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))
  9312. {
  9313. //Reserved
  9314. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9316. goto end;
  9317. }
  9318. else
  9319. {
  9320. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9321. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9322. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9323. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9324. {
  9325. DEBUG_WARN("GB connector not allow start\n.");
  9326. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9327. goto end;
  9328. }
  9329. }// END FOR ELSE
  9330. }
  9331. } // END FOR GB_QUANTITY
  9332. }
  9333. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9334. {
  9335. tempIndex = connectorIdInt -1;
  9336. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9337. {
  9338. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9339. {
  9340. 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))
  9341. {
  9342. //Reserved
  9343. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9344. }
  9345. 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))
  9346. {
  9347. //Reserved
  9348. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9349. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9350. goto end;
  9351. }
  9352. else
  9353. {
  9354. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9355. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9356. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9357. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9358. {
  9359. DEBUG_WARN("GB connector not allow start\n.");
  9360. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9361. goto end;
  9362. }
  9363. }// END FOR ELSE
  9364. }
  9365. } // END FOR GB_QUANTITY
  9366. }
  9367. else
  9368. {
  9369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9370. {
  9371. tempIndex = 2;
  9372. }
  9373. else
  9374. {
  9375. tempIndex = connectorIdInt -1;
  9376. }
  9377. for (int index = 0; index < AC_QUANTITY; index++)
  9378. {
  9379. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9380. {
  9381. 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))
  9382. {
  9383. //Reserved
  9384. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9385. }
  9386. 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))
  9387. {
  9388. //Reserved
  9389. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9390. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9391. goto end;
  9392. }
  9393. else
  9394. {
  9395. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9396. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9397. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9398. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9399. {
  9400. DEBUG_WARN("AC connector not allow start\n.");
  9401. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9402. goto end;
  9403. }
  9404. }//END FOR ELSE
  9405. }
  9406. }// END FOR AC_QUANTITY
  9407. }
  9408. if(chargingProfileIsNULL == FALSE)
  9409. {
  9410. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9411. {
  9412. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9413. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9414. //memset idTag
  9415. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9416. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9417. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9418. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9419. // Save profile to file
  9420. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9421. system(cmdBuf);
  9422. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9423. fp = fopen(cmdBuf, "w");
  9424. 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));
  9425. fclose(fp);
  9426. }
  9427. else
  9428. {
  9429. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9430. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9431. }
  9432. }
  9433. else
  9434. {
  9435. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9436. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9437. //memset idTag
  9438. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9439. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9440. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9441. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9442. }
  9443. }
  9444. else
  9445. {
  9446. DEBUG_WARN("Connector id over\n.");
  9447. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9448. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9449. }
  9450. end:
  9451. json_object_put(RemoteStartTransaction);
  9452. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9453. {
  9454. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9455. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9456. }
  9457. //OCPP send RemoteStartConfirmation by first.
  9458. sendRemoteStartConfirmation(uuid, comfirmstr);
  9459. return result;
  9460. }
  9461. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9462. {
  9463. mtrace();
  9464. int result = FAIL;
  9465. int match = FALSE;
  9466. int GunNO = 0;
  9467. int tempIndex = 0;
  9468. int transactionIdInt=0;
  9469. int transactionIdIsNULL= TRUE;
  9470. char comfirmstr[20];
  9471. json_object *RemoteStopTransaction;
  9472. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9473. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9474. if(server_pending == TRUE)
  9475. {
  9476. return 0;
  9477. }
  9478. RemoteStopTransaction = json_tokener_parse(payload);
  9479. if(!is_error(RemoteStopTransaction))
  9480. {
  9481. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9482. {
  9483. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9484. transactionIdIsNULL = FALSE;
  9485. }
  9486. }
  9487. json_object_put(RemoteStopTransaction);
  9488. if(transactionIdIsNULL == FALSE)
  9489. {
  9490. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9491. {
  9492. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9493. {
  9494. //check Transaction active
  9495. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9496. {
  9497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9498. {
  9499. tempIndex = ((gun_index==2) ? 1: 0);
  9500. }
  9501. else
  9502. {
  9503. tempIndex = gun_index;
  9504. }
  9505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9506. {
  9507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9508. {
  9509. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9510. {
  9511. match = TRUE;
  9512. GunNO = gun_index;
  9513. }
  9514. }
  9515. }// END FOR CHAdeMO_QUANTITY
  9516. }
  9517. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9518. {
  9519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9520. {
  9521. tempIndex = ((gun_index==2) ? 1: 0);
  9522. }
  9523. else
  9524. {
  9525. tempIndex = gun_index;
  9526. }
  9527. for (int index = 0; index < CCS_QUANTITY; index++)
  9528. {
  9529. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9530. {
  9531. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9532. {
  9533. match = TRUE;
  9534. GunNO = gun_index;
  9535. }
  9536. }
  9537. }// END FOR CCS_QUANTITY
  9538. }
  9539. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9540. {
  9541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9542. {
  9543. tempIndex = ((gun_index==2) ? 1: 0);
  9544. }
  9545. else
  9546. {
  9547. tempIndex = gun_index;
  9548. }
  9549. for (int index = 0; index < GB_QUANTITY; index++)
  9550. {
  9551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9552. {
  9553. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9554. {
  9555. match = TRUE;
  9556. GunNO = gun_index;
  9557. }
  9558. }
  9559. }// END FOR GB_QUANTITY
  9560. }
  9561. else if(gunType[gun_index] == GUN_TYPE_DO)
  9562. {
  9563. tempIndex = gun_index;
  9564. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9565. {
  9566. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9567. {
  9568. 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
  9569. {
  9570. match = TRUE;
  9571. GunNO = gun_index;
  9572. }
  9573. }
  9574. }// END FOR GB_QUANTITY
  9575. }
  9576. else
  9577. {
  9578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9579. {
  9580. tempIndex = 2;
  9581. }
  9582. else
  9583. {
  9584. tempIndex = gun_index;
  9585. }
  9586. for (int index = 0; index < AC_QUANTITY; index++)
  9587. {
  9588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9589. {
  9590. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9591. {
  9592. match = TRUE;
  9593. GunNO = gun_index;
  9594. }
  9595. }
  9596. }// END FOR CHAdeMO_QUANTITY
  9597. } // END FOR AC ELSE
  9598. }// CHECK IF ResponseTransactionId == transactionIdInt
  9599. }//END FOR
  9600. if( match == TRUE)
  9601. {
  9602. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9603. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9604. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9605. }
  9606. else
  9607. {
  9608. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9609. }
  9610. }
  9611. else
  9612. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9613. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9614. return result;
  9615. }
  9616. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9617. {
  9618. mtrace();
  9619. int result = FAIL;
  9620. int connectorIdInt=0, reservationIdInt=0;
  9621. int tempIndex = 0;
  9622. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9623. char comfirmstr[20]={0};
  9624. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9625. int c = 0;
  9626. char *loc;
  9627. //char *ptr;
  9628. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9629. strcpy(sstrtemp, stringtrimspace(payload));
  9630. //***(1)connectorId ****/
  9631. c=0;
  9632. loc = strstr(sstrtemp, "connectorId");
  9633. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9634. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9635. {
  9636. sstr[c] = loc[strlen("connectorId")+2+c];
  9637. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9638. c++;
  9639. }
  9640. sstr[c] = '\0';
  9641. connectorIdInt = atoi(sstr);
  9642. //***(2)expiryDate ****/
  9643. loc = strstr(sstrtemp, "expiryDate");
  9644. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9645. c = 0;
  9646. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9647. {
  9648. sstr[c] = loc[3+strlen("expiryDate")+c];
  9649. c++;
  9650. }
  9651. sstr[c] = '\0';
  9652. strcpy(expiryDatestr, sstr);
  9653. //***(3)idTag ****/
  9654. loc = strstr(sstrtemp, "idTag");
  9655. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9656. c = 0;
  9657. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9658. {
  9659. sstr[c] = loc[3+strlen("idTag")+c];
  9660. c++;
  9661. }
  9662. sstr[c] = '\0';
  9663. strcpy(idTagstr, sstr);
  9664. //***(4)parentIdTag ****/
  9665. loc = strstr(sstrtemp, "parentIdTag");
  9666. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9667. c = 0;
  9668. if(loc == NULL)
  9669. {
  9670. strcpy(parentIdTagstr, "");
  9671. }
  9672. else
  9673. {
  9674. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9675. {
  9676. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9677. c++;
  9678. }
  9679. sstr[c] = '\0';
  9680. strcpy(parentIdTagstr, sstr);
  9681. }
  9682. //***(5)reservationId ****/
  9683. c=0;
  9684. loc = strstr(sstrtemp, "reservationId");
  9685. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9686. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9687. {
  9688. sstr[c] = loc[strlen("reservationId")+2+c];
  9689. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9690. c++;
  9691. }
  9692. sstr[c] = '\0';
  9693. reservationIdInt = atoi(sstr);
  9694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9695. /*
  9696. enum SYSTEM_STATUS
  9697. {
  9698. SYS_MODE_BOOTING = 0,
  9699. SYS_MODE_IDLE = 1,
  9700. SYS_MODE_AUTHORIZING = 2,
  9701. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9702. SYS_MODE_REASSIGN = 4,
  9703. SYS_MODE_PREPARING = 5,
  9704. SYS_MODE_PREPARE_FOR_EV = 6,
  9705. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9706. SYS_MODE_CHARGING = 8,
  9707. SYS_MODE_TERMINATING = 9,
  9708. SYS_MODE_COMPLETE = 10,
  9709. SYS_MODE_ALARM = 11,
  9710. SYS_MODE_FAULT = 12,
  9711. SYS_MODE_RESERVATION = 13,
  9712. SYS_MODE_BOOKING = 14,
  9713. SYS_MODE_MAINTAIN = 15,
  9714. SYS_MODE_DEBUG = 16,
  9715. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9716. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9717. SYS_MODE_UPDATE = 19
  9718. };
  9719. */
  9720. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9721. {
  9722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9723. goto end;
  9724. }
  9725. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9726. {
  9727. //check Transaction active
  9728. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9729. {
  9730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9731. {
  9732. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9733. }
  9734. else
  9735. {
  9736. tempIndex = connectorIdInt -1;
  9737. }
  9738. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9739. {
  9740. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9741. {
  9742. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9743. {
  9744. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9745. {
  9746. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9747. {
  9748. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9750. }
  9751. 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'))
  9752. {
  9753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9754. }
  9755. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9756. {
  9757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9758. }
  9759. else
  9760. {
  9761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9762. }
  9763. }
  9764. 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
  9765. {
  9766. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9767. }
  9768. }
  9769. else
  9770. {
  9771. //replace reservation
  9772. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9774. }
  9775. }
  9776. } // END FOR CHAdeMO_QUANTITY
  9777. }
  9778. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9779. {
  9780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9781. {
  9782. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9783. }
  9784. else
  9785. {
  9786. tempIndex = connectorIdInt -1;
  9787. }
  9788. for (int index = 0; index < CCS_QUANTITY; index++)
  9789. {
  9790. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9791. {
  9792. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9793. {
  9794. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9795. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9796. {
  9797. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9798. {
  9799. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9801. }
  9802. 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'))
  9803. {
  9804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9805. }
  9806. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9807. {
  9808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9809. }
  9810. else
  9811. {
  9812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9813. }
  9814. }
  9815. 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
  9816. {
  9817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9818. }
  9819. }
  9820. else
  9821. {
  9822. //replace reservation
  9823. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9825. }
  9826. }
  9827. } // END FOR CCS_QUANTITY
  9828. }
  9829. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9830. {
  9831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9832. {
  9833. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9834. }
  9835. else
  9836. {
  9837. tempIndex = connectorIdInt -1;
  9838. }
  9839. for (int index = 0; index < GB_QUANTITY; index++)
  9840. {
  9841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9842. {
  9843. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9844. {
  9845. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9846. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9847. {
  9848. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9849. {
  9850. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9851. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9852. }
  9853. 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'))
  9854. {
  9855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9856. }
  9857. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9858. {
  9859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9860. }
  9861. else
  9862. {
  9863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9864. }
  9865. }
  9866. 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
  9867. {
  9868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9869. }
  9870. }
  9871. else
  9872. {
  9873. //replace reservation
  9874. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9876. }
  9877. }
  9878. }// END FOR GB_QUANTITY
  9879. }
  9880. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9881. {
  9882. tempIndex = connectorIdInt -1;
  9883. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9884. {
  9885. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9886. {
  9887. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9888. {
  9889. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9890. 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
  9891. {
  9892. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9893. {
  9894. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9896. }
  9897. 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'))
  9898. {
  9899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9900. }
  9901. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9902. {
  9903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9904. }
  9905. else
  9906. {
  9907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9908. }
  9909. }
  9910. 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
  9911. {
  9912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9913. }
  9914. }
  9915. else
  9916. {
  9917. //replace reservation
  9918. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9920. }
  9921. }
  9922. }// END FOR GB_QUANTITY
  9923. }
  9924. else
  9925. {
  9926. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9927. {
  9928. tempIndex = 2;
  9929. }
  9930. else
  9931. {
  9932. tempIndex = (connectorIdInt -1);
  9933. }
  9934. for (int index = 0; index < AC_QUANTITY; index++)
  9935. {
  9936. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9937. {
  9938. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9939. {
  9940. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9941. {
  9942. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9943. {
  9944. 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))
  9945. {
  9946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9947. }
  9948. else
  9949. {
  9950. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9952. }
  9953. }
  9954. 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'))
  9955. {
  9956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9957. }
  9958. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9959. {
  9960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9961. }
  9962. else
  9963. {
  9964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9965. }
  9966. }
  9967. 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
  9968. {
  9969. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9970. }
  9971. }
  9972. else
  9973. {
  9974. //replace reservation
  9975. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9977. }
  9978. }
  9979. } // END FOR AC_QUANTITY
  9980. }
  9981. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9982. }
  9983. else if(connectorIdInt == 0)
  9984. {
  9985. //check Transaction active
  9986. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9987. {
  9988. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9989. {
  9990. 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'))
  9991. {
  9992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9993. goto end;
  9994. }
  9995. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9996. {
  9997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9998. goto end;
  9999. }
  10000. 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
  10001. {
  10002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10003. goto end;
  10004. }
  10005. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10006. {
  10007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10008. goto end;
  10009. }
  10010. }
  10011. }// END FOR CHAdeMO_QUANTITY
  10012. for (int index = 0; index < CCS_QUANTITY; index++)
  10013. {
  10014. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10015. {
  10016. 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'))
  10017. {
  10018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10019. goto end;
  10020. }
  10021. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10022. {
  10023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10024. goto end;
  10025. }
  10026. 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
  10027. {
  10028. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10029. goto end;
  10030. }
  10031. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10032. {
  10033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10034. goto end;
  10035. }
  10036. }
  10037. } // END FOR CCS_QUANTITY
  10038. for (int index = 0; index < GB_QUANTITY; index++)
  10039. {
  10040. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10041. {
  10042. 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'))
  10043. {
  10044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10045. goto end;
  10046. }
  10047. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10048. {
  10049. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10050. goto end;
  10051. }
  10052. 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
  10053. {
  10054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10055. goto end;
  10056. }
  10057. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10058. {
  10059. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10060. goto end;
  10061. }
  10062. }
  10063. } // END FOR GB_QUANTITY
  10064. for (int index = 0; index < AC_QUANTITY; index++)
  10065. {
  10066. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10067. {
  10068. 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'))
  10069. {
  10070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10071. goto end;
  10072. }
  10073. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10074. {
  10075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10076. goto end;
  10077. }
  10078. 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
  10079. {
  10080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10081. goto end;
  10082. }
  10083. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10084. {
  10085. 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))
  10086. {
  10087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10088. goto end;
  10089. }
  10090. }
  10091. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10092. {
  10093. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10094. goto end;
  10095. }
  10096. }
  10097. }// END FOR AC_QUANTITY
  10098. //The connectorId is 0
  10099. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10101. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10102. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10103. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10104. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10105. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10106. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10107. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10108. result = TRUE;
  10109. return result;
  10110. }
  10111. else
  10112. {
  10113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10114. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10115. }
  10116. if(strcmp(comfirmstr,"Accepted") == 0)
  10117. {
  10118. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10119. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10120. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10121. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10122. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10123. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10124. result = TRUE;
  10125. return result;
  10126. }
  10127. end:
  10128. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10129. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10130. return result;
  10131. }
  10132. int handleResetRequest(char *uuid, char *payload)
  10133. {
  10134. mtrace();
  10135. int result = FAIL;
  10136. char sstr[10]={0},sstrtemp[30]={ 0 };
  10137. char typestr[10]={0};
  10138. char comfirmstr[20]={0};
  10139. int c = 0;
  10140. char *loc;
  10141. DEBUG_INFO("handleResetRequest...\n");
  10142. strcpy(sstrtemp, stringtrimspace(payload));
  10143. loc = strstr(sstrtemp, "type");
  10144. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10145. c = 0;
  10146. while (loc[3+strlen("type")+c] != '\"')
  10147. {
  10148. sstr[c] = loc[3+strlen("type")+c];
  10149. c++;
  10150. }
  10151. sstr[c] = '\0';
  10152. strcpy(typestr,sstr);
  10153. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10154. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10155. {
  10156. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10157. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10158. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10159. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10160. }
  10161. else
  10162. {
  10163. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10164. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10165. result = PASS;
  10166. }
  10167. sendResetConfirmation(uuid, comfirmstr);
  10168. return result;
  10169. }
  10170. int handleSendLocalListRequest(char *uuid, char *payload)
  10171. {
  10172. mtrace();
  10173. int result = FAIL;
  10174. char comfirmstr[20];
  10175. int checkState_Faulted = FALSE;
  10176. json_object *SendLocalList;
  10177. DEBUG_INFO("handleSendLocalListRequest...\n");
  10178. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10179. {
  10180. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10181. goto end;
  10182. }
  10183. //check Charge Point state
  10184. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10185. {
  10186. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10187. {
  10188. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10189. }
  10190. }
  10191. for (int index = 0; index < CCS_QUANTITY; index++)
  10192. {
  10193. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10194. {
  10195. checkState_Faulted = TRUE; //OCPP Status
  10196. }
  10197. }
  10198. for (int index = 0; index < GB_QUANTITY; index++)
  10199. {
  10200. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10201. {
  10202. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10203. }
  10204. }
  10205. //check Charge Point state
  10206. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10207. {
  10208. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10209. {
  10210. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10211. }
  10212. }
  10213. //check Charge Point state
  10214. for (int index = 0; index < AC_QUANTITY; index++)
  10215. {
  10216. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10217. {
  10218. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10219. }
  10220. }
  10221. if(checkState_Faulted == TRUE)
  10222. {
  10223. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10224. goto end;
  10225. }
  10226. // Parsing payload
  10227. SendLocalList = json_tokener_parse(payload);
  10228. if(!is_error(SendLocalList))
  10229. {
  10230. // Required data
  10231. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10232. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10233. // Optional data
  10234. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10235. {
  10236. //Check UpdateType
  10237. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10238. {
  10239. //Local list full update
  10240. DEBUG_INFO("Local list full update.\n");
  10241. OCPP_getListVerion();
  10242. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10243. {
  10244. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10245. goto end;
  10246. }
  10247. OCPP_cleanLocalList();
  10248. }
  10249. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10250. {
  10251. //Local list different update
  10252. DEBUG_INFO("Local list different update.\n");
  10253. OCPP_getListVerion();
  10254. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10255. {
  10256. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10257. goto end;
  10258. }
  10259. }
  10260. else
  10261. {
  10262. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10263. goto end;
  10264. }
  10265. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  10266. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10267. {
  10268. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10269. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10270. {
  10271. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  10272. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10273. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  10274. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10275. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  10276. }
  10277. // Add to db
  10278. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10279. {
  10280. //Local list full update
  10281. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10282. idx,
  10283. ShmOCPP16Data->SendLocalList.ListVersion,
  10284. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10285. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10286. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10287. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10288. // update list
  10289. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10290. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10291. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10292. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10293. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10294. }
  10295. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10296. {
  10297. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10298. idx,
  10299. ShmOCPP16Data->SendLocalList.ListVersion,
  10300. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10301. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10302. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10303. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10304. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10305. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10306. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10307. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10308. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10309. }
  10310. }
  10311. }
  10312. else
  10313. {
  10314. //Check UpdateType
  10315. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10316. {
  10317. //Local list full update
  10318. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10319. OCPP_cleanLocalList();
  10320. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10321. goto end;
  10322. }
  10323. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10324. {
  10325. //Local list different update
  10326. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10327. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10328. goto end;
  10329. }
  10330. }
  10331. result = PASS;
  10332. }
  10333. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10334. end:
  10335. json_object_put(SendLocalList);
  10336. sendSendLocalListConfirmation(uuid, comfirmstr);
  10337. return result;
  10338. }
  10339. #define MAX 200
  10340. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10341. {
  10342. mtrace();
  10343. int result = FAIL;
  10344. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10345. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10346. char chargingProfilePurposeStr[30]={0};
  10347. char chargingProfileKindStr[16]={0};
  10348. char recurrencyKindStr[10]={0};
  10349. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10350. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10351. int chargingSchedulePeriodCount = 0;
  10352. char comfirmstr[20]={0};
  10353. int meet= FALSE;
  10354. FILE *fptr1;
  10355. char filename[MAX]={0};
  10356. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10357. char rmFileCmd[50]={0};
  10358. char tempchargingProfilePurposeStr[30]={0};
  10359. char word[1600]={0};
  10360. int n_chargingProfile = 0;
  10361. json_object *SetChargingProfile;
  10362. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10363. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10364. SetChargingProfile = json_tokener_parse(payload);
  10365. if(!is_error(SetChargingProfile))
  10366. {
  10367. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10368. {
  10369. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10370. if(connectorIdInt == 0)
  10371. {
  10372. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10373. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10374. }
  10375. else
  10376. {
  10377. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10378. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10379. }
  10380. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10381. }
  10382. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10383. {
  10384. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10385. {
  10386. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10387. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10388. {
  10389. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10390. }
  10391. else
  10392. {
  10393. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10394. }
  10395. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10396. }
  10397. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10398. {
  10399. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10400. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10401. {
  10402. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10403. }
  10404. else
  10405. {
  10406. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10407. }
  10408. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10409. }
  10410. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10411. {
  10412. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10413. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10414. {
  10415. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10416. }
  10417. else
  10418. {
  10419. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10420. }
  10421. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10422. }
  10423. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10424. {
  10425. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10426. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10427. {
  10428. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10429. }
  10430. else
  10431. {
  10432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10433. }
  10434. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10435. }
  10436. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10437. {
  10438. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10439. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10440. {
  10441. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10442. }
  10443. else
  10444. {
  10445. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10446. }
  10447. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10448. }
  10449. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10450. {
  10451. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10452. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10453. {
  10454. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10455. }
  10456. else
  10457. {
  10458. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10459. }
  10460. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10461. }
  10462. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10463. {
  10464. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10465. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10466. {
  10467. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10468. }
  10469. else
  10470. {
  10471. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10472. }
  10473. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10474. }
  10475. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10476. {
  10477. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10478. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10479. {
  10480. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10481. }
  10482. else
  10483. {
  10484. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10485. }
  10486. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10487. }
  10488. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10489. {
  10490. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10491. {
  10492. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10493. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10494. {
  10495. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10496. }
  10497. else
  10498. {
  10499. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10500. }
  10501. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10502. }
  10503. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10504. {
  10505. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10506. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10507. {
  10508. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10509. }
  10510. else
  10511. {
  10512. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10513. }
  10514. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10515. }
  10516. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10517. {
  10518. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10519. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10520. {
  10521. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10522. }
  10523. else
  10524. {
  10525. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10526. }
  10527. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10528. }
  10529. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10530. {
  10531. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10532. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10533. {
  10534. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10535. }
  10536. else
  10537. {
  10538. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10539. }
  10540. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10541. }
  10542. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10543. {
  10544. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10545. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10546. if(chargingSchedulePeriodCount <= 10)
  10547. {
  10548. 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++)
  10549. {
  10550. 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)
  10551. {
  10552. 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"));
  10553. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10554. {
  10555. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10556. }
  10557. else
  10558. {
  10559. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10560. }
  10561. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10562. }
  10563. 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)
  10564. {
  10565. 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"));
  10566. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10567. {
  10568. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10569. }
  10570. else
  10571. {
  10572. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10573. }
  10574. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10575. }
  10576. 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)
  10577. {
  10578. 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"));
  10579. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10580. {
  10581. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10582. }
  10583. else
  10584. {
  10585. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10586. }
  10587. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10588. }
  10589. }
  10590. }
  10591. }
  10592. }
  10593. }
  10594. }
  10595. json_object_put(SetChargingProfile);
  10596. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10597. {
  10598. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10599. goto end;
  10600. }
  10601. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10602. {
  10603. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10604. if(connectorIdInt != 0)
  10605. {
  10606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10607. goto end;
  10608. }
  10609. strcpy(filename, ChargePointMaxProfile_JSON );
  10610. fptr1 = fopen(filename, "r");
  10611. if (!fptr1)
  10612. {
  10613. //file not exist
  10614. DEBUG_INFO("Unable to open the input file!!\n");
  10615. fptr1 = fopen(filename, "w+");
  10616. }
  10617. else
  10618. {
  10619. //Check Charging Profile Count
  10620. while(fscanf(fptr1, "%s", word) != EOF)
  10621. {
  10622. //DEBUG_INFO("word=%s\n",word);
  10623. if(strstr(word, "chargingProfileId")!= NULL)
  10624. {
  10625. //DEBUG_INFO("test chargingProfileId \n");
  10626. n_chargingProfile = n_chargingProfile + 1;
  10627. //DEBUG_INFO("chargingProfileId Found\n");
  10628. }
  10629. }
  10630. }
  10631. fclose(fptr1);
  10632. }
  10633. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10634. {
  10635. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10636. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10637. {
  10638. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10639. goto end;
  10640. }
  10641. memset(filename, 0, ARRAY_SIZE(filename));
  10642. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10643. fptr1 = fopen(filename, "r");
  10644. if (!fptr1)
  10645. {
  10646. //file not exist
  10647. //DEBUG_INFO("Unable to open the input file!!\n");
  10648. fptr1 = fopen(filename, "w+");
  10649. }
  10650. else
  10651. {
  10652. //Check Charging Profile Count
  10653. while(fscanf(fptr1, "%s", word) != EOF)
  10654. {
  10655. //DEBUG_INFO("word=%s\n",word);
  10656. if(strstr(word, "chargingProfileId")!= NULL)
  10657. {
  10658. //DEBUG_INFO("test chargingProfileId \n");
  10659. n_chargingProfile = n_chargingProfile + 1;
  10660. //DEBUG_INFO("chargingProfileId Found\n");
  10661. }
  10662. }
  10663. }
  10664. fclose(fptr1);
  10665. }
  10666. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10667. {
  10668. //printf("set chargingProfile 1-4\n");
  10669. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10670. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10671. if(connectorIdInt == 0)
  10672. {
  10673. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10674. goto end;
  10675. }
  10676. int tempIndex = 0;
  10677. //check Transaction active
  10678. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10679. {
  10680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10681. {
  10682. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10683. }
  10684. else
  10685. {
  10686. tempIndex = connectorIdInt -1;
  10687. }
  10688. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10689. {
  10690. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10691. {
  10692. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10693. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10694. {
  10695. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10696. {
  10697. meet = TRUE;
  10698. break;
  10699. }
  10700. }
  10701. }
  10702. }
  10703. }
  10704. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10705. {
  10706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10707. {
  10708. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10709. }
  10710. else
  10711. {
  10712. tempIndex = connectorIdInt -1;
  10713. }
  10714. for (int index = 0; index < CCS_QUANTITY; index++)
  10715. {
  10716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10717. {
  10718. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10719. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10720. {
  10721. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10722. {
  10723. meet = TRUE;
  10724. break;
  10725. }
  10726. }
  10727. }
  10728. }
  10729. }
  10730. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10731. {
  10732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10733. {
  10734. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10735. }
  10736. else
  10737. {
  10738. tempIndex = connectorIdInt -1;
  10739. }
  10740. for (int index = 0; index < GB_QUANTITY; index++)
  10741. {
  10742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10743. {
  10744. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10745. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10746. {
  10747. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10748. {
  10749. meet = TRUE;
  10750. break;
  10751. }
  10752. }
  10753. }
  10754. }
  10755. }
  10756. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10757. {
  10758. tempIndex = connectorIdInt -1;
  10759. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10760. {
  10761. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10762. {
  10763. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10764. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10765. {
  10766. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10767. {
  10768. meet = TRUE;
  10769. break;
  10770. }
  10771. }
  10772. }
  10773. }
  10774. }
  10775. else
  10776. {
  10777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10778. {
  10779. tempIndex = 2;
  10780. }
  10781. else
  10782. {
  10783. tempIndex = (connectorIdInt -1);
  10784. }
  10785. for (int index = 0; index < AC_QUANTITY; index++)
  10786. {
  10787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10788. {
  10789. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10790. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10791. {
  10792. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10793. {
  10794. meet = TRUE;
  10795. break;
  10796. }
  10797. }
  10798. }
  10799. }
  10800. }
  10801. //check Transaction active
  10802. if(meet == FALSE)
  10803. {
  10804. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10805. goto end;
  10806. }
  10807. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10808. {
  10809. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10810. goto end;
  10811. }
  10812. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10813. fptr1 = fopen(filename, "r");
  10814. if (!fptr1)
  10815. {
  10816. //file not exist
  10817. DEBUG_INFO("Unable to open the input file!!\n");
  10818. fptr1 = fopen(filename, "w+");
  10819. }
  10820. else
  10821. {
  10822. //Check Charging Profile Count
  10823. while(fscanf(fptr1, "%s", word) != EOF)
  10824. {
  10825. //DEBUG_INFO("word=%s\n",word);
  10826. if(strstr(word, "chargingProfileId")!= NULL)
  10827. {
  10828. //DEBUG_INFO("test chargingProfileId \n");
  10829. n_chargingProfile = n_chargingProfile + 1;
  10830. //DEBUG_INFO("chargingProfileId Found\n");
  10831. }
  10832. }
  10833. }
  10834. fclose(fptr1);
  10835. }
  10836. // Check ChargeProfileMaxStackLevel
  10837. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10838. {
  10839. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10840. goto end;
  10841. }
  10842. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10843. {
  10844. int i = 0;
  10845. char fnametemp[200]={0};
  10846. n_chargingProfile = 0;
  10847. //Check ChargePointMaxProfile.json exit
  10848. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10849. {
  10850. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10851. //Check Charging Profile Count
  10852. while(fscanf(fptr1, "%s", word) != EOF)
  10853. {
  10854. //DEBUG_INFO("word=%s\n",word);
  10855. if(strstr(word, "chargingProfileId")!= NULL)
  10856. {
  10857. //DEBUG_INFO("test chargingProfileId \n");
  10858. n_chargingProfile = n_chargingProfile + 1;
  10859. i = i + 1;
  10860. //DEBUG_INFO("chargingProfileId Found\n");
  10861. }
  10862. memset(word, 0, ARRAY_SIZE(word));
  10863. }
  10864. fclose(fptr1);
  10865. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10866. }
  10867. //Check TxDefaultProfile_0.json exit
  10868. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10869. {
  10870. i = 0;
  10871. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10872. //Check Charging Profile Count
  10873. while(fscanf(fptr1, "%s", word) != EOF)
  10874. {
  10875. //DEBUG_INFO("word=%s\n",word);
  10876. if(strstr(word, "chargingProfileId")!= NULL)
  10877. {
  10878. //DEBUG_INFO("test chargingProfileId \n");
  10879. n_chargingProfile = n_chargingProfile + 1;
  10880. i = i + 1;
  10881. //DEBUG_INFO("chargingProfileId Found\n");
  10882. }
  10883. memset(word, 0, ARRAY_SIZE(word));
  10884. }
  10885. fclose(fptr1);
  10886. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10887. }
  10888. //Check TxDefaultProfile_%d.json
  10889. for(int j=1; j <= gunTotalNumber; j++)
  10890. {
  10891. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10892. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10893. if((access(fnametemp,F_OK))!=-1)
  10894. {
  10895. i = 0;
  10896. fptr1 = fopen(fnametemp, "r");
  10897. //Check Charging Profile Count
  10898. while(fscanf(fptr1, "%s", word) != EOF)
  10899. {
  10900. //DEBUG_INFO("word=%s\n",word);
  10901. if(strstr(word, "chargingProfileId")!= NULL)
  10902. {
  10903. //DEBUG_INFO("test chargingProfileId \n");
  10904. n_chargingProfile = n_chargingProfile + 1;
  10905. i = i + 1;
  10906. //DEBUG_INFO("chargingProfileId Found\n");
  10907. }
  10908. memset(word, 0, ARRAY_SIZE(word));
  10909. }
  10910. fclose(fptr1);
  10911. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10912. }
  10913. }
  10914. //Check TxProfile_%d.json
  10915. for(int j=1; j <= gunTotalNumber; j++)
  10916. {
  10917. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10918. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10919. if((access(fnametemp,F_OK))!=-1)
  10920. {
  10921. i = 0;
  10922. fptr1 = fopen(fnametemp, "r");
  10923. //Check Charging Profile Count
  10924. while(fscanf(fptr1, "%s", word) != EOF)
  10925. {
  10926. //DEBUG_INFO("word=%s\n",word);
  10927. if(strstr(word, "chargingProfileId")!= NULL)
  10928. {
  10929. //DEBUG_INFO("test chargingProfileId \n");
  10930. n_chargingProfile = n_chargingProfile + 1;
  10931. i = i + 1;
  10932. //DEBUG_INFO("chargingProfileId Found\n");
  10933. }
  10934. memset(word, 0, ARRAY_SIZE(word));
  10935. }
  10936. fclose(fptr1);
  10937. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10938. }
  10939. }
  10940. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10941. {
  10942. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10943. goto end;
  10944. }
  10945. }
  10946. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10947. //**********************************Write to File********************************************************/
  10948. FILE *infile;
  10949. FILE *outfile;
  10950. infile = fopen (filename, "r");
  10951. outfile = fopen (tempfile, "w");
  10952. int d =0;
  10953. d = fgetc(infile);
  10954. rewind(infile);
  10955. if(d == EOF)
  10956. {
  10957. // Profile is empty
  10958. fprintf(outfile,"%s\n",payload);
  10959. fclose(infile);
  10960. fclose(outfile);
  10961. sprintf(rmFileCmd,"rm -f %s",filename);
  10962. system(rmFileCmd);
  10963. rename(tempfile, filename);
  10964. }
  10965. else
  10966. {
  10967. // Profile is not empty
  10968. char buf[2048]={0};
  10969. int ChargingProfileAdded = FALSE;
  10970. while (fgets(buf, sizeof(buf), infile) != NULL)
  10971. {
  10972. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10973. json_object *tmpChargingProfile;
  10974. tmpChargingProfile = json_tokener_parse(buf);
  10975. if(!is_error(SetChargingProfile))
  10976. {
  10977. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10978. {
  10979. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10980. }
  10981. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10982. {
  10983. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10984. {
  10985. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10986. }
  10987. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10988. {
  10989. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10990. }
  10991. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10992. {
  10993. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10994. }
  10995. }
  10996. }
  10997. json_object_put(tmpChargingProfile);
  10998. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10999. {
  11000. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11001. {
  11002. //DEBUG_INFO("update set chargingProfile to file -0\n");
  11003. if(ChargingProfileAdded == FALSE)
  11004. {
  11005. fprintf(outfile,"%s\n",payload);
  11006. ChargingProfileAdded = TRUE;
  11007. }
  11008. }
  11009. else
  11010. {
  11011. if(tempstackLevelInt < stackLevelInt)
  11012. {
  11013. if(ChargingProfileAdded == FALSE)
  11014. {
  11015. fprintf(outfile,"%s\n",buf);
  11016. fprintf(outfile,"%s\n",payload);
  11017. ChargingProfileAdded = TRUE;
  11018. }
  11019. else
  11020. {
  11021. fprintf(outfile,"%s\n",buf);
  11022. }
  11023. }
  11024. else
  11025. {
  11026. if(ChargingProfileAdded == FALSE)
  11027. {
  11028. fprintf(outfile,"%s\n",buf);
  11029. fprintf(outfile,"%s\n",payload);
  11030. ChargingProfileAdded = TRUE;
  11031. }
  11032. else
  11033. {
  11034. fprintf(outfile,"%s\n",buf);
  11035. }
  11036. }
  11037. }
  11038. }
  11039. else
  11040. {
  11041. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11042. {
  11043. if(ChargingProfileAdded == FALSE)
  11044. {
  11045. fprintf(outfile,"%s\n",buf);
  11046. fprintf(outfile,"%s\n",payload);
  11047. ChargingProfileAdded = TRUE;
  11048. }
  11049. else
  11050. {
  11051. fprintf(outfile,"%s\n",buf);
  11052. }
  11053. }
  11054. else if(tempstackLevelInt < stackLevelInt)
  11055. {
  11056. if(ChargingProfileAdded == FALSE)
  11057. {
  11058. fprintf(outfile,"%s\n",buf);
  11059. fprintf(outfile,"%s\n",payload);
  11060. ChargingProfileAdded = TRUE;
  11061. }
  11062. else
  11063. {
  11064. fprintf(outfile,"%s\n",buf);
  11065. }
  11066. }
  11067. else
  11068. {
  11069. if(ChargingProfileAdded == FALSE)
  11070. {
  11071. fprintf(outfile,"%s\n",buf);
  11072. fprintf(outfile,"%s\n",payload);
  11073. ChargingProfileAdded = TRUE;
  11074. }
  11075. else
  11076. {
  11077. fprintf(outfile,"%s\n",buf);
  11078. }
  11079. }
  11080. }
  11081. } // end of while loop
  11082. fclose(infile);
  11083. fclose(outfile);
  11084. sprintf(rmFileCmd,"rm -f %s",filename);
  11085. system(rmFileCmd);
  11086. rename(tempfile, filename);
  11087. }
  11088. sleep(1);
  11089. result = TRUE;
  11090. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11091. end:
  11092. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11093. {
  11094. if(connectorIdInt == 0)
  11095. {
  11096. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11097. {
  11098. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11099. }
  11100. }
  11101. else
  11102. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11103. }
  11104. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11105. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11106. return result;
  11107. }
  11108. int handleTriggerMessageRequest(char *uuid, char *payload)
  11109. {
  11110. mtrace();
  11111. int result = FAIL;
  11112. int connectorIdIsNULL = FALSE;
  11113. int connectorIdInt =0;
  11114. char sstr[40]={0},sstrtemp[100]={ 0 };
  11115. char requestedMessagestr[40]={0};
  11116. char comfirmstr[20]={0};
  11117. int c = 0;
  11118. char *loc;
  11119. DEBUG_INFO("handleTriggerMessageRequest\n");
  11120. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11121. strcpy(sstrtemp, stringtrimspace(payload));
  11122. c = 0;
  11123. loc = strstr(sstrtemp, "requestedMessage");
  11124. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11125. {
  11126. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11127. c++;
  11128. }
  11129. sstr[c] = '\0';
  11130. strcpy(requestedMessagestr, sstr);
  11131. c = 0;
  11132. loc = strstr(sstrtemp, "connectorId");
  11133. if(loc == NULL)
  11134. {
  11135. connectorIdIsNULL = TRUE;
  11136. }
  11137. else
  11138. {
  11139. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11140. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11141. {
  11142. sstr[c] = loc[strlen("connectorId")+2+c];
  11143. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11144. c++;
  11145. }
  11146. sstr[c] = '\0';
  11147. connectorIdInt = atoi(sstr);
  11148. }
  11149. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11150. {
  11151. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11152. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11153. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11154. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11155. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11156. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11157. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11158. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11159. {
  11160. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11161. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11162. return TRUE;
  11163. }
  11164. else
  11165. {
  11166. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11167. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11168. }
  11169. }
  11170. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11171. {
  11172. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11173. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11174. return TRUE;
  11175. }
  11176. //==========================
  11177. // Trigger message
  11178. //==========================
  11179. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11180. {
  11181. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11182. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11183. {
  11184. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11185. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11186. }
  11187. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11188. }
  11189. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11190. {
  11191. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11192. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11193. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11194. }
  11195. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11196. {
  11197. //sendBootNotificationRequest();
  11198. server_sign = FALSE;
  11199. }
  11200. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11201. {
  11202. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11203. }
  11204. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11205. {
  11206. if(connectorIdIsNULL == FALSE)
  11207. {
  11208. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11209. {
  11210. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11211. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11212. }
  11213. }
  11214. else
  11215. {
  11216. for(int idx=0;idx< gunTotalNumber;idx++)
  11217. {
  11218. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11219. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11220. }
  11221. }
  11222. }
  11223. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11224. {
  11225. if(connectorIdIsNULL == FALSE)
  11226. {
  11227. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11228. {
  11229. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11230. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11231. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11232. }
  11233. }
  11234. else
  11235. {
  11236. for(int idx=0;idx< gunTotalNumber;idx++)
  11237. {
  11238. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11239. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11240. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11241. }
  11242. }
  11243. }
  11244. return result;
  11245. }
  11246. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11247. {
  11248. mtrace();
  11249. int result = FAIL;
  11250. int connectorIdInt =0;
  11251. char comfirmstr[20]={0};
  11252. int tempIndex = 0;
  11253. json_object *UnlockConnector;
  11254. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11255. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11256. UnlockConnector = json_tokener_parse(payload);
  11257. if(!is_error(UnlockConnector))
  11258. {
  11259. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11260. {
  11261. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11262. }
  11263. }
  11264. json_object_put(UnlockConnector);
  11265. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11266. if(gunTotalNumber == 0)
  11267. {
  11268. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11269. goto end;
  11270. }
  11271. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11272. {
  11273. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11274. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11275. goto end;
  11276. }
  11277. else
  11278. {
  11279. //check Transaction active
  11280. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11281. {
  11282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11283. {
  11284. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11285. }
  11286. else
  11287. {
  11288. tempIndex = connectorIdInt -1;
  11289. }
  11290. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11291. {
  11292. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11293. {
  11294. //stop Transaction
  11295. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11296. }
  11297. }
  11298. }
  11299. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11300. {
  11301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11302. {
  11303. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11304. }
  11305. else
  11306. {
  11307. tempIndex = connectorIdInt -1;
  11308. }
  11309. for (int index = 0; index < CCS_QUANTITY; index++)
  11310. {
  11311. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11312. {
  11313. //stop Transaction
  11314. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11315. }
  11316. }
  11317. }
  11318. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11319. {
  11320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11321. {
  11322. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11323. }
  11324. else
  11325. {
  11326. tempIndex = connectorIdInt -1;
  11327. }
  11328. for (int index = 0; index < GB_QUANTITY; index++)
  11329. {
  11330. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11331. {
  11332. //stop Transaction
  11333. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11334. }
  11335. }
  11336. }
  11337. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11338. {
  11339. tempIndex = connectorIdInt -1;
  11340. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11341. {
  11342. 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)))
  11343. {
  11344. //stop Transaction
  11345. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11346. }
  11347. }
  11348. }
  11349. else
  11350. {
  11351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11352. {
  11353. tempIndex = 2;
  11354. }
  11355. else
  11356. {
  11357. tempIndex = connectorIdInt-1;
  11358. }
  11359. for (int index = 0; index < AC_QUANTITY; index++)
  11360. {
  11361. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11362. {
  11363. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11364. }
  11365. }
  11366. }
  11367. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11368. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11369. result = TRUE;
  11370. return result;
  11371. }
  11372. end:
  11373. //json_object_put(obj); --- remove temporally
  11374. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11375. return result;
  11376. }
  11377. static char UpdateFirmwarepayloadData[300]={0};
  11378. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11379. {
  11380. mtrace();
  11381. int result = FAIL;
  11382. pthread_t t;
  11383. sendUpdateFirmwareConfirmation(uuid);
  11384. memset(UpdateFirmwarepayloadData, 0, 300);
  11385. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11386. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11387. ////pthread_join(t, NULL); //
  11388. //pthread_detach(t);
  11389. //sendUpdateFirmwareConfirmation(uuid);
  11390. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11391. return result;
  11392. }
  11393. void *UpdateFirmwareProcess(void *data)
  11394. {
  11395. pthread_detach(pthread_self());
  11396. mtrace();
  11397. int retriesInt =0, retryIntervalInt=0;
  11398. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11399. int port=0;
  11400. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11401. int isSuccess = 0;
  11402. char ftpbuf[1024];
  11403. char temp[1024];
  11404. char * pch;
  11405. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11406. json_object *UpdateFirmware;
  11407. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11408. if(!is_error(UpdateFirmware))
  11409. {
  11410. // Required data
  11411. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11412. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11413. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11414. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11415. // Optional data
  11416. if(json_object_object_get(UpdateFirmware, "retries"))
  11417. {
  11418. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11419. }
  11420. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11421. {
  11422. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11423. }
  11424. }
  11425. json_object_put(UpdateFirmware);
  11426. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11427. memset(path, 0, ARRAY_SIZE(path));
  11428. // Wait retrieveData
  11429. if(strlen(retrieveDatestr) > 10)
  11430. {
  11431. do
  11432. {
  11433. sleep(1);
  11434. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11435. }
  11436. // Ready to download
  11437. system("rm -f /mnt/*");
  11438. if(strncmp(locationstr,"http", 4) == 0)
  11439. {
  11440. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11441. sprintf(ftppath,"/%s", path);
  11442. DEBUG_INFO("locationstr: %s\n", locationstr);
  11443. DEBUG_INFO("protocol: %s\n",protocol);
  11444. DEBUG_INFO("host: %s\n",host);
  11445. DEBUG_INFO("path: %s\n",path);
  11446. DEBUG_INFO("ftppath: %s\n",ftppath);
  11447. int ftppathlen=strlen(ftppath);
  11448. int i=1;
  11449. char filenametemp[50];
  11450. while(i < ftppathlen)
  11451. {
  11452. int len=ftppathlen-i;
  11453. if(ftppath[len]== 47) // '/' ascll code: 47
  11454. {
  11455. DEBUG_INFO("compare '/' all right\n");
  11456. break;
  11457. }
  11458. i=i+1;
  11459. }
  11460. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11461. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11462. filenametemp[i+1] = 0;
  11463. do
  11464. {
  11465. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11466. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11467. sleep(1);
  11468. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11469. if(!isSuccess)
  11470. {
  11471. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11472. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11473. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11474. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11475. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11476. }
  11477. else
  11478. {
  11479. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11480. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11481. }
  11482. retriesInt--;
  11483. }while((isSuccess == 0)&&(retriesInt >= 0));
  11484. }
  11485. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11486. {
  11487. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11488. memset(temp, 0, ARRAY_SIZE(temp));
  11489. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11490. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11491. int ftppathlen=strlen(ftpbuf);
  11492. int i=1;
  11493. char filenametemp[50];
  11494. while(i < ftppathlen)
  11495. {
  11496. int len=ftppathlen-i;
  11497. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11498. {
  11499. DEBUG_INFO(" compare '/' all right\n");
  11500. break;
  11501. }
  11502. i=i+1;
  11503. }
  11504. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11505. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11506. filenametemp[i+1] = 0;
  11507. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11508. pch=strchr(temp,'@');
  11509. if(pch==NULL)
  11510. {
  11511. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11512. protocol, host, &port, path);
  11513. strcpy(user,"anonymous");
  11514. strcpy(password,"");
  11515. }
  11516. else
  11517. {
  11518. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11519. protocol, user, password, host, &port, path);
  11520. }
  11521. sscanf(host,"%[^/]%s",host1, path1);
  11522. sprintf(ftppath,"%s", path1);
  11523. //DEBUG_INFO("protocol =%s\n",protocol);
  11524. //DEBUG_INFO("user =%s\n",user);
  11525. //DEBUG_INFO("password =%s\n",password);
  11526. //DEBUG_INFO("host1 =%s\n",host1);
  11527. //DEBUG_INFO("port =%d\n",port);
  11528. //DEBUG_INFO("path1 =%s\n",path1);
  11529. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11530. //ftpFile(host, user, password, port, ftppath, fname);
  11531. //download firmware pthred
  11532. if(port == 0)
  11533. {
  11534. port = 21;
  11535. }
  11536. do
  11537. {
  11538. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11539. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11540. sleep(1);
  11541. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11542. if(!isSuccess)
  11543. {
  11544. //BulldogUtil.sleepMs(interval*1000);
  11545. DEBUG_INFO("Update firmware request and download file fail.\n");
  11546. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11547. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11548. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11549. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11550. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11551. }
  11552. else
  11553. {
  11554. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11555. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11556. }
  11557. retriesInt--;
  11558. }while((!isSuccess)&&(retriesInt >= 0));
  11559. }
  11560. else
  11561. {
  11562. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11563. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11564. sleep(1);
  11565. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11566. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11567. }
  11568. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11569. pthread_exit(NULL);
  11570. }
  11571. int handleCertificateSignedRequest(char *uuid, char *payload)
  11572. {
  11573. mtrace();
  11574. int result = PASS;
  11575. json_object *CertificateSigned;
  11576. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11577. CertificateSigned = json_tokener_parse(payload);
  11578. if(!is_error(CertificateSigned))
  11579. {
  11580. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11581. }
  11582. json_object_put(CertificateSigned);
  11583. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11584. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11585. fclose(fp);
  11586. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11587. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11588. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11589. sendCertificateSignedConfirmation(uuid);
  11590. return result;
  11591. }
  11592. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11593. {
  11594. mtrace();
  11595. int result = PASS;
  11596. json_object *DeleteCertificate;
  11597. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11598. DeleteCertificate = json_tokener_parse(payload);
  11599. if(!is_error(DeleteCertificate))
  11600. {
  11601. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11602. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11603. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11604. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11605. }
  11606. json_object_put(DeleteCertificate);
  11607. /*
  11608. * TODO: Delete certificateSigned process
  11609. */
  11610. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11611. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11612. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11613. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11614. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11615. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11616. sendDeleteCertificateConfirmation(uuid);
  11617. return result;
  11618. }
  11619. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11620. {
  11621. mtrace();
  11622. int result = PASS;
  11623. json_object *ExtendedTriggerMessage;
  11624. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11625. ExtendedTriggerMessage = json_tokener_parse(payload);
  11626. if(!is_error(ExtendedTriggerMessage))
  11627. {
  11628. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11629. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11630. {
  11631. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11632. }
  11633. else
  11634. {
  11635. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11636. }
  11637. }
  11638. json_object_put(ExtendedTriggerMessage);
  11639. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11640. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11641. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11642. {
  11643. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11644. }
  11645. else
  11646. {
  11647. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11648. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11649. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11650. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11651. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11652. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11653. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11654. {
  11655. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11656. }
  11657. else
  11658. {
  11659. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11660. }
  11661. }
  11662. sendExtendedTriggerMessageConfirmation(uuid);
  11663. //==========================
  11664. // Trigger message
  11665. //==========================
  11666. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11667. {
  11668. //sendBootNotificationRequest();
  11669. server_sign = FALSE;
  11670. }
  11671. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11672. {
  11673. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11674. }
  11675. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11676. {
  11677. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11678. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11679. {
  11680. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11681. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11682. }
  11683. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11684. }
  11685. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11686. {
  11687. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11688. }
  11689. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11690. {
  11691. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11692. {
  11693. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11694. }
  11695. else
  11696. {
  11697. for(int idx=0;idx< gunTotalNumber;idx++)
  11698. {
  11699. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11700. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11701. }
  11702. }
  11703. }
  11704. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11705. {
  11706. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11707. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11708. {
  11709. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  11710. }
  11711. }
  11712. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11713. {
  11714. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11715. {
  11716. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11717. }
  11718. else
  11719. {
  11720. for(int idx=0;idx< gunTotalNumber;idx++)
  11721. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11722. }
  11723. }
  11724. return result;
  11725. }
  11726. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11727. {
  11728. mtrace();
  11729. int result = PASS;
  11730. json_object *GetInstalledCertificateIds;
  11731. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11732. GetInstalledCertificateIds = json_tokener_parse(payload);
  11733. if(!is_error(GetInstalledCertificateIds))
  11734. {
  11735. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11736. }
  11737. json_object_put(GetInstalledCertificateIds);
  11738. /*
  11739. * TODO: Return installed certificate process
  11740. */
  11741. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11742. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11743. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11744. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11745. sendGetInstalledCertificateIdsConfirmation(uuid);
  11746. return result;
  11747. }
  11748. int handleGetLogRequest(char *uuid, char *payload)
  11749. {
  11750. mtrace();
  11751. int result = PASS;
  11752. json_object *GetLog;
  11753. DEBUG_INFO("handleGetLogRequest...\n");
  11754. GetLog = json_tokener_parse(payload);
  11755. if(!is_error(GetLog))
  11756. {
  11757. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11758. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11759. if(json_object_object_get(GetLog, "retries") != NULL)
  11760. {
  11761. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11762. }
  11763. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11764. {
  11765. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11766. }
  11767. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11768. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11769. {
  11770. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11771. }
  11772. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11773. {
  11774. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11775. }
  11776. }
  11777. json_object_put(GetLog);
  11778. /*
  11779. * TODO: Upload log process
  11780. */
  11781. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11782. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11783. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11784. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11785. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11786. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11787. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11788. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11789. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11790. sendGetLogConfirmation(uuid);
  11791. return result;
  11792. }
  11793. int handleInstallCertificateRequest(char *uuid, char *payload)
  11794. {
  11795. mtrace();
  11796. int result = PASS;
  11797. json_object *InstallCertificate;
  11798. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11799. InstallCertificate = json_tokener_parse(payload);
  11800. if(!is_error(InstallCertificate))
  11801. {
  11802. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11803. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11804. /*
  11805. * TODO: Install certificate process
  11806. */
  11807. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11808. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11809. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11810. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11811. sendInstallCertificateConfirmation(uuid);
  11812. }
  11813. json_object_put(InstallCertificate);
  11814. return result;
  11815. }
  11816. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11817. {
  11818. mtrace();
  11819. int result = PASS;
  11820. json_object *SignedUpdateFirmware;
  11821. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11822. SignedUpdateFirmware = json_tokener_parse(payload);
  11823. if(!is_error(SignedUpdateFirmware))
  11824. {
  11825. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11826. {
  11827. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11828. }
  11829. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11830. {
  11831. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11832. }
  11833. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11834. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11835. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11836. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11837. {
  11838. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11839. }
  11840. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11841. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11842. }
  11843. json_object_put(SignedUpdateFirmware);
  11844. /*
  11845. * TODO: Upgrade firmware process
  11846. */
  11847. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11848. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11849. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11850. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11851. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11852. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11853. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11854. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11855. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11856. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11857. sendInstallCertificateConfirmation(uuid);
  11858. return result;
  11859. }
  11860. int handleUnknownRequest(char *uuid, char *payload)
  11861. {
  11862. mtrace();
  11863. int result = PASS;
  11864. DEBUG_INFO("handleUnknownRequest...\n");
  11865. sendUnknownConfirmation(uuid);
  11866. result = PASS;
  11867. return result;
  11868. }
  11869. //==========================================
  11870. // Handle server response routine
  11871. //==========================================
  11872. void handleAuthorizeResponse(char *payload, int gun_index)
  11873. {
  11874. mtrace();
  11875. char expiryDatestr[30]={0};
  11876. char parentIdTagstr[20]={0};
  11877. char statusstr[20]={0};
  11878. int expiryDateISNULL=FALSE;
  11879. int parentIdTagISNULL=FALSE;
  11880. DEBUG_INFO("handleAuthorizeResponse...\n");
  11881. json_object *Authorize;
  11882. Authorize = json_tokener_parse(payload);
  11883. if(!is_error(Authorize))
  11884. {
  11885. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11886. {
  11887. // Required data
  11888. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11889. // Optional data
  11890. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11891. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11892. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11893. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11894. }
  11895. }
  11896. json_object_put(Authorize);
  11897. if(expiryDateISNULL == FALSE)
  11898. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11899. if(parentIdTagISNULL == FALSE)
  11900. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11901. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11902. //Update idTag information to authorization cache if supproted
  11903. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11904. {
  11905. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11906. }
  11907. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11908. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11909. authorizeRetryTimes = 0;
  11910. }
  11911. void handleBootNotificationResponse(char *payload, int gun_index)
  11912. {
  11913. mtrace();
  11914. char statusStr[12]={0};
  11915. char currentTimeStr[30]={0};
  11916. int intervalInt = 0;
  11917. DEBUG_INFO("handleBootNotificationResponse...\n");
  11918. json_object *BootNotification;
  11919. BootNotification = json_tokener_parse(payload);
  11920. if(!is_error(BootNotification))
  11921. {
  11922. // Required data
  11923. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11924. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11925. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11926. }
  11927. json_object_put(BootNotification);
  11928. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11929. BootNotificationInterval = intervalInt;
  11930. HeartBeatWaitTime = intervalInt;
  11931. //write back to ShmOCPP16Data->BootNotification
  11932. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11933. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11934. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11935. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11936. {
  11937. server_sign = TRUE;
  11938. server_pending =FALSE;
  11939. }
  11940. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11941. {
  11942. server_pending = TRUE;
  11943. }
  11944. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11945. srand(time(NULL));
  11946. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11947. SetOcppConnStatus(TRUE);
  11948. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11949. }
  11950. void handleDataTransferResponse(char *payload, int gun_index)
  11951. {
  11952. char sstr[160]={0};//sstr[200]={ 0 };
  11953. int c = 0;
  11954. char *loc;
  11955. DEBUG_INFO("handleDataTransferResponse ...\n");
  11956. loc = strstr(payload, "status");
  11957. c = 0;
  11958. while (loc[3+strlen("status")+c] != '\"')
  11959. {
  11960. sstr[c] = loc[3+strlen("status")+c];
  11961. c++;
  11962. }
  11963. sstr[c] = '\0';
  11964. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11965. }
  11966. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11967. {
  11968. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11969. //struct json_object *obj;
  11970. // obj = json_tokener_parse(payload);
  11971. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11972. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11973. //No fields are defined.
  11974. }
  11975. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11976. {
  11977. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11978. //struct json_object *obj;
  11979. // obj = json_tokener_parse(payload);
  11980. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11981. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11982. //No fields are defined.
  11983. }
  11984. void handleHeartbeatResponse(char *payload, int gun_index)
  11985. {
  11986. mtrace();
  11987. DEBUG_INFO("handleHeartbeatResponse...\n");
  11988. json_object *Heartbeat;
  11989. Heartbeat = json_tokener_parse(payload);
  11990. if(!is_error(Heartbeat))
  11991. {
  11992. // Required data
  11993. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11994. }
  11995. json_object_put(Heartbeat);
  11996. if(FirstHeartBeat == 0)
  11997. {
  11998. FirstHeartBeat = 1;
  11999. DEBUG_INFO("FirstHeartBeat \n");
  12000. }
  12001. HeartBeatWithNOResponse = 0;
  12002. clientTime.Heartbeat=time((time_t*)NULL);
  12003. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12004. }
  12005. void handleMeterValuesResponse(char *payload, int gun_index)
  12006. {
  12007. mtrace();
  12008. DEBUG_INFO("handleMeterValuesResponse...\n");
  12009. }
  12010. void handleStartTransactionResponse(char *payload, int gun_index)
  12011. {
  12012. mtrace();
  12013. //int transactionIdInt = 0;
  12014. FILE *outfile;
  12015. char data[100]={0};
  12016. DEBUG_INFO("handleStartTransactionResponse...\n");
  12017. json_object *StartTransaction;
  12018. StartTransaction = json_tokener_parse(payload);
  12019. if(!is_error(StartTransaction))
  12020. {
  12021. // Required data
  12022. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12023. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12024. // Optional data
  12025. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12026. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12027. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12028. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12029. }
  12030. json_object_put(StartTransaction);
  12031. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12032. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12033. //-----------Start : write to the Queue TransactionId file -----------------//
  12034. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12035. {}
  12036. else
  12037. {
  12038. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12039. if(log == NULL)
  12040. {
  12041. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12042. return ;
  12043. }
  12044. else
  12045. {
  12046. fclose(log);
  12047. }
  12048. }
  12049. // open file for writing
  12050. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12051. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12052. {
  12053. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12054. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12055. fputs(data, outfile);
  12056. fclose (outfile);
  12057. }
  12058. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12059. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12060. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12061. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12062. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12063. }
  12064. void handleStatusNotificationResponse(char *payload, int gun_index)
  12065. {
  12066. mtrace();
  12067. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12068. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12069. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12070. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12071. }
  12072. void handleStopTransactionnResponse(char *payload, int gun_index)
  12073. {
  12074. mtrace();
  12075. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12076. json_object *StopTransaction;
  12077. StopTransaction = json_tokener_parse(payload);
  12078. if(!is_error(StopTransaction))
  12079. {
  12080. // Optional data
  12081. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12082. {
  12083. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12084. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12085. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12086. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12087. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12088. }
  12089. }
  12090. json_object_put(StopTransaction);
  12091. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12092. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12093. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12094. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12095. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12096. }
  12097. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12098. {
  12099. mtrace();
  12100. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12101. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12102. }
  12103. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12104. {
  12105. mtrace();
  12106. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12107. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12108. }
  12109. void handleSignCertificateResponse(char *payload, int gun_index)
  12110. {
  12111. mtrace();
  12112. DEBUG_INFO("handleSignCertificateResponse...\n");
  12113. json_object *SignCertificate;
  12114. SignCertificate = json_tokener_parse(payload);
  12115. if(!is_error(SignCertificate))
  12116. {
  12117. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12118. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12119. }
  12120. json_object_put(SignCertificate);
  12121. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12122. }
  12123. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12124. {
  12125. mtrace();
  12126. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12127. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12128. }
  12129. //==========================================
  12130. // Handle Error routine
  12131. //==========================================
  12132. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12133. {
  12134. mtrace();
  12135. #ifdef SystemLogMessage
  12136. DEBUG_INFO("errorCode: %s\n", errorCode);
  12137. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12138. DEBUG_INFO("errorDetails: %s\n", payload);
  12139. #endif
  12140. }
  12141. //===============================================
  12142. // Common routine
  12143. //===============================================
  12144. int initialConfigurationTable(void)
  12145. {
  12146. //clock_t start_t, end_t, total_t;
  12147. FILE *fp;
  12148. FILE *outfile;
  12149. char str[512]={0};
  12150. char sstr[256]={0};
  12151. int c = 0;
  12152. char *loc;
  12153. int confVersion = 6;
  12154. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12155. //start_t = clock();
  12156. //printf("Starting of the program, start_t = %ld\n", start_t);
  12157. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12158. // Check configuration file size is correct
  12159. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12160. {
  12161. struct stat st;
  12162. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12163. if(st.st_size < 3100)
  12164. {
  12165. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12166. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12167. }
  12168. }
  12169. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12170. {
  12171. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12172. if(outfile == NULL)
  12173. {
  12174. DEBUG_INFO("Error opening file\n");
  12175. return FALSE;
  12176. }
  12177. /*Core Profile*/
  12178. //AllowOfflineTxForUnknownId
  12179. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12183. //AuthorizationCacheEnabled
  12184. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12188. //AuthorizeRemoteTxRequests
  12189. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12193. //BlinkRepeat
  12194. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12198. //ClockAlignedDataInterval
  12199. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12203. //ConnectionTimeOut
  12204. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12208. //GetConfigurationMaxKeys
  12209. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12213. // HeartbeatInterval
  12214. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12218. // LightIntensity
  12219. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12223. // LocalAuthorizeOffline
  12224. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12228. // LocalPreAuthorize
  12229. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12233. // MaxEnergyOnInvalidId
  12234. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12238. // MeterValuesAlignedData
  12239. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12243. else
  12244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12246. // MeterValuesAlignedDataMaxLength
  12247. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  12251. else
  12252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  12253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12254. // MeterValuesSampledData
  12255. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12259. else
  12260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12262. // MeterValuesSampledDataMaxLength
  12263. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  12267. else
  12268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  12269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12270. // MeterValueSampleInterval
  12271. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12275. // MinimumStatusDuration
  12276. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12279. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12281. // NumberOfConnectors
  12282. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12285. {
  12286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12287. }
  12288. else
  12289. {
  12290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12291. }
  12292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12293. // ResetRetries
  12294. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12298. // ConnectorPhaseRotation
  12299. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12303. // ConnectorPhaseRotationMaxLength
  12304. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12308. // StopTransactionOnEVSideDisconnect
  12309. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12313. // StopTransactionOnInvalidId
  12314. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12318. // StopTxnAlignedData
  12319. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12323. // StopTxnAlignedDataMaxLength
  12324. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12328. // StopTxnSampledData
  12329. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12333. else
  12334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12336. // StopTxnSampledDataMaxLength
  12337. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12339. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12340. {
  12341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12342. }
  12343. else
  12344. {
  12345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12346. }
  12347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12348. // SupportedFeatureProfiles
  12349. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12353. // SupportedFeatureProfilesMaxLength
  12354. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12358. // TransactionMessageAttempts
  12359. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12362. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12364. // TransactionMessageRetryInterval
  12365. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12368. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12370. // UnlockConnectorOnEVSideDisconnect
  12371. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12375. // WebSocketPingInterval
  12376. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12380. // QueueOffLineStartTransactionMessage
  12381. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12385. // AuthorizationKey
  12386. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12390. // SecurityProfile
  12391. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12395. // DefaultPrice
  12396. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12400. // CustomDisplayCostAndPrice
  12401. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12405. // CustomIdleFeeAfterStop
  12406. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12410. // TimeOffset
  12411. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12415. // NextTimeOffsetTransitionDateTime
  12416. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12420. // TimeOffsetNextTransition
  12421. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12425. // Configuration Version
  12426. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12430. //* Local Auth List Management Profile*/
  12431. #if 0
  12432. //For OCTT Test Case
  12433. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12436. #endif
  12437. #if 1
  12438. //LocalAuthListEnabled
  12439. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12443. #endif
  12444. //LocalAuthListMaxLength
  12445. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12448. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12449. //SendLocalListMaxLength
  12450. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12454. //ReserveConnectorZeroSupported
  12455. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12459. //* Smart Charging Profile */
  12460. //ChargeProfileMaxStackLevel
  12461. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12465. // ChargingScheduleAllowedChargingRateUnit
  12466. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12470. // ChargingScheduleMaxPeriods
  12471. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12475. // ConnectorSwitch3to1PhaseSupported
  12476. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12480. // MaxChargingProfilesInstalled
  12481. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12485. fclose(outfile);
  12486. }
  12487. else
  12488. {
  12489. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12490. char keystr[60]={0};
  12491. char readonlystr[10]={0};
  12492. char valuestr[256]={0};
  12493. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12494. if(fp == NULL) {
  12495. DEBUG_INFO("Error opening file");
  12496. return FALSE;
  12497. }
  12498. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12499. {
  12500. //DEBUG_INFO("Get Configuration \n");
  12501. if(strlen(str) > 0)
  12502. {
  12503. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12504. //*************************key*********************************/
  12505. if(strstr(str, "key") != NULL)
  12506. {
  12507. loc = strstr(str, "key");
  12508. c = 0;
  12509. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12510. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12511. {
  12512. sstr[c] = loc[strlen("key")+3+c];
  12513. c++;
  12514. }
  12515. sstr[c] = '\0';
  12516. strcpy(keystr,sstr);
  12517. }
  12518. //*************************readonly*********************************/
  12519. if(strstr(str, "readonly") != NULL)
  12520. {
  12521. loc = strstr(str, "readonly");
  12522. c = 0;
  12523. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12524. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12525. {
  12526. sstr[c] = loc[strlen("readonly")+2+c];
  12527. c++;
  12528. }
  12529. sstr[c] = '\0';
  12530. strcpy(readonlystr,sstr);
  12531. }
  12532. //*************************value*********************************/
  12533. if(strstr(str, "value") != NULL)
  12534. {
  12535. loc = strstr(str, "value");
  12536. c = 0;
  12537. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12538. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12539. {
  12540. sstr[c] = loc[strlen("value")+3+c];
  12541. c++;
  12542. }
  12543. sstr[c] = '\0';
  12544. strcpy(valuestr,sstr);
  12545. }
  12546. // DEBUG_INFO("keystr=%s\n",keystr);
  12547. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12548. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12549. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12550. {
  12551. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12552. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12554. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12555. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12556. }
  12557. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12558. {
  12559. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12560. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12562. }
  12563. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12564. {
  12565. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12567. }
  12568. if(strcmp(keystr, "BlinkRepeat") == 0)
  12569. {
  12570. //Charger.BlinkRepeat = Integer.parseInt(value);
  12571. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12573. }
  12574. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12575. {
  12576. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12578. }
  12579. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12580. {
  12581. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12583. }
  12584. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12585. {
  12586. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12588. }
  12589. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12590. {
  12591. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12593. HeartBeatWaitTime = atoi(valuestr);
  12594. }
  12595. if(strcmp(keystr, "LightIntensity") == 0)
  12596. {
  12597. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12599. }
  12600. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12601. {
  12602. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12604. }
  12605. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12606. {
  12607. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12609. }
  12610. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12611. {
  12612. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12614. }
  12615. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12616. {
  12617. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12619. }
  12620. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12621. {
  12622. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12624. }
  12625. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12626. {
  12627. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12629. }
  12630. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12631. {
  12632. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12634. }
  12635. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12636. {
  12637. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12639. }
  12640. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12641. {
  12642. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12644. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12645. }
  12646. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12647. {
  12648. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12650. }
  12651. if(strcmp(keystr, "ResetRetries") == 0)
  12652. {
  12653. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12655. }
  12656. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12657. {
  12658. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12660. }
  12661. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12662. {
  12663. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12665. }
  12666. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12667. {
  12668. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12670. }
  12671. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12672. {
  12673. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12675. }
  12676. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12677. {
  12678. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12680. }
  12681. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12682. {
  12683. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12685. }
  12686. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12687. {
  12688. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12690. }
  12691. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12692. {
  12693. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12695. }
  12696. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12697. {
  12698. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12700. }
  12701. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12702. {
  12703. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12705. }
  12706. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12707. {
  12708. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12710. TransactionMessageAttemptsValue = atoi(valuestr);
  12711. }
  12712. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12713. {
  12714. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12716. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12717. }
  12718. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12719. {
  12720. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12722. }
  12723. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12724. {
  12725. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12727. }
  12728. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12729. {
  12730. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12732. }
  12733. if(strcmp(keystr, "AuthorizationKey") == 0)
  12734. {
  12735. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12736. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12738. }
  12739. if(strcmp(keystr, "SecurityProfile") == 0)
  12740. {
  12741. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12743. }
  12744. if(strcmp(keystr, "DefaultPrice") == 0)
  12745. {
  12746. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12748. }
  12749. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12750. {
  12751. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12753. }
  12754. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12755. {
  12756. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12758. }
  12759. if(strcmp(keystr, "TimeOffset") == 0)
  12760. {
  12761. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12763. }
  12764. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12765. {
  12766. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12768. }
  12769. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12770. {
  12771. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12773. }
  12774. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12775. {
  12776. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12778. }
  12779. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12780. {
  12781. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12783. }
  12784. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12785. {
  12786. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12788. }
  12789. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12790. {
  12791. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12793. }
  12794. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12795. {
  12796. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12798. }
  12799. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12800. {
  12801. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12803. }
  12804. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12805. {
  12806. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12808. }
  12809. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12810. {
  12811. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12813. }
  12814. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12815. {
  12816. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12818. }
  12819. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12820. {
  12821. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12823. }
  12824. }
  12825. }
  12826. fclose(fp);
  12827. }
  12828. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12829. {
  12830. return PASS;
  12831. }
  12832. else
  12833. {
  12834. return FAIL;
  12835. }
  12836. }
  12837. void StoreConfigurationTable(void)
  12838. {
  12839. FILE *outfile;
  12840. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12841. if(outfile == NULL)
  12842. {
  12843. DEBUG_INFO("Error opening file");
  12844. return ;
  12845. }
  12846. /*Core Profile*/
  12847. //AllowOfflineTxForUnknownId
  12848. /*
  12849. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12850. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12853. */
  12854. //DEBUG_INFO("data=%s\n",data);
  12855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12856. //AuthorizationCacheEnabled
  12857. /*
  12858. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12861. */
  12862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12863. //AuthorizeRemoteTxRequests
  12864. /*
  12865. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12868. */
  12869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12870. //BlinkRepeat
  12871. /*
  12872. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12875. */
  12876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12877. //ClockAlignedDataInterval
  12878. /*
  12879. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12882. */
  12883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12884. //ConnectionTimeOut
  12885. /*
  12886. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12889. */
  12890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12891. //GetConfigurationMaxKeys
  12892. /*
  12893. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12896. */
  12897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12898. // HeartbeatInterval
  12899. /*
  12900. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12903. */
  12904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12905. // LightIntensity
  12906. /*
  12907. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12910. */
  12911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12912. // LocalAuthorizeOffline
  12913. /*
  12914. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12917. */
  12918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12919. // LocalPreAuthorize
  12920. /*
  12921. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12924. */
  12925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12926. // MaxEnergyOnInvalidId
  12927. /*
  12928. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12931. */
  12932. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12934. // MeterValuesAlignedData
  12935. /*
  12936. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12939. */
  12940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12941. // MeterValuesAlignedDataMaxLength
  12942. /*
  12943. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12946. */
  12947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12948. // MeterValuesSampledData
  12949. /*
  12950. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12953. */
  12954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12955. // MeterValuesSampledDataMaxLength
  12956. /*
  12957. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12960. */
  12961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12962. // MeterValueSampleInterval
  12963. /*
  12964. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12967. */
  12968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12969. // MinimumStatusDuration
  12970. /*
  12971. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12974. */
  12975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12976. // NumberOfConnectors
  12977. /*
  12978. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12981. {
  12982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12983. }
  12984. else
  12985. {
  12986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12987. }
  12988. */
  12989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12990. // ResetRetries
  12991. /*
  12992. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12995. */
  12996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12997. // ConnectorPhaseRotation
  12998. /*
  12999. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13002. */
  13003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13004. // ConnectorPhaseRotationMaxLength
  13005. /*
  13006. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13009. */
  13010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13011. // StopTransactionOnEVSideDisconnect
  13012. /*
  13013. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13016. */
  13017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13018. // StopTransactionOnInvalidId
  13019. /*
  13020. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13023. */
  13024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13025. // StopTxnAlignedData
  13026. /*
  13027. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13030. */
  13031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13032. // StopTxnAlignedDataMaxLength
  13033. /*
  13034. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13037. */
  13038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13039. // StopTxnSampledData
  13040. /*
  13041. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13044. */
  13045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13046. // StopTxnSampledDataMaxLength
  13047. /*
  13048. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13051. */
  13052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13053. // SupportedFeatureProfiles
  13054. /*
  13055. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13058. */
  13059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13060. // SupportedFeatureProfilesMaxLength
  13061. /*
  13062. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13065. */
  13066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13067. // TransactionMessageAttempts
  13068. /*
  13069. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13072. */
  13073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13074. // TransactionMessageRetryInterval
  13075. /*
  13076. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13079. */
  13080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13081. // UnlockConnectorOnEVSideDisconnect
  13082. /*
  13083. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13086. */
  13087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13088. // WebSocketPingInterval
  13089. /*
  13090. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13093. */
  13094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13095. // QueueOffLineStartTransactionMessage
  13096. /*
  13097. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  13098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  13099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  13100. */
  13101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  13102. // AuthorizationKey
  13103. /*
  13104. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13107. */
  13108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13109. // SecurityProfile
  13110. /*
  13111. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13114. */
  13115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13116. // DefaultPrice
  13117. /*
  13118. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13121. */
  13122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13123. // CustomDisplayCostAndPrice
  13124. /*
  13125. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13128. */
  13129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13130. // CustomIdleFeeAfterStop
  13131. /*
  13132. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13135. */
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13137. // TimeOffset
  13138. /*
  13139. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13142. */
  13143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13144. // NextTimeOffsetTransitionDateTime
  13145. /*
  13146. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13149. */
  13150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13151. // TimeOffsetNextTransition
  13152. /*
  13153. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13156. */
  13157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13158. // ConfigurationVersion
  13159. /*
  13160. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13163. */
  13164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13165. //* Local Auth List Management Profile*/
  13166. //LocalAuthListEnabled
  13167. /*
  13168. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13171. */
  13172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13173. //LocalAuthListMaxLength
  13174. /*
  13175. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13178. */
  13179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13180. //SendLocalListMaxLength
  13181. /*
  13182. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13185. */
  13186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13187. //ReserveConnectorZeroSupported
  13188. /*
  13189. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13192. */
  13193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13194. //* Smart Charging Profile */
  13195. //ChargeProfileMaxStackLevel
  13196. /*
  13197. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13200. */
  13201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13202. // ChargingScheduleAllowedChargingRateUnit
  13203. /*
  13204. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13207. */
  13208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13209. // ChargingScheduleMaxPeriods
  13210. /*
  13211. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13214. */
  13215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13216. // ConnectorSwitch3to1PhaseSupported
  13217. /*
  13218. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13221. */
  13222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13223. // MaxChargingProfilesInstalled
  13224. /*
  13225. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13228. */
  13229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13230. fclose(outfile);
  13231. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13232. }
  13233. void getKeyValue(char *keyReq)
  13234. {
  13235. int isEmpty = FALSE;
  13236. int isKnowKey = FALSE;
  13237. DEBUG_INFO("keyReq = %s\n", keyReq);
  13238. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13239. isEmpty = TRUE;
  13240. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13241. {
  13242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13245. {
  13246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13247. }
  13248. else
  13249. {
  13250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13251. }
  13252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13253. isKnowKey = TRUE;
  13254. }
  13255. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13256. {
  13257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13260. {
  13261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13262. }
  13263. else
  13264. {
  13265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13266. }
  13267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13268. isKnowKey = TRUE;
  13269. }
  13270. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13271. {
  13272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13275. {
  13276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13277. }
  13278. else
  13279. {
  13280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13281. }
  13282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13283. isKnowKey = TRUE;
  13284. }
  13285. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13286. {
  13287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13290. {
  13291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13292. }
  13293. else
  13294. {
  13295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13296. }
  13297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13298. isKnowKey = TRUE;
  13299. }
  13300. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13301. {
  13302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13305. {
  13306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13307. }
  13308. else
  13309. {
  13310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13311. }
  13312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13313. isKnowKey = TRUE;
  13314. }
  13315. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13316. {
  13317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13320. {
  13321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13322. }
  13323. else
  13324. {
  13325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13326. }
  13327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13328. isKnowKey = TRUE;
  13329. }
  13330. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13331. {
  13332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13335. {
  13336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13337. }
  13338. else
  13339. {
  13340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13341. }
  13342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13343. isKnowKey = TRUE;
  13344. }
  13345. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13346. {
  13347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13350. {
  13351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13352. }
  13353. else
  13354. {
  13355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13356. }
  13357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13358. isKnowKey = TRUE;
  13359. }
  13360. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13361. {
  13362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13365. {
  13366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13367. }
  13368. else
  13369. {
  13370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13371. }
  13372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13373. isKnowKey = TRUE;
  13374. }
  13375. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13376. {
  13377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13380. {
  13381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13382. }
  13383. else
  13384. {
  13385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13386. }
  13387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13388. isKnowKey = TRUE;
  13389. }
  13390. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13391. {
  13392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13395. {
  13396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13397. }
  13398. else
  13399. {
  13400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13401. }
  13402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13403. isKnowKey = TRUE;
  13404. }
  13405. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13406. {
  13407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13410. {
  13411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13412. }
  13413. else
  13414. {
  13415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13416. }
  13417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13418. isKnowKey = TRUE;
  13419. }
  13420. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13421. {
  13422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13425. {
  13426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13427. }
  13428. else
  13429. {
  13430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13431. }
  13432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13433. isKnowKey = TRUE;
  13434. }
  13435. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13436. {
  13437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13440. {
  13441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13442. }
  13443. else
  13444. {
  13445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13446. }
  13447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13448. isKnowKey = TRUE;
  13449. }
  13450. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13451. {
  13452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13455. {
  13456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13457. }
  13458. else
  13459. {
  13460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13461. }
  13462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13463. isKnowKey = TRUE;
  13464. }
  13465. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13466. {
  13467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13470. {
  13471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13472. }
  13473. else
  13474. {
  13475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13476. }
  13477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13478. isKnowKey = TRUE;
  13479. }
  13480. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13481. {
  13482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13485. {
  13486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13487. }
  13488. else
  13489. {
  13490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13491. }
  13492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13493. isKnowKey = TRUE;
  13494. }
  13495. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13496. {
  13497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13500. {
  13501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13502. }
  13503. else
  13504. {
  13505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13506. }
  13507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13508. isKnowKey = TRUE;
  13509. }
  13510. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13511. {
  13512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13515. {
  13516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13517. }
  13518. else
  13519. {
  13520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13521. }
  13522. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13524. isKnowKey = TRUE;
  13525. }
  13526. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13527. {
  13528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13531. {
  13532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13533. }
  13534. else
  13535. {
  13536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13537. }
  13538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13539. isKnowKey = TRUE;
  13540. }
  13541. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13542. {
  13543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13546. {
  13547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13548. }
  13549. else
  13550. {
  13551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13552. }
  13553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13554. isKnowKey = TRUE;
  13555. }
  13556. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13557. {
  13558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13561. {
  13562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13563. }
  13564. else
  13565. {
  13566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13567. }
  13568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13569. isKnowKey = TRUE;
  13570. }
  13571. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13572. {
  13573. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13576. {
  13577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13578. }
  13579. else
  13580. {
  13581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13582. }
  13583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13584. isKnowKey = TRUE;
  13585. }
  13586. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13587. {
  13588. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13591. {
  13592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13593. }
  13594. else
  13595. {
  13596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13597. }
  13598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13599. isKnowKey = TRUE;
  13600. }
  13601. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13602. {
  13603. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13606. {
  13607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13608. }
  13609. else
  13610. {
  13611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13612. }
  13613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13614. isKnowKey = TRUE;
  13615. }
  13616. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13617. {
  13618. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13621. {
  13622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13623. }
  13624. else
  13625. {
  13626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13627. }
  13628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13629. isKnowKey = TRUE;
  13630. }
  13631. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13632. {
  13633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13636. {
  13637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13638. }
  13639. else
  13640. {
  13641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13642. }
  13643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13644. isKnowKey = TRUE;
  13645. }
  13646. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13647. {
  13648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13651. {
  13652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13653. }
  13654. else
  13655. {
  13656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13657. }
  13658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13659. isKnowKey = TRUE;
  13660. }
  13661. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13662. {
  13663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13666. {
  13667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13668. }
  13669. else
  13670. {
  13671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13672. }
  13673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13674. isKnowKey = TRUE;
  13675. }
  13676. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13677. {
  13678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13681. {
  13682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13683. }
  13684. else
  13685. {
  13686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13687. }
  13688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13689. isKnowKey = TRUE;
  13690. }
  13691. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13692. {
  13693. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13696. {
  13697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13698. }
  13699. else
  13700. {
  13701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13702. }
  13703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13704. isKnowKey = TRUE;
  13705. }
  13706. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13707. {
  13708. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13710. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13711. {
  13712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13713. }
  13714. else
  13715. {
  13716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13717. }
  13718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13719. isKnowKey = TRUE;
  13720. }
  13721. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13722. {
  13723. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13725. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13726. {
  13727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13728. }
  13729. else
  13730. {
  13731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13732. }
  13733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13734. isKnowKey = TRUE;
  13735. }
  13736. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13737. {
  13738. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13741. {
  13742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13743. }
  13744. else
  13745. {
  13746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13747. }
  13748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13749. isKnowKey = TRUE;
  13750. }
  13751. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13752. {
  13753. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13756. {
  13757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13758. }
  13759. else
  13760. {
  13761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13762. }
  13763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13764. isKnowKey = TRUE;
  13765. }
  13766. /*
  13767. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13768. {
  13769. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13772. {
  13773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13774. }
  13775. else
  13776. {
  13777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13778. }
  13779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13780. isKnowKey = TRUE;
  13781. }*/
  13782. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13783. {
  13784. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13787. {
  13788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13789. }
  13790. else
  13791. {
  13792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13793. }
  13794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13795. isKnowKey = TRUE;
  13796. }
  13797. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13798. {
  13799. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13801. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13802. {
  13803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13804. }
  13805. else
  13806. {
  13807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13808. }
  13809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13810. isKnowKey = TRUE;
  13811. }
  13812. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13813. {
  13814. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13817. {
  13818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13819. }
  13820. else
  13821. {
  13822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13823. }
  13824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13825. isKnowKey = TRUE;
  13826. }
  13827. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13828. {
  13829. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13832. {
  13833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13834. }
  13835. else
  13836. {
  13837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13838. }
  13839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13840. isKnowKey = TRUE;
  13841. }
  13842. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13843. {
  13844. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13847. {
  13848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13849. }
  13850. else
  13851. {
  13852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13853. }
  13854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13855. isKnowKey = TRUE;
  13856. }
  13857. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13858. {
  13859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13862. {
  13863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13864. }
  13865. else
  13866. {
  13867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13868. }
  13869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13870. isKnowKey = TRUE;
  13871. }
  13872. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13873. {
  13874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13877. {
  13878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13879. }
  13880. else
  13881. {
  13882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13883. }
  13884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13885. isKnowKey = TRUE;
  13886. }
  13887. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13888. {
  13889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13892. {
  13893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13894. }
  13895. else
  13896. {
  13897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13898. }
  13899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13900. isKnowKey = TRUE;
  13901. }
  13902. #if 1
  13903. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13904. {
  13905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13907. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13908. {
  13909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13910. }
  13911. else
  13912. {
  13913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13914. }
  13915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13916. isKnowKey = TRUE;
  13917. }
  13918. #endif
  13919. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13920. {
  13921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13923. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13924. {
  13925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13926. }
  13927. else
  13928. {
  13929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13930. }
  13931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13932. isKnowKey = TRUE;
  13933. }
  13934. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13935. {
  13936. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13938. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13939. {
  13940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13941. }
  13942. else
  13943. {
  13944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13945. }
  13946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13947. isKnowKey = TRUE;
  13948. }
  13949. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13950. {
  13951. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13953. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13954. {
  13955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13956. }
  13957. else
  13958. {
  13959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13960. }
  13961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13962. isKnowKey = TRUE;
  13963. }
  13964. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13965. {
  13966. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13968. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13969. {
  13970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13971. }
  13972. else
  13973. {
  13974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13975. }
  13976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13977. isKnowKey = TRUE;
  13978. }
  13979. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13980. {
  13981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13983. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13984. {
  13985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13986. }
  13987. else
  13988. {
  13989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13990. }
  13991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13992. isKnowKey = TRUE;
  13993. }
  13994. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13995. {
  13996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13998. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13999. {
  14000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14001. }
  14002. else
  14003. {
  14004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14005. }
  14006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14007. isKnowKey = TRUE;
  14008. }
  14009. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14010. {
  14011. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14013. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14014. {
  14015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14016. }
  14017. else
  14018. {
  14019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14020. }
  14021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14022. isKnowKey = TRUE;
  14023. }
  14024. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14025. {
  14026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14028. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14029. {
  14030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14031. }
  14032. else
  14033. {
  14034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14035. }
  14036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14037. isKnowKey = TRUE;
  14038. }
  14039. //=========================================================
  14040. if(!isEmpty && !isKnowKey)
  14041. {
  14042. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14043. strcpy(unknownkey[UnknownKeynum], keyReq);
  14044. UnknownKeynum = UnknownKeynum + 1;
  14045. }
  14046. }
  14047. void processUnkownKey(void)
  14048. {
  14049. DEBUG_INFO("processUnkownKey...\n");
  14050. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14051. for(int index=0; index < UnknownKeynum; index++)
  14052. {
  14053. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14054. {
  14055. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14056. }
  14057. }
  14058. }
  14059. int setKeyValue(char *key, char *value)
  14060. {
  14061. int isSuccess = NotSupported;
  14062. int check_ascii=0;
  14063. char str[256]={0};
  14064. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14065. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14066. {
  14067. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14069. {
  14070. strcpy(str, (const char*)value);
  14071. for(int i = 0; str[i]; i++){
  14072. str[i] = tolower(str[i]);
  14073. }
  14074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14075. isSuccess = ConfigurationStatus_Accepted;
  14076. }
  14077. else
  14078. {
  14079. isSuccess = ConfigurationStatus_Rejected;
  14080. }
  14081. }
  14082. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14083. {
  14084. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14086. {
  14087. strcpy(str, (const char*)value);
  14088. for(int i = 0; str[i]; i++){
  14089. str[i] = tolower(str[i]);
  14090. }
  14091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14092. isSuccess = ConfigurationStatus_Accepted;
  14093. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14094. }
  14095. else
  14096. {
  14097. isSuccess = ConfigurationStatus_Rejected;
  14098. }
  14099. }
  14100. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14101. {
  14102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14103. {
  14104. strcpy(str, (const char*)value);
  14105. for(int i = 0; str[i]; i++)
  14106. {
  14107. str[i] = tolower(str[i]);
  14108. }
  14109. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14111. isSuccess = ConfigurationStatus_Accepted;
  14112. }
  14113. else
  14114. {
  14115. isSuccess = ConfigurationStatus_Rejected;
  14116. }
  14117. }
  14118. if(strcmp(key, "BlinkRepeat") == 0)
  14119. {
  14120. //Charger.BlinkRepeat = Integer.parseInt(value);
  14121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14122. {
  14123. check_ascii = value[0];
  14124. if( (check_ascii < 48) || (check_ascii > 57) )
  14125. {
  14126. isSuccess = ConfigurationStatus_Rejected;
  14127. }
  14128. else
  14129. {
  14130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14131. isSuccess = ConfigurationStatus_Accepted;
  14132. }
  14133. }
  14134. else
  14135. {
  14136. isSuccess = ConfigurationStatus_Rejected;
  14137. }
  14138. }
  14139. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14140. {
  14141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14142. {
  14143. check_ascii = value[0];
  14144. if( (check_ascii < 48) || (check_ascii > 57) )
  14145. {
  14146. isSuccess = ConfigurationStatus_Rejected;
  14147. }
  14148. else
  14149. {
  14150. if((atoi(value) == 0) || (atoi(value) >= 10))
  14151. {
  14152. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14154. isSuccess = ConfigurationStatus_Accepted;
  14155. }
  14156. else
  14157. isSuccess = ConfigurationStatus_Rejected;
  14158. }
  14159. }
  14160. else
  14161. {
  14162. isSuccess = ConfigurationStatus_Rejected;
  14163. }
  14164. }
  14165. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14166. {
  14167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14168. {
  14169. check_ascii = value[0];
  14170. if( (check_ascii < 48) || (check_ascii > 57) )
  14171. {
  14172. isSuccess = ConfigurationStatus_Rejected;
  14173. }
  14174. else
  14175. {
  14176. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14178. isSuccess = ConfigurationStatus_Accepted;
  14179. }
  14180. }
  14181. else
  14182. {
  14183. isSuccess = ConfigurationStatus_Rejected;
  14184. }
  14185. }
  14186. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14187. {
  14188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14189. {
  14190. check_ascii = value[0];
  14191. if( (check_ascii < 48) || (check_ascii > 57) )
  14192. {
  14193. isSuccess = ConfigurationStatus_Rejected;
  14194. }
  14195. else
  14196. {
  14197. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14199. isSuccess = ConfigurationStatus_Accepted;
  14200. }
  14201. }
  14202. else
  14203. {
  14204. isSuccess = ConfigurationStatus_Rejected;
  14205. }
  14206. }
  14207. if(strcmp(key, "HeartbeatInterval") == 0)
  14208. {
  14209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14210. {
  14211. check_ascii = value[0];
  14212. if( (check_ascii < 48) || (check_ascii > 57) )
  14213. {
  14214. isSuccess = ConfigurationStatus_Rejected;
  14215. }
  14216. else
  14217. {
  14218. if((atoi(value) == 0) || (atoi(value) >= 10))
  14219. {
  14220. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14222. HeartBeatWaitTime = atoi(value);
  14223. isSuccess = ConfigurationStatus_Accepted;
  14224. }
  14225. else
  14226. {
  14227. isSuccess = ConfigurationStatus_Rejected;
  14228. }
  14229. }
  14230. }
  14231. else
  14232. {
  14233. isSuccess = ConfigurationStatus_Rejected;
  14234. }
  14235. }
  14236. if(strcmp(key, "LightIntensity") == 0)
  14237. {
  14238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14239. {
  14240. check_ascii = value[0];
  14241. if( (check_ascii < 48) || (check_ascii > 57) )
  14242. {
  14243. isSuccess = ConfigurationStatus_Rejected;
  14244. }
  14245. else
  14246. {
  14247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14248. isSuccess = ConfigurationStatus_Accepted;
  14249. }
  14250. }
  14251. else
  14252. {
  14253. isSuccess = ConfigurationStatus_Rejected;
  14254. }
  14255. }
  14256. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14257. {
  14258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14259. {
  14260. strcpy(str, (const char*)value);
  14261. for(int i = 0; str[i]; i++)
  14262. {
  14263. str[i] = tolower(str[i]);
  14264. }
  14265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14266. isSuccess = ConfigurationStatus_Accepted;
  14267. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14268. }
  14269. else
  14270. {
  14271. isSuccess = ConfigurationStatus_Rejected;
  14272. }
  14273. }
  14274. if(strcmp(key, "LocalPreAuthorize") == 0)
  14275. {
  14276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14277. {
  14278. strcpy(str, (const char*)value);
  14279. for(int i = 0; str[i]; i++)
  14280. {
  14281. str[i] = tolower(str[i]);
  14282. }
  14283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14284. isSuccess = ConfigurationStatus_Accepted;
  14285. }
  14286. else
  14287. {
  14288. isSuccess = ConfigurationStatus_Rejected;
  14289. }
  14290. }
  14291. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14292. {
  14293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14294. {
  14295. check_ascii = value[0];
  14296. if( (check_ascii < 48) || (check_ascii > 57) )
  14297. {
  14298. isSuccess = ConfigurationStatus_Rejected;
  14299. }
  14300. else
  14301. {
  14302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14303. isSuccess = ConfigurationStatus_Accepted;
  14304. }
  14305. }
  14306. else
  14307. {
  14308. isSuccess = ConfigurationStatus_Rejected;
  14309. }
  14310. }
  14311. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14312. {
  14313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14314. {
  14315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14316. isSuccess = ConfigurationStatus_Accepted;
  14317. }
  14318. else
  14319. {
  14320. isSuccess = ConfigurationStatus_Rejected;
  14321. }
  14322. }
  14323. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14324. {
  14325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14326. {
  14327. check_ascii = value[0];
  14328. if( (check_ascii < 48) || (check_ascii > 57) )
  14329. {
  14330. isSuccess = ConfigurationStatus_Rejected;
  14331. }
  14332. else
  14333. {
  14334. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14336. isSuccess = ConfigurationStatus_Accepted;
  14337. }
  14338. }
  14339. else
  14340. {
  14341. isSuccess = ConfigurationStatus_Rejected;
  14342. }
  14343. }
  14344. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14345. {
  14346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14347. {
  14348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14349. isSuccess = ConfigurationStatus_Accepted;
  14350. }
  14351. else
  14352. {
  14353. isSuccess = ConfigurationStatus_Rejected;
  14354. }
  14355. }
  14356. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14357. {
  14358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14359. {
  14360. check_ascii = value[0];
  14361. if( (check_ascii < 48) || (check_ascii > 57) )
  14362. {
  14363. isSuccess = ConfigurationStatus_Rejected;
  14364. }
  14365. else
  14366. {
  14367. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14369. isSuccess = ConfigurationStatus_Accepted;
  14370. }
  14371. }
  14372. else
  14373. {
  14374. isSuccess = ConfigurationStatus_Rejected;
  14375. }
  14376. }
  14377. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14378. {
  14379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14380. {
  14381. check_ascii = value[0];
  14382. if( (check_ascii < 48) || (check_ascii > 57) )
  14383. {
  14384. isSuccess = ConfigurationStatus_Rejected;
  14385. }
  14386. else
  14387. {
  14388. if((atoi(value) == 0) || (atoi(value) >= 10))
  14389. {
  14390. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14392. isSuccess = ConfigurationStatus_Accepted;
  14393. }
  14394. else
  14395. {
  14396. isSuccess = ConfigurationStatus_Rejected;
  14397. }
  14398. }
  14399. }
  14400. else
  14401. {
  14402. isSuccess = ConfigurationStatus_Rejected;
  14403. }
  14404. }
  14405. if(strcmp(key, "MinimumStatusDuration") == 0)
  14406. {
  14407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14408. {
  14409. check_ascii = value[0];
  14410. if( (check_ascii < 48) || (check_ascii > 57) )
  14411. {
  14412. isSuccess = ConfigurationStatus_Rejected;
  14413. }
  14414. else
  14415. {
  14416. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14417. {
  14418. isSuccess = ConfigurationStatus_Rejected;
  14419. }
  14420. else
  14421. {
  14422. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14424. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14425. isSuccess = ConfigurationStatus_Accepted;
  14426. }
  14427. }
  14428. }
  14429. else
  14430. {
  14431. isSuccess = ConfigurationStatus_Rejected;
  14432. }
  14433. }
  14434. if(strcmp(key, "NumberOfConnectors") == 0)
  14435. {
  14436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14437. {
  14438. check_ascii = value[0];
  14439. if( (check_ascii < 48) || (check_ascii > 57) )
  14440. {
  14441. isSuccess = ConfigurationStatus_Rejected;
  14442. }
  14443. else
  14444. {
  14445. //Charger.ResetRetries = Integer.parseInt(value);
  14446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14447. isSuccess = ConfigurationStatus_Accepted;
  14448. }
  14449. }
  14450. else
  14451. {
  14452. isSuccess = ConfigurationStatus_Rejected;
  14453. }
  14454. }
  14455. if(strcmp(key, "ResetRetries") == 0)
  14456. {
  14457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14458. {
  14459. check_ascii = value[0];
  14460. if( (check_ascii < 48) || (check_ascii > 57) )
  14461. {
  14462. isSuccess = ConfigurationStatus_Rejected;
  14463. }
  14464. else
  14465. {
  14466. //Charger.ResetRetries = Integer.parseInt(value);
  14467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14468. isSuccess = ConfigurationStatus_Accepted;
  14469. }
  14470. }
  14471. else
  14472. {
  14473. isSuccess = ConfigurationStatus_Rejected;
  14474. }
  14475. }
  14476. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14477. {
  14478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14479. {
  14480. strcpy(str, (const char*)value);
  14481. for(int i = 0; str[i]; i++)
  14482. {
  14483. str[i] = tolower(str[i]);
  14484. }
  14485. if(strcmp(str, "notapplicable")== 0)
  14486. {
  14487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14488. isSuccess = ConfigurationStatus_Accepted;
  14489. }
  14490. else if(strcmp(str, "unknown")== 0)
  14491. {
  14492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14493. isSuccess = ConfigurationStatus_Accepted;
  14494. }
  14495. else if(strcmp(str, "rst")== 0)
  14496. {
  14497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14498. isSuccess = ConfigurationStatus_Accepted;
  14499. }
  14500. else if(strcmp(str, "rts")== 0)
  14501. {
  14502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14503. isSuccess = ConfigurationStatus_Accepted;
  14504. }
  14505. else if(strcmp(str, "srt")== 0)
  14506. {
  14507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14508. isSuccess = ConfigurationStatus_Accepted;
  14509. }
  14510. else if(strcmp(str, "str")== 0)
  14511. {
  14512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14513. isSuccess = ConfigurationStatus_Accepted;
  14514. }
  14515. else if(strcmp(str, "trs")== 0)
  14516. {
  14517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14518. isSuccess = ConfigurationStatus_Accepted;
  14519. }
  14520. else if(strcmp(str, "tsr")== 0)
  14521. {
  14522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14523. isSuccess = ConfigurationStatus_Accepted;
  14524. }
  14525. else
  14526. {
  14527. isSuccess = ConfigurationStatus_Rejected;
  14528. }
  14529. }
  14530. else
  14531. {
  14532. isSuccess = ConfigurationStatus_Rejected;
  14533. }
  14534. }
  14535. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14536. {
  14537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14538. {
  14539. check_ascii = value[0];
  14540. if( (check_ascii < 48) || (check_ascii > 57) )
  14541. {
  14542. isSuccess = ConfigurationStatus_Rejected;
  14543. }
  14544. else
  14545. {
  14546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14547. isSuccess = ConfigurationStatus_Accepted;
  14548. }
  14549. }
  14550. else
  14551. {
  14552. isSuccess = ConfigurationStatus_Rejected;
  14553. }
  14554. }
  14555. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14556. {
  14557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14558. {
  14559. strcpy(str, (const char*)value);
  14560. for(int i = 0; str[i]; i++)
  14561. {
  14562. str[i] = tolower(str[i]);
  14563. }
  14564. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14566. isSuccess = ConfigurationStatus_Accepted;
  14567. }
  14568. else
  14569. {
  14570. isSuccess = ConfigurationStatus_Rejected;
  14571. }
  14572. }
  14573. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14574. {
  14575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14576. {
  14577. strcpy(str, (const char*)value);
  14578. for(int i = 0; str[i]; i++)
  14579. {
  14580. str[i] = tolower(str[i]);
  14581. }
  14582. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14584. isSuccess = ConfigurationStatus_Accepted;
  14585. }
  14586. else
  14587. {
  14588. isSuccess = ConfigurationStatus_Rejected;
  14589. }
  14590. }
  14591. if(strcmp(key, "StopTxnAlignedData") == 0)
  14592. {
  14593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14594. {
  14595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14596. isSuccess = ConfigurationStatus_Accepted;
  14597. }
  14598. else
  14599. {
  14600. isSuccess = ConfigurationStatus_Rejected;
  14601. }
  14602. }
  14603. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14604. {
  14605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14606. {
  14607. check_ascii = value[0];
  14608. if( (check_ascii < 48) || (check_ascii > 57) )
  14609. {
  14610. isSuccess = ConfigurationStatus_Rejected;
  14611. }
  14612. else
  14613. {
  14614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14615. isSuccess = ConfigurationStatus_Accepted;
  14616. }
  14617. }
  14618. else
  14619. {
  14620. isSuccess = ConfigurationStatus_Rejected;
  14621. }
  14622. }
  14623. if(strcmp(key, "StopTxnSampledData") == 0)
  14624. {
  14625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14626. {
  14627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14628. isSuccess = ConfigurationStatus_Accepted;
  14629. }
  14630. else
  14631. {
  14632. isSuccess = ConfigurationStatus_Rejected;
  14633. }
  14634. }
  14635. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14636. {
  14637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14638. {
  14639. check_ascii = value[0];
  14640. if( (check_ascii < 48) || (check_ascii > 57) )
  14641. {
  14642. isSuccess = ConfigurationStatus_Rejected;
  14643. }
  14644. else
  14645. {
  14646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14647. isSuccess = ConfigurationStatus_Accepted;
  14648. }
  14649. }
  14650. else
  14651. {
  14652. isSuccess = ConfigurationStatus_Rejected;
  14653. }
  14654. }
  14655. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14656. {
  14657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14658. {
  14659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14660. isSuccess = ConfigurationStatus_Accepted;
  14661. }
  14662. else
  14663. {
  14664. isSuccess = ConfigurationStatus_Rejected;
  14665. }
  14666. }
  14667. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14668. {
  14669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14670. {
  14671. check_ascii = value[0];
  14672. if( (check_ascii < 48) || (check_ascii > 57) )
  14673. {
  14674. isSuccess = ConfigurationStatus_Rejected;
  14675. }
  14676. else
  14677. {
  14678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14679. isSuccess = ConfigurationStatus_Accepted;
  14680. }
  14681. }
  14682. else
  14683. {
  14684. isSuccess = ConfigurationStatus_Rejected;
  14685. }
  14686. }
  14687. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14688. {
  14689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14690. {
  14691. check_ascii = value[0];
  14692. if( (check_ascii < 48) || (check_ascii > 57) )
  14693. {
  14694. isSuccess = ConfigurationStatus_Rejected;
  14695. }
  14696. else
  14697. {
  14698. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14700. TransactionMessageAttemptsValue = atoi(value);
  14701. isSuccess = ConfigurationStatus_Accepted;
  14702. }
  14703. }
  14704. else
  14705. {
  14706. isSuccess = ConfigurationStatus_Rejected;
  14707. }
  14708. }
  14709. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14710. {
  14711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14712. {
  14713. check_ascii = value[0];
  14714. if( (check_ascii < 48) || (check_ascii > 57) )
  14715. {
  14716. isSuccess = ConfigurationStatus_Rejected;
  14717. }
  14718. else
  14719. {
  14720. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14722. TransactionMessageRetryIntervalValue = atoi(value);
  14723. isSuccess = ConfigurationStatus_Accepted;
  14724. }
  14725. }
  14726. else
  14727. {
  14728. isSuccess = ConfigurationStatus_Rejected;
  14729. }
  14730. }
  14731. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14732. {
  14733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14734. {
  14735. strcpy(str, (const char*)value);
  14736. for(int i = 0; str[i]; i++)
  14737. {
  14738. str[i] = tolower(str[i]);
  14739. }
  14740. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14742. isSuccess = ConfigurationStatus_Accepted;
  14743. }
  14744. else
  14745. {
  14746. isSuccess = ConfigurationStatus_Rejected;
  14747. }
  14748. }
  14749. if(strcmp(key, "WebSocketPingInterval") == 0)
  14750. {
  14751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14752. {
  14753. check_ascii = value[0];
  14754. if( (check_ascii < 48) || (check_ascii > 57) )
  14755. {
  14756. isSuccess = ConfigurationStatus_Rejected;
  14757. }
  14758. else
  14759. {
  14760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14761. isSuccess = ConfigurationStatus_Accepted;
  14762. }
  14763. }
  14764. else
  14765. {
  14766. isSuccess = ConfigurationStatus_Rejected;
  14767. }
  14768. }
  14769. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14770. {
  14771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14772. {
  14773. strcpy(str, (const char*)value);
  14774. for(int i = 0; str[i]; i++)
  14775. {
  14776. str[i] = tolower(str[i]);
  14777. }
  14778. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14780. isSuccess = ConfigurationStatus_Accepted;
  14781. }
  14782. else
  14783. {
  14784. isSuccess = ConfigurationStatus_Rejected;
  14785. }
  14786. }
  14787. if(strcmp(key, "AuthorizationKey") == 0)
  14788. {
  14789. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14790. {
  14791. strcpy(str, (const char*)value);
  14792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14793. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14794. isSuccess = ConfigurationStatus_Accepted;
  14795. }
  14796. else
  14797. {
  14798. isSuccess = ConfigurationStatus_Rejected;
  14799. }
  14800. }
  14801. if(strcmp(key, "SecurityProfile") == 0)
  14802. {
  14803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14804. {
  14805. check_ascii = value[0];
  14806. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14807. {
  14808. isSuccess = ConfigurationStatus_Rejected;
  14809. }
  14810. else if(check_ascii == 0x33)
  14811. {
  14812. isSuccess = NotSupported;
  14813. }
  14814. else
  14815. {
  14816. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14817. {
  14818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14819. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14820. isSuccess = ConfigurationStatus_Accepted;
  14821. }
  14822. else
  14823. isSuccess = ConfigurationStatus_Rejected;
  14824. }
  14825. }
  14826. else
  14827. {
  14828. isSuccess = ConfigurationStatus_Rejected;
  14829. }
  14830. }
  14831. if(strcmp(key, "DefaultPrice") == 0)
  14832. {
  14833. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14834. {
  14835. strcpy(str, (const char*)value);
  14836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14837. isSuccess = ConfigurationStatus_Accepted;
  14838. }
  14839. else
  14840. {
  14841. isSuccess = ConfigurationStatus_Rejected;
  14842. }
  14843. }
  14844. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14845. {
  14846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14847. {
  14848. strcpy(str, (const char*)value);
  14849. for(int i = 0; str[i]; i++)
  14850. {
  14851. str[i] = tolower(str[i]);
  14852. }
  14853. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14855. isSuccess = ConfigurationStatus_Accepted;
  14856. }
  14857. else
  14858. {
  14859. isSuccess = ConfigurationStatus_Rejected;
  14860. }
  14861. }
  14862. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14863. {
  14864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14865. {
  14866. strcpy(str, (const char*)value);
  14867. for(int i = 0; str[i]; i++)
  14868. {
  14869. str[i] = tolower(str[i]);
  14870. }
  14871. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14873. isSuccess = ConfigurationStatus_Accepted;
  14874. }
  14875. else
  14876. {
  14877. isSuccess = ConfigurationStatus_Rejected;
  14878. }
  14879. }
  14880. if(strcmp(key, "TimeOffset") == 0)
  14881. {
  14882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14883. {
  14884. strcpy(str, (const char*)value);
  14885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14886. isSuccess = ConfigurationStatus_Accepted;
  14887. }
  14888. else
  14889. {
  14890. isSuccess = ConfigurationStatus_Rejected;
  14891. }
  14892. }
  14893. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14894. {
  14895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14896. {
  14897. strcpy(str, (const char*)value);
  14898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14899. isSuccess = ConfigurationStatus_Accepted;
  14900. }
  14901. else
  14902. {
  14903. isSuccess = ConfigurationStatus_Rejected;
  14904. }
  14905. }
  14906. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14907. {
  14908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14909. {
  14910. strcpy(str, (const char*)value);
  14911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14912. isSuccess = ConfigurationStatus_Accepted;
  14913. }
  14914. else
  14915. {
  14916. isSuccess = ConfigurationStatus_Rejected;
  14917. }
  14918. }
  14919. #if 0
  14920. //For OCPP Test Case
  14921. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14922. {
  14923. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14924. {
  14925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14926. isSuccess = ConfigurationStatus_Accepted;
  14927. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14928. }
  14929. else
  14930. {
  14931. isSuccess = ConfigurationStatus_Rejected;
  14932. }
  14933. }
  14934. #endif
  14935. #if 1
  14936. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14937. {
  14938. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14939. {
  14940. strcpy(str, (const char*)value);
  14941. for(int i = 0; str[i]; i++)
  14942. {
  14943. str[i] = tolower(str[i]);
  14944. }
  14945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14946. isSuccess = ConfigurationStatus_Accepted;
  14947. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14948. }
  14949. else
  14950. {
  14951. isSuccess = ConfigurationStatus_Rejected;
  14952. }
  14953. }
  14954. #endif
  14955. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14956. {
  14957. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14958. {
  14959. check_ascii = value[0];
  14960. if( (check_ascii < 48) || (check_ascii > 57) )
  14961. {
  14962. isSuccess = ConfigurationStatus_Rejected;
  14963. }
  14964. else
  14965. {
  14966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14967. isSuccess = ConfigurationStatus_Accepted;
  14968. }
  14969. }
  14970. else
  14971. {
  14972. isSuccess = ConfigurationStatus_Rejected;
  14973. }
  14974. }
  14975. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14976. {
  14977. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14978. {
  14979. check_ascii = value[0];
  14980. if( (check_ascii < 48) || (check_ascii > 57) )
  14981. {
  14982. isSuccess = ConfigurationStatus_Rejected;
  14983. }
  14984. else
  14985. {
  14986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14987. isSuccess = ConfigurationStatus_Accepted;
  14988. }
  14989. }
  14990. else
  14991. {
  14992. isSuccess = ConfigurationStatus_Rejected;
  14993. }
  14994. }
  14995. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14996. {
  14997. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14998. {
  14999. strcpy(str, (const char*)value);
  15000. for(int i = 0; str[i]; i++)
  15001. {
  15002. str[i] = tolower(str[i]);
  15003. }
  15004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15005. isSuccess = ConfigurationStatus_Accepted;
  15006. }
  15007. else
  15008. {
  15009. isSuccess = ConfigurationStatus_Rejected;
  15010. }
  15011. }
  15012. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15013. {
  15014. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15015. {
  15016. check_ascii = value[0];
  15017. if( (check_ascii < 48) || (check_ascii > 57) )
  15018. {
  15019. isSuccess = ConfigurationStatus_Rejected;
  15020. }
  15021. else
  15022. {
  15023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15024. isSuccess = ConfigurationStatus_Accepted;
  15025. }
  15026. }
  15027. else
  15028. {
  15029. isSuccess = ConfigurationStatus_Rejected;
  15030. }
  15031. }
  15032. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15033. {
  15034. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15035. {
  15036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15037. isSuccess = ConfigurationStatus_Accepted;
  15038. }
  15039. else
  15040. {
  15041. isSuccess = ConfigurationStatus_Rejected;
  15042. }
  15043. }
  15044. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15045. {
  15046. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15047. {
  15048. check_ascii = value[0];
  15049. if( (check_ascii < 48) || (check_ascii > 57) )
  15050. {
  15051. isSuccess = ConfigurationStatus_Rejected;
  15052. }
  15053. else
  15054. {
  15055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15056. isSuccess = ConfigurationStatus_Accepted;
  15057. }
  15058. }
  15059. else
  15060. {
  15061. isSuccess = ConfigurationStatus_Rejected;
  15062. }
  15063. }
  15064. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15065. {
  15066. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15067. {
  15068. strcpy(str, (const char*)value);
  15069. for(int i = 0; str[i]; i++)
  15070. {
  15071. str[i] = tolower(str[i]);
  15072. }
  15073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15074. isSuccess = ConfigurationStatus_Accepted;
  15075. }
  15076. else
  15077. {
  15078. isSuccess = ConfigurationStatus_Rejected;
  15079. }
  15080. }
  15081. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15082. {
  15083. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15084. {
  15085. check_ascii = value[0];
  15086. if( (check_ascii < 48) || (check_ascii > 57) )
  15087. {
  15088. isSuccess = ConfigurationStatus_Rejected;
  15089. }
  15090. else
  15091. {
  15092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15093. isSuccess = ConfigurationStatus_Accepted;
  15094. }
  15095. }
  15096. else
  15097. {
  15098. isSuccess = ConfigurationStatus_Rejected;
  15099. }
  15100. }
  15101. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15102. return isSuccess;
  15103. }
  15104. int TransactionMessageAttemptsGet(void)
  15105. {
  15106. return TransactionMessageAttemptsValue;
  15107. }
  15108. int FirstHeartBeatResponse(void)
  15109. {
  15110. return FirstHeartBeat;
  15111. }
  15112. int TransactionMessageRetryIntervalGet(void)
  15113. {
  15114. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15115. }
  15116. int ReadHttpStatus(int sock)
  15117. {
  15118. //char c;
  15119. char buff[1024]="",*ptr=buff+1;
  15120. int bytes_received, status;
  15121. DEBUG_INFO("Begin Response ..\n");
  15122. while((bytes_received = recv(sock, ptr, 1, 0))){
  15123. if(bytes_received==-1){
  15124. perror("ReadHttpStatus");
  15125. exit(1);
  15126. }
  15127. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15128. ptr++;
  15129. }
  15130. *ptr=0;
  15131. ptr=buff+1;
  15132. sscanf(ptr,"%*s %d ", &status);
  15133. DEBUG_INFO("%s\n",ptr);
  15134. DEBUG_INFO("status=%d\n",status);
  15135. DEBUG_INFO("End Response ..\n");
  15136. return (bytes_received>0)?status:0;
  15137. }
  15138. //the only filed that it parsed is 'Content-Length'
  15139. int ParseHeader(int sock)
  15140. {
  15141. //char c;
  15142. char buff[1024]="",*ptr=buff+4;
  15143. int bytes_received;
  15144. DEBUG_INFO("Begin HEADER ..\n");
  15145. while((bytes_received = recv(sock, ptr, 1, 0))){
  15146. if(bytes_received==-1){
  15147. perror("Parse Header");
  15148. exit(1);
  15149. }
  15150. if(
  15151. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15152. (ptr[-1]=='\r') && (*ptr=='\n' )
  15153. ) break;
  15154. ptr++;
  15155. }
  15156. *ptr=0;
  15157. ptr=buff+4;
  15158. //printf("%s",ptr);
  15159. if(bytes_received){
  15160. ptr=strstr(ptr,"Content-Length:");
  15161. if(ptr){
  15162. sscanf(ptr,"%*s %d",&bytes_received);
  15163. }else
  15164. bytes_received=-1; //unknown size
  15165. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15166. }
  15167. DEBUG_INFO("End HEADER ..\n");
  15168. return bytes_received ;
  15169. }
  15170. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15171. {
  15172. int result = TRUE;
  15173. char rmFileCmd[100]={0};
  15174. char FilePath[100]={0};
  15175. char ftpbuf[200];
  15176. int systemresult;
  15177. //DEBUG_INFO("filename=%s\n",filename);
  15178. //DEBUG_INFO("url=%s\n",url);
  15179. sprintf(FilePath,"/mnt/%s",filename);
  15180. system("ping 8.8.8.8 &");
  15181. if((access(FilePath,F_OK))!=-1)
  15182. {
  15183. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15184. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15185. system(rmFileCmd);
  15186. }
  15187. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15188. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15189. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15190. systemresult = system(ftpbuf);
  15191. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15192. if(systemresult != 0)
  15193. {
  15194. DEBUG_INFO("http DownLoad error!\n");
  15195. result = FALSE;
  15196. }
  15197. system("pkill ping");
  15198. return result;
  15199. }
  15200. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15201. {
  15202. int result = TRUE;
  15203. char rmFileCmd[100]={0};
  15204. char FilePath[100]={0};
  15205. char ftpbuf[200];
  15206. int systemresult;
  15207. //char temp[100];
  15208. sprintf(FilePath,"/mnt/%s",filename);
  15209. system("ping 8.8.8.8 &");
  15210. if((access(FilePath,F_OK))!=-1)
  15211. {
  15212. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15213. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15214. system(rmFileCmd);
  15215. }
  15216. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15217. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15218. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  15219. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15220. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15221. systemresult = system(ftpbuf);
  15222. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15223. if(systemresult != 0)
  15224. {
  15225. DEBUG_WARN("wget error!\n");
  15226. result = FALSE;
  15227. }
  15228. system("pkill ping");
  15229. return result;
  15230. }
  15231. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15232. {
  15233. char rmFileCmd[100]={0};
  15234. char FilePath[100]={0};
  15235. char buf[512];
  15236. int systemresult = 0;
  15237. //DEBUG_INFO("filename=%s\n",filename);
  15238. //DEBUG_INFO("url=%s\n",url);
  15239. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15240. if((access(FilePath,F_OK))!=-1)
  15241. {
  15242. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15243. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15244. system(rmFileCmd);
  15245. }
  15246. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15247. if(fp == NULL)
  15248. {
  15249. DEBUG_INFO("log is NULL\n");
  15250. return FALSE;
  15251. }
  15252. else
  15253. {
  15254. fprintf(fp, "%s\n", url);
  15255. fprintf(fp, "%s\n", filename);
  15256. fclose(fp);
  15257. }
  15258. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15259. if(phpFP == NULL)
  15260. {
  15261. DEBUG_INFO("PHP upload fail.\n");
  15262. return FALSE;
  15263. }
  15264. else
  15265. {
  15266. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15267. {
  15268. if(strstr(buf, "result") != NULL)
  15269. {
  15270. sscanf(buf, "result: %d", &systemresult);
  15271. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15272. }
  15273. }
  15274. pclose(phpFP);
  15275. }
  15276. if(systemresult != 1)
  15277. {
  15278. DEBUG_INFO("HTTP upload error!\n");
  15279. return FALSE;
  15280. }
  15281. return TRUE;
  15282. }
  15283. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15284. {
  15285. struct hostent* server;
  15286. char *IPbuffer;
  15287. char ftpbuf[200];
  15288. int systemresult;
  15289. // To retrieve host information
  15290. server = gethostbyname(location);
  15291. // To convert an Internet network
  15292. // address into ASCII string
  15293. IPbuffer = inet_ntoa(*((struct in_addr*)
  15294. server->h_addr_list[0]));
  15295. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15296. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15297. /* format : ftpput -u username -p passwd IP target source*/
  15298. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15299. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15300. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15301. systemresult = system(ftpbuf);
  15302. DEBUG_INFO("systemresult=%d\n",systemresult);
  15303. if(systemresult != 0)
  15304. {
  15305. DEBUG_INFO("ftpput error!\n");
  15306. return FALSE;
  15307. }
  15308. return TRUE;
  15309. }
  15310. int GetOcppServerURL()
  15311. {
  15312. int result = FALSE;
  15313. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15314. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15315. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15316. struct yuarel url;
  15317. char urlStr[512];
  15318. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15319. {
  15320. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15321. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15322. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15323. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15324. if(yuarel_parse(&url, urlStr) != -1)
  15325. {
  15326. sprintf(OcppProtocol, "%s", url.scheme);
  15327. sprintf(OcppHost, "%s", url.host);
  15328. if(url.path == NULL)
  15329. OcppTempPath[0] = '\0';
  15330. else
  15331. {
  15332. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15333. {
  15334. sprintf(OcppTempPath, "%s/", url.path);
  15335. }
  15336. else
  15337. {
  15338. sprintf(OcppTempPath, "%s", url.path);
  15339. }
  15340. }
  15341. if(url.port == 0)
  15342. {
  15343. if(strcmp(OcppProtocol, "wss") == 0)
  15344. OcppPort = 443;
  15345. else
  15346. OcppPort = 80;
  15347. }
  15348. else
  15349. OcppPort = url.port;
  15350. result = TRUE;
  15351. }
  15352. }
  15353. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15354. {
  15355. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15356. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15357. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15358. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15359. if(yuarel_parse(&url, urlStr) != -1)
  15360. {
  15361. sprintf(OcppProtocol, "%s", url.scheme);
  15362. sprintf(OcppHost, "%s", url.host);
  15363. if(url.path == NULL)
  15364. OcppTempPath[0] = '\0';
  15365. else
  15366. sprintf(OcppTempPath, "%s", url.path);
  15367. if(url.port == 0)
  15368. {
  15369. if(strcmp(OcppProtocol, "wss") == 0)
  15370. OcppPort = 443;
  15371. else
  15372. OcppPort = 80;
  15373. }
  15374. else
  15375. OcppPort = url.port;
  15376. result = TRUE;
  15377. }
  15378. }
  15379. else
  15380. {
  15381. strcpy(OcppHost,"");
  15382. }
  15383. return result;
  15384. }
  15385. int GetOcppPath()
  15386. {
  15387. int result = FALSE;
  15388. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15389. {
  15390. if(OcppTempPath == NULL)
  15391. {
  15392. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15393. }
  15394. else
  15395. {
  15396. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15397. }
  15398. result = TRUE;
  15399. goto End;
  15400. }
  15401. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15402. {
  15403. if(OcppTempPath == NULL)
  15404. {
  15405. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15406. }
  15407. else
  15408. {
  15409. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15410. }
  15411. result = TRUE;
  15412. goto End;
  15413. }
  15414. else
  15415. {
  15416. strcpy(OcppPath,"");
  15417. }
  15418. End:
  15419. return result;
  15420. }
  15421. int GetOcppPort()
  15422. {
  15423. return OcppPort;
  15424. }
  15425. int GetOcppConnStatus(void)
  15426. {
  15427. return ShmOCPP16Data->OcppConnStatus;
  15428. }
  15429. void SetOcppConnStatus(uint8_t status)
  15430. {
  15431. ShmOCPP16Data->OcppConnStatus = status;
  15432. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15433. }
  15434. int GetHeartBeatWithNOResponse(void)
  15435. {
  15436. return HeartBeatWithNOResponse;
  15437. }
  15438. void SetHeartBeatWithNOResponse(void)
  15439. {
  15440. HeartBeatWithNOResponse = 0;
  15441. }
  15442. void GetStartTransactionIdTag(int gun_index)
  15443. {
  15444. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15445. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15446. }
  15447. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15448. {
  15449. char ch;
  15450. FILE *fptr1;
  15451. int temptransactionId;
  15452. char str[100]={0};
  15453. temptransactionId = 0;
  15454. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15455. {
  15456. DEBUG_INFO("IdTag is empty.\n");
  15457. return temptransactionId;
  15458. }
  15459. /*------ Read the file ----------------*/
  15460. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15461. if (!fptr1)
  15462. {
  15463. DEBUG_INFO("QueueTransactionId file open error.\n");
  15464. //printf(" File not found or unable to open the input file!!\n");
  15465. return temptransactionId;
  15466. }
  15467. ch=fgetc(fptr1);
  15468. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15469. rewind(fptr1);
  15470. if(ch!=EOF)
  15471. {
  15472. // printf("%c",ch);
  15473. while (fgets(str, 100, fptr1) != NULL)
  15474. {
  15475. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15476. if(str[0]=='\0')
  15477. {
  15478. break;
  15479. }
  15480. char *revbuf[8] = {0}; // Variable store string split
  15481. int num = 0;// Quantity after string split
  15482. DEBUG_INFO("Transaction queue data= %s\n", str);
  15483. splitstring(str,",",revbuf,&num); // String split
  15484. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15485. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15486. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15487. DEBUG_INFO("------------------------------\n");
  15488. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15489. {
  15490. if(isStopTransaction)
  15491. {
  15492. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15493. {
  15494. temptransactionId = atoi(revbuf[2]);
  15495. //break;
  15496. }
  15497. }
  15498. else
  15499. {
  15500. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15501. {
  15502. temptransactionId = atoi(revbuf[2]);
  15503. //break;
  15504. }
  15505. }
  15506. }
  15507. }
  15508. }
  15509. else
  15510. DEBUG_INFO("EOF\n");
  15511. fclose(fptr1);
  15512. /*------- End of reading ---------------*/
  15513. return temptransactionId;
  15514. }
  15515. void SetTransactionIdZero(int transactionId)
  15516. {
  15517. char ch;
  15518. FILE *fptr1, *fptr2;
  15519. int temptransactionId = 0;
  15520. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15521. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15522. if (!fptr1)
  15523. {
  15524. //printf(" File not found or unable to open the input file!!\n");
  15525. return ;
  15526. }
  15527. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15528. if (!fptr2)
  15529. {
  15530. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15531. fclose(fptr1);
  15532. return ;
  15533. }
  15534. ch=fgetc(fptr1);
  15535. rewind(fptr1);
  15536. if(ch!=EOF)
  15537. {
  15538. // copy all contents to the temporary file except the specific line
  15539. while (fgets(str, 100, fptr1) != NULL)
  15540. {
  15541. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15542. if(str[0]=='\0')
  15543. {
  15544. break;
  15545. }
  15546. char *revbuf[8] = {0};
  15547. int num = 0;
  15548. strcpy(strtemp, str);
  15549. splitstring(str,",",revbuf,&num);
  15550. if(revbuf[2][0] != '\0')
  15551. {
  15552. temptransactionId = atoi(revbuf[2]);
  15553. if(transactionId != temptransactionId)
  15554. {
  15555. fprintf(fptr2, "%s\n", strtemp);
  15556. }
  15557. }
  15558. }
  15559. }
  15560. fclose(fptr1);
  15561. fclose(fptr2);
  15562. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15563. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15564. /*------ Read the file ----------------*/
  15565. }
  15566. int InternetDisconnect(void)
  15567. {
  15568. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15569. }
  15570. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15571. void storeTempStopTransaction(int gun_index)
  15572. {
  15573. char guid[37]={0};
  15574. int tempIndex = 0;
  15575. char TempStopTransaction[256];
  15576. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15577. DEBUG_INFO("storeTempStopTransaction...\n");
  15578. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15579. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15580. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15581. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15582. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15583. {
  15584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15585. {
  15586. tempIndex = ((gun_index==2) ? 1: 0);
  15587. }
  15588. else
  15589. {
  15590. tempIndex = gun_index;
  15591. }
  15592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15593. {
  15594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15595. {
  15596. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15597. }
  15598. }// END OF CHAdeMO_QUANTITY
  15599. }
  15600. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15601. {
  15602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15603. {
  15604. tempIndex = ((gun_index==2) ? 1: 0);
  15605. }
  15606. else
  15607. {
  15608. tempIndex = gun_index;
  15609. }
  15610. for (int index = 0; index < CCS_QUANTITY; index++)
  15611. {
  15612. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15613. {
  15614. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15615. }
  15616. }// END OF CCS_QUANTITY
  15617. }
  15618. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15619. {
  15620. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15621. {
  15622. tempIndex = ((gun_index==2) ? 1: 0);
  15623. }
  15624. else
  15625. {
  15626. tempIndex = gun_index;
  15627. }
  15628. for (int index = 0; index < GB_QUANTITY; index++)
  15629. {
  15630. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15631. {
  15632. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15633. }
  15634. }// END OF GB_QUANTITY
  15635. }
  15636. else if(gunType[gun_index] == GUN_TYPE_DO)
  15637. {
  15638. tempIndex = gun_index;
  15639. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15640. {
  15641. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15642. {
  15643. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15644. }
  15645. }
  15646. }
  15647. else
  15648. {
  15649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15650. {
  15651. tempIndex = 2;
  15652. }
  15653. else
  15654. {
  15655. tempIndex = gun_index;
  15656. }
  15657. for (int index = 0; index < AC_QUANTITY; index++)
  15658. {
  15659. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15660. {
  15661. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15662. }
  15663. }// END OF AC_QUANTITY
  15664. }
  15665. //Stop Transaction Time
  15666. struct timeval tmnow;
  15667. struct tm *tm;
  15668. char buf[28];//, usec_buf[6];
  15669. gettimeofday(&tmnow, NULL);
  15670. time_t t;
  15671. t = time(NULL);
  15672. /*UTC time and date*/
  15673. tm = gmtime(&t);
  15674. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15676. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15678. random_uuid(guid);
  15679. /***********************************transactionData******************************************************/
  15680. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15682. //=================================
  15683. //1. Transaction_Begin
  15684. //=================================
  15685. //============================== Energy.Active.Import.Interval ===========================================
  15686. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15687. {
  15688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15691. 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*/]);
  15692. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15693. 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))
  15694. {
  15695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15696. }
  15697. else
  15698. {
  15699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15700. }
  15701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15703. }
  15704. //=================================
  15705. //2. Transaction_End
  15706. //=================================
  15707. //2.1====================================== Current.Import L1 ==============================================
  15708. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15709. {
  15710. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15711. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15712. {
  15713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15714. {
  15715. tempIndex = ((gun_index==2) ? 1: 0);
  15716. }
  15717. else
  15718. {
  15719. tempIndex = gun_index;
  15720. }
  15721. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15722. {
  15723. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15724. {
  15725. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15726. }
  15727. }// End of for CHAdeMO_QUANTITY
  15728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15729. }
  15730. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15731. {
  15732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15733. {
  15734. tempIndex = ((gun_index==2) ? 1: 0);
  15735. }
  15736. else
  15737. {
  15738. tempIndex = gun_index;
  15739. }
  15740. for (int index = 0; index < CCS_QUANTITY; index++)
  15741. {
  15742. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15743. {
  15744. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15745. }
  15746. }// End of for CCS_QUANTITY
  15747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15748. }
  15749. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15750. {
  15751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15752. {
  15753. tempIndex = ((gun_index==2) ? 1: 0);
  15754. }
  15755. else
  15756. {
  15757. tempIndex = gun_index;
  15758. }
  15759. for (int index = 0; index < GB_QUANTITY; index++)
  15760. {
  15761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15762. {
  15763. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15764. }
  15765. }// End of for GB_QUANTITY
  15766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15767. }
  15768. else if(gunType[gun_index] == GUN_TYPE_DO)
  15769. {
  15770. tempIndex = gun_index;
  15771. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15772. {
  15773. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15774. {
  15775. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15776. }
  15777. }
  15778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15779. }
  15780. else
  15781. {
  15782. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15783. {
  15784. tempIndex = 2;
  15785. }
  15786. else
  15787. {
  15788. tempIndex = gun_index;
  15789. }
  15790. for (int index = 0; index < AC_QUANTITY; index++)
  15791. {
  15792. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15793. {
  15794. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15795. }
  15796. }// End of for AC_QUANTITY
  15797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15798. }
  15799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15802. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15805. }
  15806. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15807. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15808. {
  15809. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15810. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15811. {
  15812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15813. {
  15814. tempIndex = ((gun_index==2) ? 1: 0);
  15815. }
  15816. else
  15817. {
  15818. tempIndex = gun_index;
  15819. }
  15820. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15821. {
  15822. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15823. {
  15824. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15825. }
  15826. }// END OF CHAdeMO_QUANTITY
  15827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15828. }
  15829. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15830. {
  15831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15832. {
  15833. tempIndex = ((gun_index==2) ? 1: 0);
  15834. }
  15835. else
  15836. {
  15837. tempIndex = gun_index;
  15838. }
  15839. for (int index = 0; index < CCS_QUANTITY; index++)
  15840. {
  15841. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15842. {
  15843. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15844. }
  15845. }// END OF CCS_QUANTITY
  15846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15847. }
  15848. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15849. {
  15850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15851. {
  15852. tempIndex = ((gun_index==2) ? 1: 0);
  15853. }
  15854. else
  15855. {
  15856. tempIndex = gun_index;
  15857. }
  15858. for (int index = 0; index < GB_QUANTITY; index++)
  15859. {
  15860. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15861. {
  15862. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15863. }
  15864. }// END OF GB_QUANTITY
  15865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15866. }
  15867. else if(gunType[gun_index] == GUN_TYPE_DO)
  15868. {
  15869. tempIndex = gun_index;
  15870. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15871. {
  15872. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15873. {
  15874. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15875. }
  15876. }
  15877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15878. }
  15879. else
  15880. {
  15881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15882. {
  15883. tempIndex = 2;
  15884. }
  15885. else
  15886. {
  15887. tempIndex = gun_index;
  15888. }
  15889. for (int index = 0; index < AC_QUANTITY; index++)
  15890. {
  15891. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15892. {
  15893. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15894. }
  15895. }// END OF AC_QUANTITY
  15896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15897. }
  15898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15901. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15904. }
  15905. //2.3====================================== Power.Active.Import =========================================
  15906. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15907. {
  15908. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15909. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15910. {
  15911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15912. {
  15913. tempIndex = ((gun_index==2) ? 1: 0);
  15914. }
  15915. else
  15916. {
  15917. tempIndex = gun_index;
  15918. }
  15919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15920. {
  15921. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15922. {
  15923. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15924. }
  15925. } // End for CHAdeMO_QUANTITY
  15926. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15927. }
  15928. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15929. {
  15930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15931. {
  15932. tempIndex = ((gun_index==2) ? 1: 0);
  15933. }
  15934. else
  15935. {
  15936. tempIndex = gun_index;
  15937. }
  15938. for (int index = 0; index < CCS_QUANTITY; index++)
  15939. {
  15940. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15941. {
  15942. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15943. }
  15944. } // END for CCS_QUANTITY
  15945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15946. }
  15947. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15948. {
  15949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15950. {
  15951. tempIndex = ((gun_index==2) ? 1: 0);
  15952. }
  15953. else
  15954. {
  15955. tempIndex = gun_index;
  15956. }
  15957. for (int index = 0; index < GB_QUANTITY; index++)
  15958. {
  15959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15960. {
  15961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15962. }
  15963. }// END for GB_QUANTITY
  15964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15965. }
  15966. else if(gunType[gun_index] == GUN_TYPE_DO)
  15967. {
  15968. tempIndex = gun_index;
  15969. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15970. {
  15971. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15972. {
  15973. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15974. }
  15975. }
  15976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15977. }
  15978. else
  15979. {
  15980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15981. {
  15982. tempIndex = 2;
  15983. }
  15984. else
  15985. {
  15986. tempIndex = gun_index;
  15987. }
  15988. for (int index = 0; index < AC_QUANTITY; index++)
  15989. {
  15990. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15991. {
  15992. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15993. }
  15994. } // END for AC_QUANTITY
  15995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15996. }
  15997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16000. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16003. }
  16004. //2.4====================================== Voltage L1 ====================================================
  16005. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16006. {
  16007. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16008. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16009. {
  16010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16011. {
  16012. tempIndex = ((gun_index==2) ? 1: 0);
  16013. }
  16014. else
  16015. {
  16016. tempIndex = gun_index;
  16017. }
  16018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16019. {
  16020. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16021. {
  16022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16023. }
  16024. } // END OF FOR CHAdeMO_QUANTITY
  16025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16026. }
  16027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16028. {
  16029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16030. {
  16031. tempIndex = ((gun_index==2) ? 1: 0);
  16032. }
  16033. else
  16034. {
  16035. tempIndex = gun_index;
  16036. }
  16037. for (int index = 0; index < CCS_QUANTITY; index++)
  16038. {
  16039. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16040. {
  16041. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16042. }
  16043. } // END OF FOR CCS_QUANTITY
  16044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16045. }
  16046. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16047. {
  16048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16049. {
  16050. tempIndex = ((gun_index==2) ? 1: 0);
  16051. }
  16052. else
  16053. {
  16054. tempIndex = gun_index;
  16055. }
  16056. for (int index = 0; index < GB_QUANTITY; index++)
  16057. {
  16058. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16059. {
  16060. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16061. }
  16062. } // END OF FOR GB_QUANTITY
  16063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16064. }
  16065. else if(gunType[gun_index] == GUN_TYPE_DO)
  16066. {
  16067. tempIndex = gun_index;
  16068. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16069. {
  16070. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16071. {
  16072. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16073. }
  16074. }
  16075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16076. }
  16077. else
  16078. {
  16079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16080. {
  16081. tempIndex = 2;
  16082. }
  16083. else
  16084. {
  16085. tempIndex = gun_index;
  16086. }
  16087. for (int index = 0; index < AC_QUANTITY; index++)
  16088. {
  16089. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16090. {
  16091. 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
  16092. }
  16093. } // END OF FOR AC_QUANTITY
  16094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16095. }
  16096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16099. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16102. }
  16103. //2.5============================================== End SoC =========================================================
  16104. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16105. {
  16106. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16107. 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))
  16108. {
  16109. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16110. {
  16111. tempIndex = ((gun_index==2) ? 1: 0);
  16112. }
  16113. else
  16114. {
  16115. tempIndex = gun_index;
  16116. }
  16117. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16118. {
  16119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16120. {
  16121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16122. {
  16123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16124. }
  16125. }
  16126. }
  16127. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16128. {
  16129. for (int index = 0; index < CCS_QUANTITY; index++)
  16130. {
  16131. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16132. {
  16133. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16134. }
  16135. }
  16136. }
  16137. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16138. {
  16139. for (int index = 0; index < GB_QUANTITY; index++)
  16140. {
  16141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16142. {
  16143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16144. }
  16145. }
  16146. }
  16147. else if(gunType[gun_index] == GUN_TYPE_DO)
  16148. {
  16149. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16150. {
  16151. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16152. {
  16153. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16154. }
  16155. }
  16156. }
  16157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16163. } // END FOR DC CASE
  16164. }
  16165. //2.6====================================== Current.Import L2 ==============================================
  16166. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16167. {
  16168. // AC 3 phase L2 current
  16169. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16170. {
  16171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16172. {
  16173. tempIndex = 2;
  16174. }
  16175. else
  16176. {
  16177. tempIndex = gun_index;
  16178. }
  16179. for (int index = 0; index < AC_QUANTITY; index++)
  16180. {
  16181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16182. {
  16183. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16184. }
  16185. }// End of for AC_QUANTITY
  16186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16187. }
  16188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16193. }
  16194. //2.7====================================== Current.Import L3 ==============================================
  16195. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16196. {
  16197. // AC 3 phase L3 current
  16198. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16199. {
  16200. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16201. {
  16202. tempIndex = 2;
  16203. }
  16204. else
  16205. {
  16206. tempIndex = gun_index;
  16207. }
  16208. for (int index = 0; index < AC_QUANTITY; index++)
  16209. {
  16210. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16211. {
  16212. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16213. }
  16214. }// End of for AC_QUANTITY
  16215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16216. }
  16217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16222. }
  16223. //2.9====================================== Voltage L2 ====================================================
  16224. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16225. {
  16226. // AC 3 phase L2 volatge
  16227. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16228. {
  16229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16230. {
  16231. tempIndex = 2;
  16232. }
  16233. else
  16234. {
  16235. tempIndex = gun_index;
  16236. }
  16237. for (int index = 0; index < AC_QUANTITY; index++)
  16238. {
  16239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16240. {
  16241. 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
  16242. }
  16243. } // END OF FOR AC_QUANTITY
  16244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16245. }
  16246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16251. }
  16252. //2.10====================================== Voltage L3 ====================================================
  16253. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16254. {
  16255. // AC 3 phase L3 volatge
  16256. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16257. {
  16258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16259. {
  16260. tempIndex = 2;
  16261. }
  16262. else
  16263. {
  16264. tempIndex = gun_index;
  16265. }
  16266. for (int index = 0; index < AC_QUANTITY; index++)
  16267. {
  16268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16269. {
  16270. 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
  16271. }
  16272. } // END OF FOR AC_QUANTITY
  16273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16274. }
  16275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16280. }
  16281. //====================== Start SoC ================================
  16282. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16283. {
  16284. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16285. 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))
  16286. {
  16287. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16288. {
  16289. tempIndex = ((gun_index==2) ? 1: 0);
  16290. }
  16291. else
  16292. {
  16293. tempIndex = gun_index;
  16294. }
  16295. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16296. {
  16297. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16298. {
  16299. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16300. {
  16301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16302. }
  16303. }
  16304. }
  16305. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16306. {
  16307. for (int index = 0; index < CCS_QUANTITY; index++)
  16308. {
  16309. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16310. {
  16311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16312. }
  16313. }
  16314. }
  16315. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16316. {
  16317. for (int index = 0; index < GB_QUANTITY; index++)
  16318. {
  16319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16320. {
  16321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16322. }
  16323. }
  16324. }
  16325. else if(gunType[gun_index] == GUN_TYPE_DO)
  16326. {
  16327. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16328. {
  16329. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16330. {
  16331. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16332. }
  16333. }
  16334. }
  16335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16341. } // END FOR DC CASE
  16342. }
  16343. //======================================== Message create ==============================================
  16344. json_object *StopTransaction = json_object_new_object();
  16345. json_object *transactionDatas = json_object_new_array();
  16346. json_object *sampledValues = json_object_new_array();
  16347. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16348. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16349. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16350. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16351. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16352. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16353. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16354. {
  16355. json_object *transactionData = json_object_new_object();
  16356. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16357. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16358. {
  16359. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16360. {
  16361. json_object *sampledValue = json_object_new_object();
  16362. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16363. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16364. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16365. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16366. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16367. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16368. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16369. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16370. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16371. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16372. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16373. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16374. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16375. json_object_array_add(sampledValues, sampledValue);
  16376. }
  16377. }
  16378. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16379. json_object_array_add(transactionDatas, transactionData);
  16380. }
  16381. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16382. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16383. ,MESSAGE_TYPE_CALL
  16384. ,guid
  16385. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16386. json_object_put(StopTransaction);
  16387. // Check File "TempStopTransaction" Exist
  16388. if((access(TempStopTransaction,F_OK))!=-1)
  16389. {
  16390. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16391. fclose(fopen(TempStopTransaction, "w"));
  16392. }
  16393. else
  16394. {
  16395. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16396. FILE *log = fopen(TempStopTransaction, "w+");
  16397. if(log == NULL)
  16398. {
  16399. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16400. return ;
  16401. }
  16402. else
  16403. {
  16404. fclose(log);
  16405. }
  16406. }
  16407. //Add TempStopTransaction | Update TempStopTransaction
  16408. // open file for writing
  16409. FILE *outfile;
  16410. outfile = fopen (TempStopTransaction, "a");
  16411. //DEBUG_INFO("data = %s\n", queuedata);
  16412. fputs(queuedata, outfile);
  16413. fputs("\n", outfile);
  16414. fclose (outfile);
  16415. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16416. }
  16417. void checkTempStopTransaction(int gun_index)
  16418. {
  16419. FILE *fptr1;
  16420. char ch;
  16421. char str[QUEUE_MESSAGE_LENGTH]={0};
  16422. char guid[37]={0};
  16423. char tempdata[65]={0};
  16424. char connectorStr[2]={0};
  16425. char TempStopTransaction[256];
  16426. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16427. fptr1 = fopen(TempStopTransaction, "r");
  16428. //TempStopTransaction格式: 槍號,StopTransaction封包
  16429. if (!fptr1)
  16430. {
  16431. //printf(" File not found or unable to open the input file!!\n");
  16432. return ;
  16433. }
  16434. ch=fgetc(fptr1);
  16435. //printf(" Now the content of the file %s is : \n",fname);
  16436. rewind(fptr1);
  16437. if(ch!=EOF)
  16438. {
  16439. // copy all contents to the temporary file except the specific line
  16440. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16441. {
  16442. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16443. if(str[0]=='\0')
  16444. {
  16445. break;
  16446. }
  16447. //TempStopTransaction格式: 槍號,StopTransaction封包
  16448. strncpy(connectorStr, str, 1);
  16449. if(atoi(connectorStr) != (gun_index+1))
  16450. {
  16451. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16452. fclose(fptr1);
  16453. return ;
  16454. }
  16455. //random_uuid(guid);
  16456. strncpy(guid, str+6, 36); //copy guid
  16457. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16458. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16459. {
  16460. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16461. }
  16462. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16463. OCPP_insert_transaction_msg(NO, str);
  16464. memset(str,0,ARRAY_SIZE(str));
  16465. }
  16466. }
  16467. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16468. fclose(fptr1);
  16469. remove(TempStopTransaction); // remove the original file
  16470. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16471. }
  16472. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16473. {
  16474. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16475. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16476. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16477. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16478. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16479. }
  16480. int GetWebSocketPingInterval(void)
  16481. {
  16482. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16483. }
  16484. int GetServerSign(void)
  16485. {
  16486. return server_sign;
  16487. }
  16488. uint8_t GetOcppSecurityProfile()
  16489. {
  16490. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16491. }
  16492. void GetOcppChargerBoxId(uint8_t *data)
  16493. {
  16494. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16495. }
  16496. void GetOcppSecurityPassword(uint8_t *data)
  16497. {
  16498. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16499. }
  16500. void SetOcppVersion(uint8_t *version)
  16501. {
  16502. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16503. DEBUG_INFO("ocpp version: %s\n", version);
  16504. if(strstr((char*)version, "ocpp1.6") != NULL)
  16505. {
  16506. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16507. }
  16508. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16509. {
  16510. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16511. system("pkill OcppBackend");
  16512. }
  16513. }
  16514. void SetServerSign(int value)
  16515. {
  16516. server_sign = value;
  16517. }
  16518. int GetBootNotificationInterval(void)
  16519. {
  16520. return BootNotificationInterval;
  16521. }
  16522. int GetInternetConn(void)
  16523. {
  16524. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16525. }
  16526. int GetBackendConnectionTimeout(void)
  16527. {
  16528. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16529. }
  16530. int isConnectorInitMode(int gun_index)
  16531. {
  16532. int tempIndex = 0;
  16533. int result = TRUE;
  16534. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16535. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16536. {
  16537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16538. {
  16539. tempIndex = ((gun_index==2) ? 1: 0);
  16540. }
  16541. else
  16542. {
  16543. tempIndex = gun_index;
  16544. }
  16545. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16546. {
  16547. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16548. {
  16549. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16550. } //end of the same index
  16551. }//end of for CHAdeMO_QUANTITY
  16552. }
  16553. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16554. {
  16555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16556. {
  16557. tempIndex = ((gun_index==2) ? 1: 0);
  16558. }
  16559. else
  16560. {
  16561. tempIndex = gun_index;
  16562. }
  16563. for (int index = 0; index < CCS_QUANTITY; index++)
  16564. {
  16565. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16566. {
  16567. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16568. } //end of the same index
  16569. } // end of for CCS_QUANTITY
  16570. }
  16571. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16572. {
  16573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16574. {
  16575. tempIndex = ((gun_index==2) ? 1: 0);
  16576. }
  16577. else
  16578. {
  16579. tempIndex = gun_index;
  16580. }
  16581. for (int index = 0; index < GB_QUANTITY; index++)
  16582. {
  16583. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16584. {
  16585. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16586. } //end of the same index
  16587. } // end of for GB_QUANTITY
  16588. }
  16589. else if(gunType[gun_index] == GUN_TYPE_DO)
  16590. {
  16591. tempIndex = gun_index;
  16592. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16593. {
  16594. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16595. {
  16596. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16597. } //end of the same index
  16598. }
  16599. }
  16600. else
  16601. {
  16602. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16603. {
  16604. tempIndex = 2;
  16605. }
  16606. else
  16607. {
  16608. tempIndex = gun_index;
  16609. }
  16610. for (int index = 0; index < AC_QUANTITY; index++)
  16611. {
  16612. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16613. {
  16614. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16615. }//end of the same index
  16616. }//end of for AC_QUANTITY
  16617. }
  16618. return result;
  16619. }
  16620. void refreshProcDogTimer()
  16621. {
  16622. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16623. }
  16624. void InitialSystemValue(void)
  16625. {
  16626. int connectorIndex = 0;
  16627. //int valueASCII = 0;
  16628. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16629. gunTotalNumber=0;
  16630. SystemInitial = 0;
  16631. locallistVersion=0;
  16632. BootNotificationInterval = 0;
  16633. authorizeRetryTimes = 0;
  16634. GunStatusInterval = 10;
  16635. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16636. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16637. //Hear Beat
  16638. HeartBeatWithNOResponse = 0;
  16639. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16640. FirstHeartBeat = 0;
  16641. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16642. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16643. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16644. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16645. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16646. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16647. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16648. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16649. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16650. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16651. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16652. memset(gunType, 0, ARRAY_SIZE(gunType));
  16653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16654. {
  16655. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16656. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16657. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16658. {
  16659. // DO series
  16660. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16661. {
  16662. SystemInitial = SystemInitial + 1;
  16663. gunTotalNumber = gunTotalNumber + 1;
  16664. gunType[connectorIndex] = GUN_TYPE_DO;
  16665. connectorIndex = connectorIndex + 1;
  16666. }
  16667. }
  16668. else
  16669. {
  16670. // DM, DW, DS series
  16671. //check connector / socket type (index: 8, 9, 10)
  16672. for(int index=7; index <10 ; index++)
  16673. {
  16674. if(index != 8)
  16675. {
  16676. // DC Connector
  16677. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16678. {
  16679. SystemInitial = SystemInitial + 1;
  16680. gunTotalNumber = gunTotalNumber + 1;
  16681. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16682. connectorIndex = connectorIndex + 1;
  16683. }
  16684. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16685. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16686. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16687. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16688. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16689. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16690. {
  16691. SystemInitial = SystemInitial + 1;
  16692. gunTotalNumber = gunTotalNumber + 1;
  16693. gunType[connectorIndex] = GUN_TYPE_CCS;
  16694. connectorIndex = connectorIndex + 1;
  16695. }
  16696. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16697. {
  16698. SystemInitial = SystemInitial + 1;
  16699. gunTotalNumber = gunTotalNumber + 1;
  16700. gunType[connectorIndex] = GUN_TYPE_GBT;
  16701. connectorIndex = connectorIndex + 1;
  16702. }
  16703. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16704. {
  16705. SystemInitial = SystemInitial + 1;
  16706. gunTotalNumber = gunTotalNumber + 1;
  16707. gunType[connectorIndex] = GUN_TYPE_DO;
  16708. connectorIndex = connectorIndex + 1;
  16709. }
  16710. }
  16711. else
  16712. {
  16713. // AC Connector
  16714. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16715. {
  16716. SystemInitial = SystemInitial + 1;
  16717. gunTotalNumber = gunTotalNumber + 1;
  16718. gunType[connectorIndex] = GUN_TYPE_AC;
  16719. connectorIndex = connectorIndex + 1;
  16720. }
  16721. }
  16722. }
  16723. }
  16724. //DEBUG_INFO("DC ...\n");
  16725. }
  16726. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16727. {
  16728. //check connector / socket type (index: 8, 9, 10)
  16729. for(int index=7; index <10 ; index++)
  16730. {
  16731. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16732. {
  16733. SystemInitial = SystemInitial + 1;
  16734. gunTotalNumber = gunTotalNumber + 1;
  16735. gunType[connectorIndex] = GUN_TYPE_AC;
  16736. connectorIndex = connectorIndex + 1;
  16737. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16738. }
  16739. }
  16740. }
  16741. //Status && ConnectorPlugIn Setting
  16742. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16743. {
  16744. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16745. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16746. }
  16747. for (int index = 0; index < CCS_QUANTITY; index++)
  16748. {
  16749. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16750. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16751. }
  16752. for (int index = 0; index < GB_QUANTITY; index++)
  16753. {
  16754. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16755. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16756. }
  16757. for (int index = 0; index < AC_QUANTITY; index++)
  16758. {
  16759. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16760. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16761. }
  16762. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16763. {
  16764. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16765. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16766. }
  16767. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16768. {
  16769. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16770. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16771. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16772. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16773. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16774. }
  16775. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16776. clientTime.Heartbeat=time((time_t*)NULL);
  16777. sleep(1);
  16778. }
  16779. void LWS_Send(char *str)
  16780. {
  16781. //=====================================================
  16782. // Check InternetConn 0: disconnected, 1: connected
  16783. //====================================================
  16784. if(GetOcppConnStatus() == 0)
  16785. {
  16786. DEBUG_INFO("offline now !!!\n");
  16787. return;
  16788. }
  16789. // Only disable isWebsocketSendable operation initiated by charger
  16790. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16791. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16792. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16793. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16794. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16795. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16796. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16797. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16798. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16799. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16800. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16801. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16802. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16803. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16804. {
  16805. isWebsocketSendable = 0;
  16806. }
  16807. pthread_mutex_lock(&lock_send);
  16808. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16809. sprintf((char *)SendBuffer, "%s", str);
  16810. SendBufLen = strlen(str);
  16811. pthread_mutex_unlock(&lock_send);
  16812. lws_callback_on_writable(wsi_client);
  16813. //lws_service(context, 0);
  16814. //sleep(1);
  16815. }
  16816. void LWS_SendNow(char *str)
  16817. {
  16818. //=====================================================
  16819. // Check InternetConn 0: disconnected, 1: connected
  16820. //====================================================
  16821. if(GetOcppConnStatus() == 0)
  16822. {
  16823. DEBUG_INFO("offline now !!!\n");
  16824. return;
  16825. }
  16826. // Only disable isWebsocketSendable operation initiated by charger
  16827. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16828. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16829. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16830. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16831. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16832. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16833. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16834. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16835. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16836. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16837. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16838. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16839. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16840. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16841. {
  16842. isWebsocketSendable = 0;
  16843. }
  16844. pthread_mutex_lock(&lock_send);
  16845. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16846. sprintf((char *)SendBuffer, "%s", str);
  16847. SendBufLen = strlen(str);
  16848. pthread_mutex_unlock(&lock_send);
  16849. lws_callback_on_writable(wsi_client);
  16850. lws_service(context, 0);
  16851. //sleep(1);
  16852. }