MessageHandler.c 836 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264
  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 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(sendto(udp_socket_fd, tx_buf, strlen((char*)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("Message raw: %s\n", logBuf);
  552. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  553. DEBUG_TTIA_INFO("----- Header -----\n");
  554. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  555. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  556. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  557. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  558. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  559. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  560. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  561. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  562. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  563. DEBUG_TTIA_INFO("Len: 80\n");
  564. DEBUG_TTIA_INFO("----- Payload -----\n");
  565. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  566. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  567. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  568. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  569. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  570. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  571. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  572. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  573. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  574. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  575. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  576. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  577. DEBUG_TTIA_INFO("==================================\n");
  578. sn++;
  579. result = PASS;
  580. }
  581. else
  582. {
  583. DEBUG_ERROR("UDP sent out fail.\n");
  584. }
  585. }
  586. }
  587. return result;
  588. }
  589. //=========================================
  590. // Save configuration
  591. //=========================================
  592. int runShellCmd(const char*cmd)
  593. {
  594. int result = FAIL;
  595. char buf[256];
  596. FILE *fp;
  597. fp = popen(cmd, "r");
  598. if(fp != NULL)
  599. {
  600. while(fgets(buf, sizeof(buf), fp) != NULL)
  601. {
  602. DEBUG_INFO("%s\n", buf);
  603. }
  604. result = PASS;
  605. }
  606. pclose(fp);
  607. return result;
  608. }
  609. int StoreUsrConfigData(struct SysConfigData *UsrData)
  610. {
  611. int result = PASS;
  612. int fd,wrd;
  613. unsigned int i,Chk;
  614. unsigned char *ptr, *BufTmp;
  615. int MtdBlockSize = 0x300000;
  616. Chk=0;
  617. ptr=(unsigned char *)UsrData;
  618. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  619. {
  620. memset(BufTmp,0,MtdBlockSize);
  621. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  622. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  623. Chk+=*(BufTmp+i);
  624. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  625. // Output configuration to file.
  626. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  627. if (fd < 0)
  628. {
  629. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  630. free(BufTmp);
  631. return 0;
  632. }
  633. wrd=write(fd, BufTmp, MtdBlockSize);
  634. close(fd);
  635. if(wrd<MtdBlockSize)
  636. {
  637. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  638. free(BufTmp);
  639. return 0;
  640. }
  641. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  642. DEBUG_INFO("Erase /dev/mtd10.\n");
  643. runShellCmd("flash_erase /dev/mtd10 0 0");
  644. DEBUG_INFO("Write /dev/mtd10.\n");
  645. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  646. DEBUG_INFO("Erase /dev/mtd11.\n");
  647. runShellCmd("flash_erase /dev/mtd11 0 0");
  648. DEBUG_INFO("Write /dev/mtd11.\n");
  649. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  650. system("rm -f /mnt/EvseConfig.bin");
  651. DEBUG_INFO("EvseConfig write to flash OK\n");
  652. }
  653. else
  654. {
  655. DEBUG_ERROR("alloc BlockSize NG\r\n");
  656. result = FAIL;
  657. }
  658. if(BufTmp!=NULL)
  659. free(BufTmp);
  660. return result;
  661. }
  662. //=========================================
  663. // Sqlite3 related function
  664. //=========================================
  665. static int selectSqlCount = 0;
  666. static int callback(void *data, int argc, char **argv, char **azColName){
  667. int i;
  668. //printf("%s: ", (const char*)data);
  669. selectSqlCount = argc;
  670. for(i = 0; i<argc; i++){
  671. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  672. }
  673. //printf("\n");
  674. return 0;
  675. }
  676. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  677. //int i;
  678. //printf("%s:\n", (const char*)data);
  679. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  680. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  681. return 0;
  682. }
  683. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  684. //printf("%s:\n", (const char*)data);
  685. //idTag
  686. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  687. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  688. //parentIdTag
  689. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  690. //expir_date
  691. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  692. //status
  693. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  694. //version
  695. if(columenCount > 5)
  696. idTagQuery.listVersionInt = atoi(columnValue[5]);
  697. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  698. return 0;
  699. }
  700. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  701. {
  702. // localversion = argv[5] ? atoi(argv[5]) : 0;
  703. // printf("localversion=%d\n", localversion);
  704. return 0;
  705. }
  706. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  707. {
  708. for (int i = 0; i < n_columns; i++)
  709. {
  710. DEBUG_INFO("%s\t", col_values[i]);
  711. }
  712. DEBUG_INFO("\n");
  713. return 0;
  714. }
  715. int OCPP_cleanLocalCache()
  716. {
  717. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  718. char *errMsg = 0;
  719. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  720. if (SQLITE_OK != rc)
  721. {
  722. DEBUG_INFO("SQL error: %s\n",errMsg);
  723. return FALSE;
  724. }
  725. return TRUE;
  726. }
  727. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  728. {
  729. int isSuccess = TRUE;
  730. int ret = 0;
  731. //const char* data = "Callback function called";
  732. char sql[300];
  733. char zErrMsg[200];
  734. memset(sql, 0, 300);
  735. memset(zErrMsg, 0, 200);
  736. 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);
  737. //* Execute SQL statement */
  738. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  739. if( ret != SQLITE_OK )
  740. {
  741. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  742. isSuccess = FALSE;
  743. }
  744. return isSuccess;
  745. }
  746. void OCPP_getIdTagFromLocalCache(char idTag[])
  747. {
  748. int rc = 0;
  749. char sql[100];
  750. char zErrMsg[100];
  751. memset(sql, 0, 100);
  752. memset(zErrMsg, 0, 100);
  753. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  754. memset(&idTagQuery, 0, sizeof(idTagQuery));
  755. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  756. /* Execute SQL statement */
  757. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  758. if( rc != SQLITE_OK )
  759. {
  760. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  761. }
  762. }
  763. void OCPP_getListVerion()
  764. {
  765. int rc = 0;
  766. // const char* data = "Callback function called";
  767. char sql[100];
  768. char zErrMsg[100];
  769. memset(sql, 0, 100);
  770. memset(zErrMsg, 0, 100);
  771. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  772. /* Execute SQL statement */
  773. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  774. if( rc != SQLITE_OK )
  775. {
  776. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  777. }
  778. }
  779. void OCPP_get_TableAuthlocalAllData(void)
  780. {
  781. int rc = 0;
  782. char sql[100];
  783. char zErrMsg[100];
  784. memset(sql, 0, 100);
  785. memset(zErrMsg, 0, 100);
  786. sprintf(sql,"select * from ocpp_auth_local ");
  787. /* Execute SQL statement */
  788. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  789. if( rc != SQLITE_OK )
  790. {
  791. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  792. }
  793. //return ver;
  794. }
  795. int OCPP_cleanLocalList()
  796. {
  797. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  798. char *errMsg = 0;
  799. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  800. if (SQLITE_OK != rc)
  801. {
  802. DEBUG_INFO("%s\n",errMsg);
  803. return FALSE;
  804. }
  805. return TRUE;
  806. }
  807. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  808. {
  809. int isSuccess = FALSE;
  810. int ret = 0;
  811. //const char* data = "Callback function called";
  812. char sql[300];
  813. char zErrMsg[200];
  814. memset(sql, 0, 300);
  815. memset(zErrMsg, 0, 200);
  816. 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);
  817. //* Execute SQL statement */
  818. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  819. if( ret != SQLITE_OK )
  820. {
  821. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  822. return isSuccess;
  823. }
  824. memset(sql, 0, 300);
  825. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  826. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  827. if( ret != SQLITE_OK )
  828. {
  829. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  830. return isSuccess;
  831. }
  832. isSuccess = TRUE;
  833. return isSuccess;
  834. }
  835. void OCPP_getIdTagFromLocalList(char idTag[])
  836. {
  837. int rc = 0;
  838. // const char* data = "Callback function called";
  839. char sql[100];
  840. char zErrMsg[100];
  841. memset(sql, 0, 100);
  842. memset(zErrMsg, 0, 100);
  843. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  844. memset(&idTagQuery, 0, sizeof(idTagQuery));
  845. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  846. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  847. /* Execute SQL statement */
  848. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  849. if( rc != SQLITE_OK )
  850. {
  851. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  852. }
  853. //return ver;
  854. }
  855. void OCPP_deleteIdTagFromLocalList(char idTag[])
  856. {
  857. //int ver = 0;
  858. //int isSuccess = FALSE;
  859. int rc = 0;
  860. char sql[100];
  861. char zErrMsg[100];
  862. memset(sql, 0, 100);
  863. memset(zErrMsg, 0, 100);
  864. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  865. //* Execute SQL statement */
  866. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  867. if( rc != SQLITE_OK )
  868. {
  869. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  870. }
  871. }
  872. int getCurrentYear()
  873. {
  874. int result = 0;
  875. time_t CurrentTime;
  876. struct tm *tm;
  877. CurrentTime = time(NULL);
  878. tm=localtime(&CurrentTime);
  879. result = (tm->tm_year + 1900);
  880. return result;
  881. }
  882. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  883. {
  884. int result = PASS;
  885. char* errMsg = NULL;
  886. char sqlStr[8192];
  887. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  888. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  889. {
  890. result = FAIL;
  891. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  892. }
  893. 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));
  894. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  895. {
  896. result = FAIL;
  897. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  898. }
  899. return result;
  900. }
  901. //==========================================
  902. // Check time passed since today
  903. //==========================================
  904. long long DiffTimebWithNow(struct timeb ST)
  905. {
  906. //return milli-second
  907. struct timeb ET;
  908. long long StartTime,StopTime;
  909. ftime(&ET);
  910. StartTime=(long long)ST.time;
  911. StopTime=(long long)ET.time;
  912. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  913. }
  914. int getTimePassSinceToday(uint8_t gun_index)
  915. {
  916. int result = -1;
  917. static time_t lastTime[4];
  918. time_t t;
  919. struct tm *tmStartToday;
  920. struct timeb tbStartToday;
  921. t=time(NULL);
  922. if(difftime(t, lastTime[gun_index])>0)
  923. {
  924. tmStartToday=localtime(&t);
  925. tmStartToday->tm_hour = 0;
  926. tmStartToday->tm_min = 0;
  927. tmStartToday->tm_sec = 0;
  928. tbStartToday.time = mktime(tmStartToday);
  929. tbStartToday.millitm = 0;
  930. result = DiffTimebWithNow(tbStartToday)/1000;
  931. lastTime[gun_index] = t;
  932. }
  933. return result;
  934. }
  935. void getNowDatetime(uint8_t *data)
  936. {
  937. time_t t = time(NULL);
  938. struct tm tm = *localtime(&t);
  939. 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);
  940. }
  941. int syncDateTimeRTC(uint8_t *data)
  942. {
  943. struct ParsingResult
  944. {
  945. int result;
  946. int scanedElement;
  947. int year;
  948. int month;
  949. int mday;
  950. int hour;
  951. int min;
  952. int sec;
  953. int tz_hour;
  954. int tz_min;
  955. float minSec;
  956. }result;
  957. struct tm tmOrg;
  958. struct tm *tmTarget;
  959. struct timeb tbTarget;
  960. char buf[128];
  961. memset(&result, 0x00, sizeof(struct ParsingResult));
  962. result.result = PASS;
  963. if(strstr((char*)data, ".") != NULL)
  964. {
  965. // Original data with mini second
  966. if(strstr((char*)data, "Z") != NULL)
  967. {
  968. // Original data with Z
  969. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  970. &result.year,
  971. &result.month,
  972. &result.mday,
  973. &result.hour,
  974. &result.min,
  975. &result.sec,
  976. &result.minSec);
  977. }
  978. else
  979. {
  980. // Original data without Z
  981. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  982. &result.year,
  983. &result.month,
  984. &result.mday,
  985. &result.hour,
  986. &result.min,
  987. &result.sec,
  988. &result.minSec,
  989. &result.tz_hour,
  990. &result.tz_min);
  991. }
  992. }
  993. else
  994. {
  995. // Original data without mini second
  996. if(strstr((char*)data, "Z") != NULL)
  997. {
  998. // Original data with Z
  999. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1000. &result.year,
  1001. &result.month,
  1002. &result.mday,
  1003. &result.hour,
  1004. &result.min,
  1005. &result.sec);
  1006. }
  1007. else
  1008. {
  1009. // Original data without Z
  1010. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1011. &result.year,
  1012. &result.month,
  1013. &result.mday,
  1014. &result.hour,
  1015. &result.min,
  1016. &result.sec,
  1017. &result.tz_hour,
  1018. &result.tz_min);
  1019. }
  1020. }
  1021. tmOrg.tm_year = result.year - 1900;
  1022. tmOrg.tm_mon = result.month - 1;
  1023. tmOrg.tm_mday = result.mday;
  1024. tmOrg.tm_hour = result.hour;
  1025. tmOrg.tm_min = result.min;
  1026. tmOrg.tm_sec = result.sec;
  1027. tmOrg.tm_gmtoff = 0;
  1028. tbTarget.time = mktime(&tmOrg);
  1029. tbTarget.timezone = 0;
  1030. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1031. tmTarget = gmtime(&tbTarget.time);
  1032. 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);
  1033. //DEBUG_INFO(" org date time: %s\n", data);
  1034. //DEBUG_INFO("parse date time: %s\n", buf);
  1035. system(buf);
  1036. system("/sbin/hwclock -w --systohc");
  1037. if(result.scanedElement < 6)
  1038. result.result = FAIL;
  1039. return result.result;
  1040. }
  1041. //==========================================
  1042. // GetCompositeSchedule logic related function
  1043. //==========================================
  1044. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1045. {
  1046. //return milli-second
  1047. unsigned int StartTime,StopTime;
  1048. StartTime=(unsigned int)ST.time;
  1049. StopTime=(unsigned int)ET.time;
  1050. return (StopTime-StartTime);
  1051. }
  1052. int DiffTimebWithNowSec(struct timeb ST)
  1053. {
  1054. //return milli-second
  1055. struct timeb ET;
  1056. unsigned int StartTime,StopTime;
  1057. ftime(&ET);
  1058. StartTime=(unsigned int)ST.time;
  1059. StopTime=(unsigned int)ET.time;
  1060. return (StopTime-StartTime);
  1061. }
  1062. int getStartStop(uint8_t *start, uint8_t *stop)
  1063. {
  1064. int result = -1;
  1065. struct tm tmStart;
  1066. struct timeb tbStart;
  1067. struct tm tmStop;
  1068. struct timeb tbStop;
  1069. 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) &&
  1070. (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))
  1071. {
  1072. //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);
  1073. //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);
  1074. tmStart.tm_year -= 1900;
  1075. tmStart.tm_mon -= 1;
  1076. tbStart.time = mktime(&tmStart);
  1077. tbStart.millitm = 0;
  1078. tmStop.tm_year -= 1900;
  1079. tmStop.tm_mon -= 1;
  1080. tbStop.time = mktime(&tmStop);
  1081. tbStop.millitm = 0;
  1082. result = DiffTimebSec(tbStart, tbStop);
  1083. //DEBUG_INFO("getStartStop(): %d\n", result);
  1084. }
  1085. else
  1086. {
  1087. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1088. }
  1089. return result;
  1090. }
  1091. int isOvertNow(uint8_t *start)
  1092. {
  1093. int result = NO;
  1094. struct tm tmStart;
  1095. struct timeb tbStart;
  1096. 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))
  1097. {
  1098. //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);
  1099. tmStart.tm_year -= 1900;
  1100. tmStart.tm_mon -= 1;
  1101. tbStart.time = mktime(&tmStart);
  1102. tbStart.millitm = 0;
  1103. if(DiffTimebWithNowSec(tbStart) <= 0)
  1104. result = NO;
  1105. else
  1106. result = YES;
  1107. }
  1108. else
  1109. {
  1110. DEBUG_WARN("Start date parsing error.\n");
  1111. }
  1112. return result;
  1113. }
  1114. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1115. {
  1116. int result = -1;
  1117. struct tm tmStart;
  1118. struct timeb tbStart;
  1119. struct tm tmStop;
  1120. struct timeb tbStop;
  1121. 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) &&
  1122. (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))
  1123. {
  1124. tmStart.tm_year -= 1900;
  1125. tmStart.tm_mon -= 1;
  1126. tbStart.time = mktime(&tmStart);
  1127. tbStart.millitm = 0;
  1128. tmStop.tm_year -= 1900;
  1129. tmStop.tm_mon -= 1;
  1130. tbStop.time = mktime(&tmStop);
  1131. tbStop.millitm = 0;
  1132. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1133. }
  1134. return result;
  1135. }
  1136. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1137. {
  1138. FILE *fp;
  1139. char profileFileName[128];
  1140. char *line = NULL;
  1141. size_t len = 0;
  1142. time_t CurrentTime;
  1143. struct tm *tmComposite;
  1144. struct StructChargingProfile maxProfile;
  1145. uint8_t limitMax=0;
  1146. int compositePeriodIdx = 0;
  1147. CurrentTime = time(NULL);
  1148. tmComposite=localtime(&CurrentTime);
  1149. 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);
  1150. if(isUnitA)
  1151. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1152. else
  1153. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1154. compositeProfile->ChargingSchedule.Duration = durationReq;
  1155. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1156. {
  1157. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1158. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1159. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1160. }
  1161. compositeProfile->ChargingProfileId = 0;
  1162. compositeProfile->StackLevel = 99 ;
  1163. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1164. maxProfile.ChargingProfileId = -1;
  1165. maxProfile.ChargingSchedule.Duration = -1;
  1166. system("rm -f /tmp/*.json");
  1167. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1168. // Search max profile
  1169. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1170. if((access(profileFileName, F_OK))!=-1)
  1171. {
  1172. fp = fopen(profileFileName, "r");
  1173. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1174. {
  1175. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1176. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1177. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1178. }
  1179. maxProfile.ChargingProfileId = -1;
  1180. maxProfile.StackLevel = -1;
  1181. while(getline(&line, &len, fp) != -1)
  1182. {
  1183. json_object *obj = NULL;
  1184. obj = json_tokener_parse(line);
  1185. if(is_error(obj))
  1186. {
  1187. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1188. }
  1189. else
  1190. {
  1191. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1192. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1193. )
  1194. {
  1195. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1196. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1197. )
  1198. {
  1199. struct tm tmFrom, tmTo;
  1200. struct timeb tbFrom, tbTo;
  1201. 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) &&
  1202. (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))
  1203. {
  1204. tmFrom.tm_year -= 1900;
  1205. tmFrom.tm_mon -= 1;
  1206. tbFrom.time = mktime(&tmFrom);
  1207. tmTo.tm_year -= 1900;
  1208. tmTo.tm_mon -= 1;
  1209. tbTo.time = mktime(&tmTo);
  1210. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1211. {
  1212. if(maxProfile.ChargingProfileId == -1)
  1213. DEBUG_INFO("MaxProfile found.\n");
  1214. else
  1215. DEBUG_INFO("MaxProfile updated.\n");
  1216. // Required item
  1217. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1218. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1219. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1220. if(isUnitA)
  1221. {
  1222. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1223. 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++)
  1224. {
  1225. 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"));
  1226. 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?
  1227. 3:
  1228. 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")));
  1229. 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")));
  1230. }
  1231. }
  1232. else
  1233. {
  1234. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1235. 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++)
  1236. {
  1237. 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"));
  1238. 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?
  1239. 3:
  1240. 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")));
  1241. 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));
  1242. }
  1243. }
  1244. // Optional item
  1245. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1246. {
  1247. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1248. }
  1249. else
  1250. {
  1251. sprintf((char*)maxProfile.ValidFrom, " ");
  1252. }
  1253. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1254. {
  1255. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1256. }
  1257. else
  1258. {
  1259. sprintf((char*)maxProfile.ValidTo, " ");
  1260. }
  1261. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1262. {
  1263. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1264. }
  1265. else
  1266. {
  1267. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1268. }
  1269. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1270. {
  1271. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1272. }
  1273. else
  1274. {
  1275. maxProfile.TransactionId = -1;
  1276. }
  1277. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1278. {
  1279. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1280. }
  1281. else
  1282. {
  1283. maxProfile.ChargingSchedule.Duration = 86400;
  1284. }
  1285. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1286. {
  1287. 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")));
  1288. }
  1289. else
  1290. {
  1291. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1292. }
  1293. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1294. {
  1295. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1296. }
  1297. else
  1298. {
  1299. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. else
  1305. {
  1306. if(maxProfile.ChargingProfileId == -1)
  1307. DEBUG_INFO("MaxProfile found.\n");
  1308. else
  1309. DEBUG_INFO("MaxProfile updated.\n");
  1310. // Required item
  1311. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1312. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1313. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1314. if(isUnitA)
  1315. {
  1316. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1317. 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++)
  1318. {
  1319. 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"));
  1320. 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?
  1321. 3:
  1322. 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")));
  1323. 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")));
  1324. }
  1325. }
  1326. else
  1327. {
  1328. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1329. 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++)
  1330. {
  1331. 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"));
  1332. 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?
  1333. 3:
  1334. 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")));
  1335. 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));
  1336. }
  1337. }
  1338. // Optional item
  1339. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1340. {
  1341. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1342. }
  1343. else
  1344. {
  1345. sprintf((char*)maxProfile.ValidFrom, " ");
  1346. }
  1347. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1348. {
  1349. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1350. }
  1351. else
  1352. {
  1353. sprintf((char*)maxProfile.ValidTo, " ");
  1354. }
  1355. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1356. {
  1357. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1358. }
  1359. else
  1360. {
  1361. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1362. }
  1363. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1364. {
  1365. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1366. }
  1367. else
  1368. {
  1369. maxProfile.TransactionId = -1;
  1370. }
  1371. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1372. {
  1373. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1374. }
  1375. else
  1376. {
  1377. maxProfile.ChargingSchedule.Duration = 86400;
  1378. }
  1379. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1380. {
  1381. 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")));
  1382. }
  1383. else
  1384. {
  1385. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1386. }
  1387. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1388. {
  1389. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1390. }
  1391. else
  1392. {
  1393. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1394. }
  1395. }
  1396. }
  1397. }
  1398. json_object_put(obj);
  1399. }
  1400. fclose(fp);
  1401. /*
  1402. if(maxProfile.ChargingProfileId !=-1)
  1403. {
  1404. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1405. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1406. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1407. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1408. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1409. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1410. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1411. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1412. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1413. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1414. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1415. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1416. {
  1417. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1418. {
  1419. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1420. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1421. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1422. }
  1423. }
  1424. }
  1425. else
  1426. DEBUG_INFO("MaxProfile not found.\n");
  1427. DEBUG_INFO("------------------------------------\n");*/
  1428. }
  1429. if(maxProfile.ChargingProfileId != -1)
  1430. {
  1431. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1432. {
  1433. if(maxProfile.ChargingSchedule.Duration != -1)
  1434. {
  1435. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1436. 0:
  1437. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1438. }
  1439. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1440. {
  1441. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1442. {
  1443. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1444. 0:
  1445. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1446. if(idxPeriod > 0)
  1447. {
  1448. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1449. {
  1450. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1451. }
  1452. }
  1453. }
  1454. }
  1455. }
  1456. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1457. {
  1458. if(maxProfile.ChargingSchedule.Duration != -1)
  1459. {
  1460. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1461. }
  1462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1463. {
  1464. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1465. {
  1466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1467. if(idxPeriod > 0)
  1468. {
  1469. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1470. {
  1471. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. else
  1478. {
  1479. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1480. {
  1481. if(maxProfile.ChargingSchedule.Duration != -1)
  1482. {
  1483. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1484. 0:
  1485. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1486. }
  1487. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1488. {
  1489. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1490. {
  1491. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1492. 0:
  1493. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1494. if(idxPeriod > 0)
  1495. {
  1496. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1497. {
  1498. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1499. }
  1500. }
  1501. }
  1502. }
  1503. }
  1504. else
  1505. {
  1506. if(maxProfile.ChargingSchedule.Duration != -1)
  1507. {
  1508. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1509. 0:
  1510. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1511. }
  1512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1513. {
  1514. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1515. {
  1516. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1517. 0:
  1518. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1519. if(idxPeriod > 0)
  1520. {
  1521. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1522. {
  1523. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1524. }
  1525. }
  1526. }
  1527. }
  1528. }
  1529. }
  1530. /*
  1531. DEBUG_INFO("MaxProfile after align.\n");
  1532. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1533. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1534. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1535. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1536. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1537. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1538. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1539. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1540. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1541. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1542. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1544. {
  1545. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1546. {
  1547. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1548. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1549. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1550. }
  1551. }
  1552. DEBUG_INFO("------------------------------------\n");*/
  1553. }
  1554. // Find each profile period quantity
  1555. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1556. {
  1557. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1558. limitMax = idx+1;
  1559. }
  1560. if(maxProfile.ChargingProfileId != -1)
  1561. {
  1562. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1563. {
  1564. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1565. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1566. (maxProfile.ChargingSchedule.Duration > 0))
  1567. {
  1568. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1569. {
  1570. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1571. compositePeriodIdx++;
  1572. }
  1573. else
  1574. {
  1575. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1576. }
  1577. }
  1578. }
  1579. }
  1580. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1581. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1582. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1583. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1584. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1585. {
  1586. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1587. {
  1588. compositeProfile->ChargingProfileId = 1;
  1589. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1590. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1591. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1592. }
  1593. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1594. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1595. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1596. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1597. }
  1598. if(line)
  1599. free(line);
  1600. }
  1601. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1602. {
  1603. FILE *fp;
  1604. char profileFileName[128];
  1605. char *line = NULL;
  1606. size_t len = 0;
  1607. time_t CurrentTime;
  1608. struct tm *tmComposite;
  1609. struct StructChargingProfile maxProfile;
  1610. struct StructChargingProfile defaultTxProfile;
  1611. struct StructChargingProfile txProfile;
  1612. struct StructChargingSchedulePeriod tmpPeriod;
  1613. uint8_t limitMax=0;
  1614. uint8_t limitDef=0;
  1615. uint8_t limitTx=0;
  1616. int compositePeriodIdx = 0;
  1617. CurrentTime = time(NULL);
  1618. tmComposite=localtime(&CurrentTime);
  1619. 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);
  1620. if(isUnitA)
  1621. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1622. else
  1623. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1624. compositeProfile->ChargingSchedule.Duration = durationReq;
  1625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1626. {
  1627. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1628. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1629. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1630. }
  1631. compositeProfile->ChargingProfileId = 0;
  1632. compositeProfile->StackLevel = 99 ;
  1633. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1634. maxProfile.ChargingProfileId = -1;
  1635. defaultTxProfile.ChargingProfileId = -1;
  1636. txProfile.ChargingProfileId = -1;
  1637. maxProfile.ChargingSchedule.Duration = -1;
  1638. defaultTxProfile.ChargingSchedule.Duration = -1;
  1639. txProfile.ChargingSchedule.Duration = -1;
  1640. system("rm -f /tmp/*.json");
  1641. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1642. /*
  1643. * Search valid charging profile
  1644. */
  1645. //DEBUG_INFO("====================================\n");
  1646. // Search tx profile
  1647. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1648. if((access(profileFileName, F_OK))!=-1)
  1649. {
  1650. fp = fopen(profileFileName, "r");
  1651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1652. {
  1653. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1654. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1655. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1656. }
  1657. txProfile.ChargingProfileId = -1;
  1658. txProfile.StackLevel = -1;
  1659. while(getline(&line, &len, fp) != -1)
  1660. {
  1661. json_object *obj = NULL;
  1662. obj = json_tokener_parse(line);
  1663. if(is_error(obj))
  1664. {
  1665. DEBUG_ERROR("Parse txProfile from file error.\n");
  1666. }
  1667. else
  1668. {
  1669. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1670. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1671. )
  1672. {
  1673. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1674. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1675. )
  1676. {
  1677. struct tm tmFrom, tmTo;
  1678. struct timeb tbFrom, tbTo;
  1679. 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) &&
  1680. (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))
  1681. {
  1682. tmFrom.tm_year -= 1900;
  1683. tmFrom.tm_mon -= 1;
  1684. tbFrom.time = mktime(&tmFrom);
  1685. tmTo.tm_year -= 1900;
  1686. tmTo.tm_mon -= 1;
  1687. tbTo.time = mktime(&tmTo);
  1688. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1689. {
  1690. if(txProfile.ChargingProfileId == -1)
  1691. DEBUG_INFO("TxProfile found.\n");
  1692. else
  1693. DEBUG_INFO("TxProfile updated.\n");
  1694. // Required item
  1695. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1696. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1697. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1698. if(isUnitA)
  1699. {
  1700. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1701. 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++)
  1702. {
  1703. 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"));
  1704. 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?
  1705. 3:
  1706. 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")));
  1707. 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")));
  1708. }
  1709. }
  1710. else
  1711. {
  1712. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1713. 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++)
  1714. {
  1715. 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"));
  1716. 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?
  1717. 3:
  1718. 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")));
  1719. 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));
  1720. }
  1721. }
  1722. // Optional item
  1723. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1724. {
  1725. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1726. }
  1727. else
  1728. {
  1729. sprintf((char*)txProfile.ValidFrom, " ");
  1730. }
  1731. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1732. {
  1733. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1734. }
  1735. else
  1736. {
  1737. sprintf((char*)txProfile.ValidTo, " ");
  1738. }
  1739. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1740. {
  1741. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1742. }
  1743. else
  1744. {
  1745. sprintf((char*)txProfile.RecurrencyKind, " ");
  1746. }
  1747. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1748. {
  1749. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1750. }
  1751. else
  1752. {
  1753. txProfile.TransactionId = -1;
  1754. }
  1755. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1756. {
  1757. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1758. }
  1759. else
  1760. {
  1761. txProfile.ChargingSchedule.Duration = 86400;
  1762. }
  1763. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1764. {
  1765. 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")));
  1766. }
  1767. else
  1768. {
  1769. 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));
  1770. }
  1771. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1772. {
  1773. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1774. }
  1775. else
  1776. {
  1777. txProfile.ChargingSchedule.MinChargingRate = -1;
  1778. }
  1779. }
  1780. }
  1781. }
  1782. else
  1783. {
  1784. if(txProfile.ChargingProfileId == -1)
  1785. DEBUG_INFO("TxProfile found.\n");
  1786. else
  1787. DEBUG_INFO("TxProfile updated.\n");
  1788. // Required item
  1789. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1790. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1791. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1792. if(isUnitA)
  1793. {
  1794. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1795. 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++)
  1796. {
  1797. 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"));
  1798. 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?
  1799. 3:
  1800. 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")));
  1801. 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")));
  1802. }
  1803. }
  1804. else
  1805. {
  1806. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1807. 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++)
  1808. {
  1809. 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"));
  1810. 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?
  1811. 3:
  1812. 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")));
  1813. 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));
  1814. }
  1815. }
  1816. // Optional item
  1817. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1818. {
  1819. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1820. }
  1821. else
  1822. {
  1823. sprintf((char*)txProfile.ValidFrom, " ");
  1824. }
  1825. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1826. {
  1827. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1828. }
  1829. else
  1830. {
  1831. sprintf((char*)txProfile.ValidTo, " ");
  1832. }
  1833. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1834. {
  1835. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1836. }
  1837. else
  1838. {
  1839. sprintf((char*)txProfile.RecurrencyKind, " ");
  1840. }
  1841. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1842. {
  1843. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1844. }
  1845. else
  1846. {
  1847. txProfile.TransactionId = -1;
  1848. }
  1849. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1850. {
  1851. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1852. }
  1853. else
  1854. {
  1855. txProfile.ChargingSchedule.Duration = 86400;
  1856. }
  1857. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1858. {
  1859. 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")));
  1860. }
  1861. else
  1862. {
  1863. 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));
  1864. }
  1865. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1866. {
  1867. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1868. }
  1869. else
  1870. {
  1871. txProfile.ChargingSchedule.MinChargingRate = -1;
  1872. }
  1873. }
  1874. }
  1875. }
  1876. json_object_put(obj);
  1877. }
  1878. fclose(fp);
  1879. /*
  1880. if(txProfile.ChargingProfileId != -1)
  1881. {
  1882. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1883. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1884. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1885. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1886. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1887. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1888. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1889. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1890. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1891. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1892. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1896. {
  1897. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1898. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1899. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1900. }
  1901. }
  1902. }
  1903. else
  1904. DEBUG_INFO("TxProfile not found.\n");*/
  1905. }
  1906. // Search default tx profile
  1907. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1908. if((access(profileFileName, F_OK))==-1)
  1909. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1910. if((access(profileFileName, F_OK))!=-1)
  1911. {
  1912. fp = fopen(profileFileName, "r");
  1913. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1914. {
  1915. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1916. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1917. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1918. }
  1919. defaultTxProfile.ChargingProfileId = -1;
  1920. defaultTxProfile.StackLevel = -1;
  1921. while(getline(&line, &len, fp) != -1)
  1922. {
  1923. json_object *obj = NULL;
  1924. obj = json_tokener_parse(line);
  1925. if(is_error(obj))
  1926. {
  1927. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1928. }
  1929. else
  1930. {
  1931. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1932. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1933. )
  1934. {
  1935. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1936. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1937. )
  1938. {
  1939. struct tm tmFrom, tmTo;
  1940. struct timeb tbFrom, tbTo;
  1941. 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) &&
  1942. (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))
  1943. {
  1944. tmFrom.tm_year -= 1900;
  1945. tmFrom.tm_mon -= 1;
  1946. tbFrom.time = mktime(&tmFrom);
  1947. tmTo.tm_year -= 1900;
  1948. tmTo.tm_mon -= 1;
  1949. tbTo.time = mktime(&tmTo);
  1950. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1951. {
  1952. if(defaultTxProfile.ChargingProfileId == -1)
  1953. DEBUG_INFO("TxDefaultProfile found.\n");
  1954. else
  1955. DEBUG_INFO("TxDefaultProfile updated.\n");
  1956. // Required item
  1957. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1958. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1959. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1960. if(isUnitA)
  1961. {
  1962. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1963. 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++)
  1964. {
  1965. 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"));
  1966. 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?
  1967. 3:
  1968. 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")));
  1969. 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")));
  1970. }
  1971. }
  1972. else
  1973. {
  1974. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1975. 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++)
  1976. {
  1977. 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"));
  1978. 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?
  1979. 3:
  1980. 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")));
  1981. 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));
  1982. }
  1983. }
  1984. // Optional item
  1985. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1986. {
  1987. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1988. }
  1989. else
  1990. {
  1991. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1992. }
  1993. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1994. {
  1995. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1996. }
  1997. else
  1998. {
  1999. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2000. }
  2001. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2002. {
  2003. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2004. }
  2005. else
  2006. {
  2007. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2008. }
  2009. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2010. {
  2011. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2012. }
  2013. else
  2014. {
  2015. defaultTxProfile.TransactionId = -1;
  2016. }
  2017. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2018. {
  2019. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2020. }
  2021. else
  2022. {
  2023. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2024. }
  2025. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2026. {
  2027. 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")));
  2028. }
  2029. else
  2030. {
  2031. 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));
  2032. }
  2033. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2034. {
  2035. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2036. }
  2037. else
  2038. {
  2039. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2040. }
  2041. }
  2042. }
  2043. }
  2044. else
  2045. {
  2046. if(defaultTxProfile.ChargingProfileId == -1)
  2047. DEBUG_INFO("TxDefaultProfile found.\n");
  2048. else
  2049. DEBUG_INFO("TxDefaultProfile updated.\n");
  2050. // Required item
  2051. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2052. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2053. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2054. if(isUnitA)
  2055. {
  2056. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2057. 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++)
  2058. {
  2059. 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"));
  2060. 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?
  2061. 3:
  2062. 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")));
  2063. 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")));
  2064. }
  2065. }
  2066. else
  2067. {
  2068. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2069. 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++)
  2070. {
  2071. 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"));
  2072. 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?
  2073. 3:
  2074. 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")));
  2075. 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));
  2076. }
  2077. }
  2078. // Optional item
  2079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2080. {
  2081. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2082. }
  2083. else
  2084. {
  2085. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2086. }
  2087. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2088. {
  2089. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2090. }
  2091. else
  2092. {
  2093. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2094. }
  2095. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2096. {
  2097. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2098. }
  2099. else
  2100. {
  2101. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2102. }
  2103. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2104. {
  2105. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2106. }
  2107. else
  2108. {
  2109. defaultTxProfile.TransactionId = -1;
  2110. }
  2111. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2112. {
  2113. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2114. }
  2115. else
  2116. {
  2117. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2118. }
  2119. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2120. {
  2121. 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")));
  2122. }
  2123. else
  2124. {
  2125. 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));
  2126. }
  2127. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2128. {
  2129. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2130. }
  2131. else
  2132. {
  2133. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. json_object_put(obj);
  2139. }
  2140. fclose(fp);
  2141. /*
  2142. if(defaultTxProfile.ChargingProfileId != -1)
  2143. {
  2144. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2145. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2146. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2147. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2148. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2149. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2150. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2151. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2152. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2153. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2154. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2155. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2156. {
  2157. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2158. {
  2159. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2160. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2161. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2162. }
  2163. }
  2164. }
  2165. else
  2166. DEBUG_INFO("TxDefaultProfile not found.\n");
  2167. DEBUG_INFO("------------------------------------\n");*/
  2168. }
  2169. // Search max profile
  2170. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2171. if((access(profileFileName, F_OK))!=-1)
  2172. {
  2173. fp = fopen(profileFileName, "r");
  2174. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2175. {
  2176. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2177. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2179. }
  2180. maxProfile.ChargingProfileId = -1;
  2181. maxProfile.StackLevel = -1;
  2182. while(getline(&line, &len, fp) != -1)
  2183. {
  2184. json_object *obj = NULL;
  2185. obj = json_tokener_parse(line);
  2186. if(is_error(obj))
  2187. {
  2188. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2189. }
  2190. else
  2191. {
  2192. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2193. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2194. )
  2195. {
  2196. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2197. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2198. )
  2199. {
  2200. struct tm tmFrom, tmTo;
  2201. struct timeb tbFrom, tbTo;
  2202. 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) &&
  2203. (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))
  2204. {
  2205. tmFrom.tm_year -= 1900;
  2206. tmFrom.tm_mon -= 1;
  2207. tbFrom.time = mktime(&tmFrom);
  2208. tmTo.tm_year -= 1900;
  2209. tmTo.tm_mon -= 1;
  2210. tbTo.time = mktime(&tmTo);
  2211. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2212. {
  2213. if(maxProfile.ChargingProfileId == -1)
  2214. DEBUG_INFO("MaxProfile found.\n");
  2215. else
  2216. DEBUG_INFO("MaxProfile updated.\n");
  2217. // Required item
  2218. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2219. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2220. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2221. if(isUnitA)
  2222. {
  2223. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2224. 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++)
  2225. {
  2226. 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"));
  2227. 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?
  2228. 3:
  2229. 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")));
  2230. 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")));
  2231. }
  2232. }
  2233. else
  2234. {
  2235. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2236. 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++)
  2237. {
  2238. 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"));
  2239. 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?
  2240. 3:
  2241. 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")));
  2242. 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));
  2243. }
  2244. }
  2245. // Optional item
  2246. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2247. {
  2248. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2249. }
  2250. else
  2251. {
  2252. sprintf((char*)maxProfile.ValidFrom, " ");
  2253. }
  2254. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2255. {
  2256. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2257. }
  2258. else
  2259. {
  2260. sprintf((char*)maxProfile.ValidTo, " ");
  2261. }
  2262. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2263. {
  2264. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2265. }
  2266. else
  2267. {
  2268. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2269. }
  2270. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2271. {
  2272. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2273. }
  2274. else
  2275. {
  2276. maxProfile.TransactionId = -1;
  2277. }
  2278. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2279. {
  2280. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2281. }
  2282. else
  2283. {
  2284. maxProfile.ChargingSchedule.Duration = 86400;
  2285. }
  2286. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2287. {
  2288. 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")));
  2289. }
  2290. else
  2291. {
  2292. 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));
  2293. }
  2294. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2295. {
  2296. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2297. }
  2298. else
  2299. {
  2300. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2301. }
  2302. }
  2303. }
  2304. }
  2305. else
  2306. {
  2307. if(maxProfile.ChargingProfileId == -1)
  2308. DEBUG_INFO("MaxProfile found.\n");
  2309. else
  2310. DEBUG_INFO("MaxProfile updated.\n");
  2311. // Required item
  2312. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2313. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2314. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2315. if(isUnitA)
  2316. {
  2317. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2318. 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++)
  2319. {
  2320. 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"));
  2321. 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?
  2322. 3:
  2323. 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")));
  2324. 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")));
  2325. }
  2326. }
  2327. else
  2328. {
  2329. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2330. 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++)
  2331. {
  2332. 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"));
  2333. 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?
  2334. 3:
  2335. 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")));
  2336. 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));
  2337. }
  2338. }
  2339. // Optional item
  2340. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2341. {
  2342. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2343. }
  2344. else
  2345. {
  2346. sprintf((char*)maxProfile.ValidFrom, " ");
  2347. }
  2348. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2349. {
  2350. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2351. }
  2352. else
  2353. {
  2354. sprintf((char*)maxProfile.ValidTo, " ");
  2355. }
  2356. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2357. {
  2358. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2359. }
  2360. else
  2361. {
  2362. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2363. }
  2364. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2365. {
  2366. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2367. }
  2368. else
  2369. {
  2370. maxProfile.TransactionId = -1;
  2371. }
  2372. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2373. {
  2374. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2375. }
  2376. else
  2377. {
  2378. maxProfile.ChargingSchedule.Duration = 86400;
  2379. }
  2380. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2381. {
  2382. 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")));
  2383. }
  2384. else
  2385. {
  2386. 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));
  2387. }
  2388. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2389. {
  2390. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2391. }
  2392. else
  2393. {
  2394. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2395. }
  2396. }
  2397. }
  2398. }
  2399. json_object_put(obj);
  2400. }
  2401. fclose(fp);
  2402. /*
  2403. if(maxProfile.ChargingProfileId !=-1)
  2404. {
  2405. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2406. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2407. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2408. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2409. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2410. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2411. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2412. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2413. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2414. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2415. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2417. {
  2418. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2419. {
  2420. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2421. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2422. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2423. }
  2424. }
  2425. }
  2426. else
  2427. DEBUG_INFO("MaxProfile not found.\n");
  2428. DEBUG_INFO("------------------------------------\n");*/
  2429. }
  2430. /*
  2431. * Align found profile start schedule & periods
  2432. */
  2433. //DEBUG_INFO("====================================\n");
  2434. /*
  2435. // For local test usage, force modify found profile start schedule info
  2436. 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);
  2437. 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);
  2438. 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);
  2439. */
  2440. if(txProfile.ChargingProfileId != -1)
  2441. {
  2442. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2443. {
  2444. if(txProfile.ChargingSchedule.Duration != -1)
  2445. {
  2446. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2447. 0:
  2448. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2449. }
  2450. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2451. {
  2452. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2453. {
  2454. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2455. 0:
  2456. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2457. if(idxPeriod > 0)
  2458. {
  2459. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2460. {
  2461. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2462. }
  2463. }
  2464. }
  2465. }
  2466. }
  2467. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2468. {
  2469. if(txProfile.ChargingSchedule.Duration != -1)
  2470. {
  2471. 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?
  2472. 0:
  2473. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2474. }
  2475. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2476. {
  2477. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2478. {
  2479. 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?
  2480. 0:
  2481. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2482. if(idxPeriod > 0)
  2483. {
  2484. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2485. {
  2486. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2487. }
  2488. }
  2489. }
  2490. }
  2491. }
  2492. else
  2493. {
  2494. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2495. {
  2496. if(txProfile.ChargingSchedule.Duration != -1)
  2497. {
  2498. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2499. 0:
  2500. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2501. }
  2502. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2503. {
  2504. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2505. {
  2506. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2507. 0:
  2508. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2509. if(idxPeriod > 0)
  2510. {
  2511. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2512. {
  2513. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. else
  2520. {
  2521. if(txProfile.ChargingSchedule.Duration != -1)
  2522. {
  2523. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2524. 0:
  2525. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2526. }
  2527. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2528. {
  2529. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2530. {
  2531. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2532. 0:
  2533. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2534. if(idxPeriod > 0)
  2535. {
  2536. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2537. {
  2538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2539. }
  2540. }
  2541. }
  2542. }
  2543. }
  2544. }
  2545. /*
  2546. DEBUG_INFO("txProfile after align.\n");
  2547. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2548. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2549. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2550. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2551. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2552. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2553. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2554. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2555. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2556. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2557. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2558. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2559. {
  2560. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2561. {
  2562. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2563. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2564. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2565. }
  2566. }*/
  2567. }
  2568. if(defaultTxProfile.ChargingProfileId != -1)
  2569. {
  2570. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2571. {
  2572. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2573. {
  2574. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2575. 0:
  2576. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2577. }
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2581. {
  2582. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2583. 0:
  2584. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2585. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2586. {
  2587. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2588. }
  2589. if(idxPeriod > 0)
  2590. {
  2591. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2592. {
  2593. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2594. }
  2595. }
  2596. }
  2597. }
  2598. }
  2599. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2600. {
  2601. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2602. {
  2603. 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?
  2604. 0:
  2605. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2606. }
  2607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2608. {
  2609. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2610. {
  2611. 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?
  2612. 0:
  2613. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2614. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2615. {
  2616. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2617. }
  2618. if(idxPeriod > 0)
  2619. {
  2620. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2621. {
  2622. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2623. }
  2624. }
  2625. }
  2626. }
  2627. }
  2628. else
  2629. {
  2630. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2631. {
  2632. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2633. {
  2634. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2635. 0:
  2636. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2637. }
  2638. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2639. {
  2640. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2641. {
  2642. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2643. 0:
  2644. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2645. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2646. {
  2647. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2648. }
  2649. if(idxPeriod > 0)
  2650. {
  2651. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2652. {
  2653. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2654. }
  2655. }
  2656. }
  2657. }
  2658. }
  2659. else
  2660. {
  2661. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2662. {
  2663. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2664. 0:
  2665. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2666. }
  2667. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2668. {
  2669. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2670. {
  2671. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2672. 0:
  2673. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2674. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2675. {
  2676. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2677. }
  2678. if(idxPeriod > 0)
  2679. {
  2680. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2681. {
  2682. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2683. }
  2684. }
  2685. }
  2686. }
  2687. }
  2688. }
  2689. /*
  2690. DEBUG_INFO("defaultTxProfile after align.\n");
  2691. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2692. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2693. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2694. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2695. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2696. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2697. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2698. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2699. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2700. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2701. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2702. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2703. {
  2704. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2705. {
  2706. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2707. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2708. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2709. }
  2710. }
  2711. DEBUG_INFO("------------------------------------\n");*/
  2712. }
  2713. if(maxProfile.ChargingProfileId != -1)
  2714. {
  2715. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2716. {
  2717. if(maxProfile.ChargingSchedule.Duration != -1)
  2718. {
  2719. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2720. 0:
  2721. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2722. }
  2723. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2724. {
  2725. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2726. {
  2727. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2728. 0:
  2729. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2730. if(idxPeriod > 0)
  2731. {
  2732. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2733. {
  2734. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2735. }
  2736. }
  2737. }
  2738. }
  2739. }
  2740. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2741. {
  2742. if(maxProfile.ChargingSchedule.Duration != -1)
  2743. {
  2744. 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?
  2745. 0:
  2746. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2747. }
  2748. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2749. {
  2750. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2751. {
  2752. 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?
  2753. 0:
  2754. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2755. if(idxPeriod > 0)
  2756. {
  2757. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2758. {
  2759. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2760. }
  2761. }
  2762. }
  2763. }
  2764. }
  2765. else
  2766. {
  2767. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2768. {
  2769. if(maxProfile.ChargingSchedule.Duration != -1)
  2770. {
  2771. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2772. 0:
  2773. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2774. }
  2775. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2776. {
  2777. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2778. {
  2779. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2780. 0:
  2781. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2782. if(idxPeriod > 0)
  2783. {
  2784. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2785. {
  2786. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2787. }
  2788. }
  2789. }
  2790. }
  2791. }
  2792. else
  2793. {
  2794. if(maxProfile.ChargingSchedule.Duration != -1)
  2795. {
  2796. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2797. 0:
  2798. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2799. }
  2800. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2801. {
  2802. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2803. {
  2804. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2805. 0:
  2806. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2807. if(idxPeriod > 0)
  2808. {
  2809. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2810. {
  2811. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2812. }
  2813. }
  2814. }
  2815. }
  2816. }
  2817. }
  2818. /*
  2819. DEBUG_INFO("MaxProfile after align.\n");
  2820. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2821. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2822. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2823. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2824. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2825. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2826. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2827. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2828. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2829. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2830. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2832. {
  2833. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2834. {
  2835. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2836. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2837. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2838. }
  2839. }
  2840. DEBUG_INFO("------------------------------------\n");*/
  2841. }
  2842. /*
  2843. * Merge to conposite schedule
  2844. */
  2845. //DEBUG_INFO("====================================\n");
  2846. // Find each profile period quantity
  2847. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2848. {
  2849. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2850. limitMax = idx+1;
  2851. }
  2852. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2853. {
  2854. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2855. limitDef = idx+1;
  2856. }
  2857. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2858. {
  2859. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2860. limitTx = idx+1;
  2861. }
  2862. // TxProfile found, composite schedule based on it
  2863. if(txProfile.ChargingProfileId != -1)
  2864. {
  2865. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2866. {
  2867. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2868. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2869. (txProfile.ChargingSchedule.Duration > 0))
  2870. {
  2871. if(maxProfile.ChargingProfileId != -1)
  2872. {
  2873. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2874. {
  2875. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2876. {
  2877. if((maxProfile.ChargingSchedule.Duration > 0))
  2878. {
  2879. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2880. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2881. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2882. }
  2883. else
  2884. {
  2885. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2886. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2887. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2888. }
  2889. }
  2890. if(idxMaxPeriod == (limitMax-1))
  2891. {
  2892. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2893. {
  2894. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2895. {
  2896. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2897. compositePeriodIdx++;
  2898. }
  2899. else
  2900. {
  2901. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2902. }
  2903. }
  2904. }
  2905. }
  2906. }
  2907. else
  2908. {
  2909. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2910. {
  2911. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2912. compositePeriodIdx++;
  2913. }
  2914. else
  2915. {
  2916. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2917. }
  2918. }
  2919. }
  2920. if(idxTxPeriod == (limitTx-1))
  2921. {
  2922. if(defaultTxProfile.ChargingProfileId != -1)
  2923. {
  2924. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2925. {
  2926. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2927. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2928. (defaultTxProfile.ChargingSchedule.Duration>0))
  2929. {
  2930. if(maxProfile.ChargingProfileId != -1)
  2931. {
  2932. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2933. {
  2934. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2935. {
  2936. if((maxProfile.ChargingSchedule.Duration > 0))
  2937. {
  2938. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2939. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2940. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2941. }
  2942. else
  2943. {
  2944. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2945. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2946. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2947. }
  2948. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2949. {
  2950. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2951. {
  2952. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2953. compositePeriodIdx++;
  2954. }
  2955. else
  2956. {
  2957. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2958. }
  2959. }
  2960. // Delete duplicate period
  2961. if(compositePeriodIdx > 1)
  2962. {
  2963. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2964. {
  2965. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2966. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2967. compositePeriodIdx -= 1;
  2968. }
  2969. }
  2970. }
  2971. else
  2972. break;
  2973. }
  2974. }
  2975. else
  2976. {
  2977. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2978. {
  2979. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2980. compositePeriodIdx++;
  2981. }
  2982. else
  2983. {
  2984. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2985. }
  2986. }
  2987. }
  2988. }
  2989. }
  2990. }
  2991. }
  2992. }
  2993. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2994. else if(defaultTxProfile.ChargingProfileId != -1)
  2995. {
  2996. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2997. {
  2998. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2999. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3000. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3001. {
  3002. if(maxProfile.ChargingProfileId != -1)
  3003. {
  3004. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3005. {
  3006. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3007. {
  3008. if((maxProfile.ChargingSchedule.Duration > 0))
  3009. {
  3010. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3011. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3012. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3013. }
  3014. else
  3015. {
  3016. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3017. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3018. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3019. }
  3020. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3021. {
  3022. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3023. {
  3024. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3025. compositePeriodIdx++;
  3026. }
  3027. else
  3028. {
  3029. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3030. }
  3031. }
  3032. // Delete duplicate period
  3033. if(compositePeriodIdx > 1)
  3034. {
  3035. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3036. {
  3037. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3038. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3039. compositePeriodIdx -= 1;
  3040. }
  3041. }
  3042. }
  3043. else
  3044. break;
  3045. }
  3046. }
  3047. else
  3048. {
  3049. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3050. {
  3051. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3052. compositePeriodIdx++;
  3053. }
  3054. else
  3055. {
  3056. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. // Fill other period by MaxProfile
  3063. if(maxProfile.ChargingProfileId != -1)
  3064. {
  3065. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3066. {
  3067. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3068. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3069. (maxProfile.ChargingSchedule.Duration > 0))
  3070. {
  3071. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3072. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3073. {
  3074. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3075. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3076. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3077. }
  3078. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3079. {
  3080. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3081. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3082. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3083. }
  3084. if(tmpPeriod.Limit != -1)
  3085. {
  3086. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3087. {
  3088. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3089. {
  3090. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3091. compositePeriodIdx++;
  3092. }
  3093. else
  3094. {
  3095. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3096. }
  3097. }
  3098. // Delete duplicate period
  3099. if(compositePeriodIdx > 1)
  3100. {
  3101. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3102. {
  3103. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3104. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3105. compositePeriodIdx -= 1;
  3106. }
  3107. }
  3108. }
  3109. }
  3110. }
  3111. }
  3112. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3113. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3114. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3115. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3117. {
  3118. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3119. {
  3120. compositeProfile->ChargingProfileId = 1;
  3121. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3122. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3123. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3124. }
  3125. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3126. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3127. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3128. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3129. }
  3130. if(line)
  3131. free(line);
  3132. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3133. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3134. }
  3135. //==========================================
  3136. // Init all share memory
  3137. //==========================================
  3138. int InitShareMemory()
  3139. {
  3140. int result = PASS;
  3141. int MeterSMId;
  3142. //creat ShmSysConfigAndInfo
  3143. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3144. {
  3145. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3146. result = FAIL;
  3147. }
  3148. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3149. {
  3150. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3151. result = FAIL;
  3152. }
  3153. else
  3154. {}
  3155. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3156. {
  3157. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3158. result = FAIL;
  3159. }
  3160. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3161. {
  3162. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3163. result = FAIL;
  3164. }
  3165. else
  3166. {}
  3167. //creat ShmPsuData
  3168. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3169. {
  3170. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3171. result = FAIL;
  3172. }
  3173. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3174. {
  3175. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3176. result = FAIL;
  3177. }
  3178. else
  3179. {}
  3180. //creat ShmOCPP16Data
  3181. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3182. {
  3183. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3184. result = FAIL;
  3185. }
  3186. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3187. {
  3188. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3189. result = FAIL;
  3190. }
  3191. else
  3192. {}
  3193. /****************************** For Initial Settings************************************************/
  3194. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3195. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3196. // allocate Configuration memory address
  3197. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3198. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3199. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3200. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3201. //offline MeterValue Interval
  3202. TempMeterValueInterval = 0;
  3203. return result;
  3204. }
  3205. int ProcessShareMemory()
  3206. {
  3207. if(InitShareMemory() == FAIL)
  3208. {
  3209. DEBUG_ERROR("InitShareMemory NG\n");
  3210. if(ShmStatusCodeData!=NULL)
  3211. {
  3212. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3213. }
  3214. sleep(5);
  3215. return FAIL;
  3216. }
  3217. return PASS;
  3218. }
  3219. void CheckSystemValue(void)
  3220. {
  3221. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3222. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3223. char filenmae[100]={0};
  3224. char str[100]={0};
  3225. int tempIndex = 0;
  3226. //===============================
  3227. // send Heartbeat
  3228. //===============================
  3229. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3230. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3231. {
  3232. clientTime.Heartbeat=time((time_t*)NULL);
  3233. if(server_sign == TRUE)
  3234. {
  3235. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3236. }
  3237. else
  3238. {
  3239. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3240. }
  3241. }
  3242. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3243. {
  3244. //parameter for test
  3245. sendHeartbeatRequest(0);
  3246. //==============================================
  3247. // Reset Waiting Time
  3248. //==============================================
  3249. HeartBeatWithNOResponse += 1;
  3250. }
  3251. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3252. {
  3253. //==========================================
  3254. // csu trigger DataTransferReq
  3255. //==========================================
  3256. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3257. {
  3258. sendDataTransferRequest(gun_index);
  3259. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3260. }
  3261. //===============================
  3262. // CSU Trigger Authorize Request
  3263. //===============================
  3264. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3265. {
  3266. sendAuthorizeRequest(0);
  3267. authorizeRetryTimes = authorizeRetryTimes + 1;
  3268. if(authorizeRetryTimes < 3)
  3269. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3270. }
  3271. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3272. {
  3273. authorizeRetryTimes = 0;
  3274. SetOcppConnStatus(FALSE);
  3275. server_sign = FALSE;
  3276. }
  3277. 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))
  3278. {
  3279. sendAuthorizeRequest(0);
  3280. }
  3281. //==============================================
  3282. // Charger start transaction
  3283. //==============================================
  3284. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3285. {
  3286. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3287. sendStartTransactionRequest(gun_index);
  3288. clientTime.StartTransaction = time((time_t*)NULL);
  3289. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3290. storeTempStopTransaction(gun_index);
  3291. }
  3292. //==============================================
  3293. // Charger stop transaction
  3294. //==============================================
  3295. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3296. {
  3297. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3298. sendStopTransactionRequest(gun_index);
  3299. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3300. clientTime.StopTransaction = time((time_t*)NULL);
  3301. }
  3302. //==============================================
  3303. // Charger status report
  3304. //==============================================
  3305. //--- Check Mode Change ---//
  3306. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3307. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3308. {
  3309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3310. {
  3311. tempIndex = ((gun_index==2) ? 1: 0);
  3312. }
  3313. else
  3314. {
  3315. tempIndex = gun_index;
  3316. }
  3317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3318. {
  3319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3320. {
  3321. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3322. {
  3323. // Sent unplug message for California pricing logic
  3324. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3325. {
  3326. uint8_t ts[20];
  3327. getNowDatetime(ts);
  3328. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3329. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3330. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3331. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3332. }
  3333. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3334. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3335. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3336. }
  3337. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3338. {
  3339. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3340. if((access(filenmae,F_OK))!=-1)
  3341. {
  3342. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3343. sprintf(str,"rm -f %s",filenmae);
  3344. system(str);
  3345. }
  3346. }
  3347. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3348. #if 1 // for TempStopTransaction
  3349. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3350. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3351. {
  3352. checkTempStopTransaction(gun_index);
  3353. }
  3354. #endif
  3355. }
  3356. }
  3357. }
  3358. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3359. {
  3360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3361. {
  3362. tempIndex = ((gun_index==2) ? 1: 0);
  3363. }
  3364. else
  3365. {
  3366. tempIndex = gun_index;
  3367. }
  3368. for (int index = 0; index < CCS_QUANTITY; index++)
  3369. {
  3370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3371. {
  3372. 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]*/ )
  3373. {
  3374. // Sent unplug message for California pricing logic
  3375. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3376. {
  3377. uint8_t ts[20];
  3378. getNowDatetime(ts);
  3379. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3380. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3381. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3382. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3383. }
  3384. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3385. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3386. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3387. }
  3388. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3389. {
  3390. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3391. if((access(filenmae,F_OK))!=-1)
  3392. {
  3393. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3394. sprintf(str,"rm -f %s",filenmae);
  3395. system(str);
  3396. }
  3397. }
  3398. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3399. #if 1 // for TempStopTransaction
  3400. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3401. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3402. {
  3403. checkTempStopTransaction(gun_index);
  3404. }
  3405. #endif
  3406. }
  3407. }
  3408. }
  3409. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3410. {
  3411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3412. {
  3413. tempIndex = ((gun_index==2) ? 1: 0);
  3414. }
  3415. else
  3416. {
  3417. tempIndex = gun_index;
  3418. }
  3419. for (int index = 0; index < GB_QUANTITY; index++)
  3420. {
  3421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3422. {
  3423. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3424. {
  3425. // Sent unplug message for California pricing logic
  3426. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3427. {
  3428. uint8_t ts[20];
  3429. getNowDatetime(ts);
  3430. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3431. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3432. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3433. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3434. }
  3435. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3436. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3437. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3438. }
  3439. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3440. {
  3441. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3442. if((access(filenmae,F_OK))!=-1)
  3443. {
  3444. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3445. sprintf(str,"rm -f %s",filenmae);
  3446. system(str);
  3447. }
  3448. }
  3449. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3450. #if 1 // for TempStopTransaction
  3451. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3452. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3453. {
  3454. checkTempStopTransaction(gun_index);
  3455. }
  3456. #endif
  3457. }
  3458. }
  3459. }
  3460. else if(gunType[gun_index] == GUN_TYPE_DO)
  3461. {
  3462. tempIndex = gun_index;
  3463. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3464. {
  3465. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3466. {
  3467. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3468. {
  3469. // Sent unplug message for California pricing logic
  3470. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3471. {
  3472. uint8_t ts[20];
  3473. getNowDatetime(ts);
  3474. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3475. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3476. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3477. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3478. }
  3479. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3480. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3481. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3482. }
  3483. 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
  3484. {
  3485. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3486. if((access(filenmae,F_OK))!=-1)
  3487. {
  3488. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3489. sprintf(str,"rm -f %s",filenmae);
  3490. system(str);
  3491. }
  3492. }
  3493. 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);
  3494. #if 1 // for TempStopTransaction
  3495. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3496. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3497. {
  3498. checkTempStopTransaction(gun_index);
  3499. }
  3500. #endif
  3501. }
  3502. }
  3503. }
  3504. else
  3505. {
  3506. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3507. {
  3508. tempIndex = 2;
  3509. }
  3510. else
  3511. {
  3512. tempIndex = gun_index;
  3513. }
  3514. for (int index = 0; index < AC_QUANTITY; index++)
  3515. {
  3516. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3517. {
  3518. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3519. {
  3520. // Sent unplug message for California pricing logic
  3521. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3522. {
  3523. uint8_t ts[20];
  3524. getNowDatetime(ts);
  3525. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3526. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3527. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3528. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3529. }
  3530. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3531. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3532. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3533. }
  3534. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3535. {
  3536. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3537. if((access(filenmae,F_OK))!=-1)
  3538. {
  3539. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3540. sprintf(str,"rm -f %s",filenmae);
  3541. system(str);
  3542. }
  3543. }
  3544. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3545. #if 1 // for TempStopTransaction
  3546. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3547. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3548. {
  3549. checkTempStopTransaction(gun_index);
  3550. }
  3551. #endif
  3552. }
  3553. }// END
  3554. }
  3555. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3556. (
  3557. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3558. )
  3559. )
  3560. {
  3561. if(SystemInitial > 0)
  3562. SystemInitial -= 1;
  3563. sendStatusNotificationRequest(gun_index);
  3564. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3565. }
  3566. //==============================================
  3567. // CSU Trigger Smart Charging Profilw
  3568. //==============================================
  3569. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3570. {
  3571. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3572. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3573. }
  3574. //==============================================
  3575. // Meter report
  3576. //==============================================
  3577. // Trigger MeterValue
  3578. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3579. {
  3580. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3581. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3582. }
  3583. // ClockAlign MeterValue
  3584. 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))
  3585. {
  3586. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3587. {
  3588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3589. {
  3590. tempIndex = ((gun_index==2) ? 1: 0);
  3591. }
  3592. else
  3593. {
  3594. tempIndex = gun_index;
  3595. }
  3596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3597. {
  3598. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3599. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3600. {
  3601. reqClockAlignMeter[gun_index] = 1;
  3602. }
  3603. }// End for CHAdeMO
  3604. }
  3605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3606. {
  3607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3608. {
  3609. tempIndex = ((gun_index==2) ? 1: 0);
  3610. }
  3611. else
  3612. {
  3613. tempIndex = gun_index;
  3614. }
  3615. for (int index = 0; index < CCS_QUANTITY; index++)
  3616. {
  3617. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3618. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3619. {
  3620. reqClockAlignMeter[gun_index] = 1;
  3621. }
  3622. } // End for CCS
  3623. }
  3624. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3625. {
  3626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3627. {
  3628. tempIndex = ((gun_index==2) ? 1: 0);
  3629. }
  3630. else
  3631. {
  3632. tempIndex = gun_index;
  3633. }
  3634. for (int index = 0; index < GB_QUANTITY; index++)
  3635. {
  3636. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3637. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3638. {
  3639. reqClockAlignMeter[gun_index] = 1;
  3640. }
  3641. }// End for GB
  3642. }
  3643. else if(gunType[gun_index] == GUN_TYPE_DO)
  3644. {
  3645. tempIndex = gun_index;
  3646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3647. {
  3648. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3649. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3650. {
  3651. reqClockAlignMeter[gun_index] = 1;
  3652. }
  3653. }
  3654. }
  3655. else
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3658. {
  3659. tempIndex = 2;
  3660. }
  3661. else
  3662. {
  3663. tempIndex = gun_index;
  3664. }
  3665. for (int index = 0; index < AC_QUANTITY; index++)
  3666. {
  3667. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3668. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3669. {
  3670. reqClockAlignMeter[gun_index] = 1;
  3671. }
  3672. }//End for AC
  3673. }
  3674. if(reqClockAlignMeter[gun_index] == 1)
  3675. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3676. }
  3677. // Sample period MeterValue
  3678. 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))))
  3679. {
  3680. //check Transaction active
  3681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3682. {
  3683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3684. {
  3685. tempIndex = ((gun_index==2) ? 1: 0);
  3686. }
  3687. else
  3688. {
  3689. tempIndex = gun_index;
  3690. }
  3691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3692. {
  3693. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3694. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3695. {
  3696. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3697. {
  3698. reqSampleMeter[gun_index] = 1;
  3699. }
  3700. }
  3701. }// End for CHAdeMO
  3702. }
  3703. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3704. {
  3705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3706. {
  3707. tempIndex = ((gun_index==2) ? 1: 0);
  3708. }
  3709. else
  3710. {
  3711. tempIndex = gun_index;
  3712. }
  3713. for (int index = 0; index < CCS_QUANTITY; index++)
  3714. {
  3715. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3716. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3717. {
  3718. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3719. {
  3720. reqSampleMeter[gun_index] = 1;
  3721. }
  3722. }
  3723. } // End for CCS
  3724. }
  3725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3726. {
  3727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3728. {
  3729. tempIndex = ((gun_index==2) ? 1: 0);
  3730. }
  3731. else
  3732. {
  3733. tempIndex = gun_index;
  3734. }
  3735. for (int index = 0; index < GB_QUANTITY; index++)
  3736. {
  3737. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3738. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3739. {
  3740. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3741. {
  3742. reqSampleMeter[gun_index] = 1;
  3743. }
  3744. }
  3745. }// End for GB
  3746. }
  3747. else if(gunType[gun_index] == GUN_TYPE_DO)
  3748. {
  3749. tempIndex = gun_index;
  3750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3751. {
  3752. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3753. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3754. {
  3755. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3756. {
  3757. reqSampleMeter[gun_index] = 1;
  3758. }
  3759. }
  3760. }
  3761. }
  3762. else
  3763. {
  3764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3765. {
  3766. tempIndex = 2;
  3767. }
  3768. else
  3769. {
  3770. tempIndex = gun_index;
  3771. }
  3772. for (int index = 0; index < AC_QUANTITY; index++)
  3773. {
  3774. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3775. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3776. {
  3777. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3778. {
  3779. reqSampleMeter[gun_index] = 1;
  3780. }
  3781. }
  3782. }//End for AC
  3783. }
  3784. if(reqSampleMeter[gun_index] == 1)
  3785. {
  3786. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3787. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3788. storeTempStopTransaction(gun_index);
  3789. }
  3790. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3791. }
  3792. //==============================================
  3793. // Check Connector reserved
  3794. //==============================================
  3795. //===============================
  3796. // Check if Reserve is expired
  3797. //===============================
  3798. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3799. {
  3800. double diff_t;
  3801. struct tm tp;
  3802. // current time
  3803. time_t t = time(NULL);
  3804. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3805. tp.tm_isdst = -1;
  3806. time_t utc = mktime(&tp);
  3807. diff_t = difftime(utc, t);
  3808. if(diff_t <= 0)
  3809. {
  3810. DEBUG_INFO("reserve expired.\n");
  3811. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3812. }
  3813. }//END OF Check if Reserve is expired
  3814. //==========================================
  3815. // csu trigger FirmwareStatusNotificationReq
  3816. //==========================================
  3817. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3818. {
  3819. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3820. }
  3821. //==========================================
  3822. // csu trigger DiagnosticsStatusNotificationReq
  3823. //==========================================
  3824. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3825. {
  3826. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3827. }
  3828. //==========================================
  3829. // csu trigger CancelReservationConf
  3830. //==========================================
  3831. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3832. {
  3833. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3834. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3835. }
  3836. //==========================================
  3837. // csu trigger ChangeAvailabilityConf
  3838. //==========================================
  3839. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3840. {
  3841. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3842. }
  3843. //==========================================
  3844. // csu trigger UnlockConnectorConf
  3845. //==========================================
  3846. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3847. {
  3848. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3849. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3850. }
  3851. //==========================================
  3852. // csu trigger ReserveNowConf
  3853. //==========================================
  3854. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3855. {
  3856. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3857. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3858. }
  3859. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3860. {
  3861. sendSignCertificateRequest();
  3862. }
  3863. }
  3864. }
  3865. //==========================================
  3866. // send request routine
  3867. //==========================================
  3868. int sendAuthorizeRequest(int gun_index)
  3869. {
  3870. mtrace();
  3871. int result = FAIL;
  3872. char message[100]={0};
  3873. char guid[37];
  3874. char tempdata[65]={0};
  3875. DEBUG_INFO("sendAuthorizeRequest...\n");
  3876. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3877. //Local Authorize
  3878. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3879. {
  3880. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3881. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3882. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3883. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3884. result = PASS;
  3885. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3886. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3887. authorizeRetryTimes = 0;
  3888. return result;
  3889. }
  3890. 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))||
  3891. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3892. {
  3893. // Query from cache
  3894. DEBUG_INFO("Authorize from cache.\n");
  3895. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3896. // Query from list
  3897. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3898. {
  3899. DEBUG_INFO("Authorize from list.\n");
  3900. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3901. }
  3902. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3903. {
  3904. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3905. {
  3906. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3907. }
  3908. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3909. {
  3910. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3911. }
  3912. if(!GetOcppConnStatus())
  3913. {
  3914. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3915. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3916. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3917. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3918. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3919. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3920. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3921. authorizeRetryTimes = 0;
  3922. return result;
  3923. }
  3924. }
  3925. else
  3926. {
  3927. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3928. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3929. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3930. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3931. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3932. else
  3933. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3934. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3935. result = PASS;
  3936. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3937. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3938. authorizeRetryTimes = 0;
  3939. return result;
  3940. }
  3941. }
  3942. //initialize struct Authorize
  3943. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3944. //get data from shared memory
  3945. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3946. random_uuid(guid);
  3947. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3948. LWS_Send(message);
  3949. sprintf(tempdata, "Authorize,%d", gun_index);
  3950. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3951. {
  3952. result = PASS;
  3953. DEBUG_INFO("Authorize mapItem pass\n");
  3954. }
  3955. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3956. return result;
  3957. }
  3958. int sendBootNotificationRequest(void)
  3959. {
  3960. mtrace();
  3961. int result = FAIL;
  3962. char message[500]={0}, payload[700]={0};
  3963. char guid[37]={0};
  3964. char tempdata[65]={0};
  3965. // Fill BootNotification fields
  3966. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3967. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3968. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3969. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3970. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3971. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3972. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3973. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3974. ShmOCPP16Data->ChargeBoxId
  3975. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3976. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3977. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3978. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3979. ,ShmOCPP16Data->BootNotification.CpIccid
  3980. ,ShmOCPP16Data->BootNotification.CpImsi);
  3981. random_uuid(guid);
  3982. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3983. LWS_Send(message);
  3984. sprintf(tempdata, "BootNotification,0");
  3985. 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*/)
  3986. {
  3987. result = PASS;
  3988. }
  3989. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3990. strcpy(queuedata,message);
  3991. return result;
  3992. }
  3993. int sendDataTransferRequest(int gun_index)
  3994. {
  3995. mtrace();
  3996. char message[1000]={0};
  3997. char guid[37]={0};
  3998. char tempdata[65]={0};
  3999. int result = FAIL;
  4000. random_uuid(guid);
  4001. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4002. MESSAGE_TYPE_CALL,
  4003. guid,
  4004. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4005. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4006. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4007. LWS_Send(message);
  4008. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4009. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4010. {
  4011. result = PASS;
  4012. DEBUG_INFO("DataTransfer mapItem pass\n");
  4013. }
  4014. return result;
  4015. }
  4016. int sendDiagnosticsStatusNotificationRequest(char *status)
  4017. {
  4018. mtrace();
  4019. int result = FAIL;
  4020. char message[110]={0};
  4021. char guid[37]={0};
  4022. char tempdata[65]={0};
  4023. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4024. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4025. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4026. random_uuid(guid);
  4027. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4028. LWS_SendNow(message);
  4029. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4030. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4031. {
  4032. result = PASS;
  4033. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4034. }
  4035. //#ifdef SystemLogMessage
  4036. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4037. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4038. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4039. //#endif
  4040. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4041. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4042. //record status
  4043. if(strcmp(status,"Idle")==0)
  4044. {
  4045. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4046. }
  4047. else if(strcmp(status,"Uploaded")==0)
  4048. {
  4049. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4050. }
  4051. else if(strcmp(status,"UploadFailed")==0)
  4052. {
  4053. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4054. }
  4055. else if(strcmp(status,"Uploading")==0)
  4056. {
  4057. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4058. }
  4059. return result;
  4060. }
  4061. int sendFirmwareStatusNotificationRequest(char *status)
  4062. {
  4063. mtrace();
  4064. int result = FAIL;
  4065. char message[110]={0};
  4066. char guid[37]={0};
  4067. char tempdata[65]={0};
  4068. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4069. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4070. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4071. random_uuid(guid);
  4072. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4073. LWS_SendNow(message);
  4074. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4075. 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*/)
  4076. {
  4077. result = PASS;
  4078. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4079. }
  4080. //#ifdef SystemLogMessage
  4081. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4082. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4083. //#endif
  4084. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4085. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4086. //record status
  4087. if(strcmp(status,"Downloaded")==0)
  4088. {
  4089. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4090. }
  4091. else if(strcmp(status,"DownloadFailed")==0)
  4092. {
  4093. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4094. }
  4095. else if(strcmp(status,"Downloading")==0)
  4096. {
  4097. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4098. }
  4099. else if(strcmp(status,"Idle")==0)
  4100. {
  4101. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4102. }
  4103. else if(strcmp(status,"InstallationFailed")==0)
  4104. {
  4105. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4106. }
  4107. else if(strcmp(status,"Installing")==0)
  4108. {
  4109. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4110. }
  4111. else if(strcmp(status,"Installed")==0)
  4112. {
  4113. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4114. }
  4115. return result;
  4116. }
  4117. int sendHeartbeatRequest(int gun_index)
  4118. {
  4119. mtrace();
  4120. int result = FAIL;
  4121. char message[80]={0};
  4122. char guid[37]={0};
  4123. char tempdata[65]={0};
  4124. random_uuid(guid);
  4125. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4126. , MESSAGE_TYPE_CALL
  4127. , guid );
  4128. LWS_Send(message);
  4129. sprintf(tempdata, "Heartbeat,%d", 0);
  4130. 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*/)
  4131. {
  4132. result = PASS;
  4133. }
  4134. return result;
  4135. }
  4136. int sendStartTransactionRequest(int gun_index)
  4137. {
  4138. mtrace();
  4139. int result = FAIL;
  4140. char message[250]={0};
  4141. char guid[37]={0};
  4142. struct timeval tmnow;
  4143. struct tm *tm;
  4144. char buf[28];//, usec_buf[6];
  4145. char tempdata[65]={0};
  4146. int tempIndex = 0;
  4147. DEBUG_INFO("sendStartTransactionRequest...\n");
  4148. gettimeofday(&tmnow, NULL);
  4149. time_t t;
  4150. t = time(NULL);
  4151. /*UTC time and date*/
  4152. tm = gmtime(&t);
  4153. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4154. #if 0 // remove temporally
  4155. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4156. strcat(buf,".");
  4157. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4158. strcat(buf,usec_buf);
  4159. #endif
  4160. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4161. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4162. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4163. // clear StartTransaction Response
  4164. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4165. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4166. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4167. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4168. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4169. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4170. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4171. {
  4172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4173. {
  4174. tempIndex = ((gun_index==2) ? 1: 0);
  4175. }
  4176. else
  4177. {
  4178. tempIndex = gun_index;
  4179. }
  4180. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4181. {
  4182. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4183. {
  4184. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4185. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4186. }
  4187. }
  4188. }
  4189. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4190. {
  4191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4192. {
  4193. tempIndex = ((gun_index==2) ? 1: 0);
  4194. }
  4195. else
  4196. {
  4197. tempIndex = gun_index;
  4198. }
  4199. for (int index = 0; index < CCS_QUANTITY; index++)
  4200. {
  4201. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4202. {
  4203. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4204. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4205. }
  4206. }
  4207. }
  4208. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4209. {
  4210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4211. {
  4212. tempIndex = ((gun_index==2) ? 1: 0);
  4213. }
  4214. else
  4215. {
  4216. tempIndex = gun_index;
  4217. }
  4218. for (int index = 0; index < GB_QUANTITY; index++)
  4219. {
  4220. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4221. {
  4222. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4223. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4224. }
  4225. }
  4226. }
  4227. else if(gunType[gun_index] == GUN_TYPE_DO)
  4228. {
  4229. tempIndex = gun_index;
  4230. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4231. {
  4232. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4233. {
  4234. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4235. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4236. }
  4237. }
  4238. }
  4239. else
  4240. {
  4241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4242. {
  4243. tempIndex = 2;
  4244. }
  4245. else
  4246. {
  4247. tempIndex = gun_index;
  4248. }
  4249. for (int index = 0; index < AC_QUANTITY; index++)
  4250. {
  4251. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4252. {
  4253. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4254. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4255. }
  4256. }
  4257. }
  4258. random_uuid(guid);
  4259. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4260. {
  4261. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4262. , gun_index +1
  4263. , MESSAGE_TYPE_CALL
  4264. , guid
  4265. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4266. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4267. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4268. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4269. }
  4270. else
  4271. {
  4272. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4273. , gun_index +1
  4274. , MESSAGE_TYPE_CALL
  4275. , guid
  4276. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4277. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4278. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4279. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4280. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4281. }
  4282. #if 1
  4283. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4284. 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*/)
  4285. {
  4286. result = PASS;
  4287. }
  4288. #endif
  4289. strcpy(queuedata, message);
  4290. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4291. OCPP_insert_transaction_msg(YES, queuedata);
  4292. return result;
  4293. }
  4294. int sendStatusNotificationRequest(int gun_index)
  4295. {
  4296. mtrace();
  4297. int result = FAIL;
  4298. char message[600]={0};
  4299. char guid[37];
  4300. int currentStatus = 0;
  4301. struct timeval tmnow;
  4302. struct tm *tm;
  4303. char buf[28];//, usec_buf[6];
  4304. char tempdata[65]={0};
  4305. int tempIndex = 0;
  4306. uint8_t isStateChanged = TRUE;
  4307. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4308. gettimeofday(&tmnow, NULL);
  4309. time_t t;
  4310. t = time(NULL);
  4311. /*UTC time and date*/
  4312. tm = gmtime(&t);
  4313. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4314. #if 0 // remove temporally
  4315. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4316. strcat(buf,".");
  4317. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4318. strcat(buf,usec_buf);
  4319. #endif
  4320. //printf("%s",buf);
  4321. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4322. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4323. // it's option
  4324. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4325. /*
  4326. enum _SYSTEM_STATUS
  4327. {
  4328. S_BOOTING = 0,
  4329. S_IDLE, = 1
  4330. S_AUTHORIZING, =2
  4331. S_REASSIGN_CHECK, =3
  4332. S_REASSIGN, =4
  4333. S_PRECHARGE, =5
  4334. S_PREPARING_FOR_EV, =6
  4335. S_PREPARING_FOR_EVSE, =7
  4336. S_CHARGING, =8
  4337. S_TERMINATING, =9
  4338. S_COMPLETE, =10
  4339. S_ALARM, =11
  4340. S_FAULT =12
  4341. }
  4342. */
  4343. //check Transaction active
  4344. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4345. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4346. {
  4347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4348. {
  4349. tempIndex = ((gun_index==2) ? 1: 0);
  4350. }
  4351. else
  4352. {
  4353. tempIndex = gun_index;
  4354. }
  4355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4356. {
  4357. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4358. {
  4359. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4360. {
  4361. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4362. {
  4363. currentStatus = Preparing; //OCPP Status: Preparing
  4364. }
  4365. else
  4366. {
  4367. currentStatus = Available; //OCPP Status: Available
  4368. }
  4369. }
  4370. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4371. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4372. ) //S_PRECHARGE
  4373. {
  4374. currentStatus = Preparing; //OCPP Status: Preparing
  4375. }
  4376. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4377. {
  4378. currentStatus = Charging; //OCPP Status: Charging
  4379. }
  4380. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4381. {
  4382. currentStatus = Finishing; //OCPP Status: Finishing
  4383. }
  4384. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4385. {
  4386. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4387. }
  4388. 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
  4389. {
  4390. currentStatus = Unavailable; //OCPP Status: Unavailable
  4391. }
  4392. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4393. {
  4394. currentStatus = Faulted; //OCPP Status: Faulted
  4395. }
  4396. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4397. {
  4398. currentStatus = Reserved; //OCPP Status: Reserved
  4399. }
  4400. } //end of the same index
  4401. }//end of for CHAdeMO_QUANTITY
  4402. }
  4403. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < CCS_QUANTITY; index++)
  4414. {
  4415. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4416. {
  4417. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4418. {
  4419. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4420. {
  4421. currentStatus = Preparing; //OCPP Status: Preparing
  4422. }
  4423. else
  4424. {
  4425. currentStatus = Available; //OCPP Status: Available
  4426. }
  4427. }
  4428. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4429. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4430. ) //S_PRECHARGE
  4431. {
  4432. currentStatus = Preparing; //OCPP Status: Preparing
  4433. }
  4434. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4435. {
  4436. currentStatus = Charging; //OCPP Status: Charging
  4437. }
  4438. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4439. {
  4440. currentStatus = Finishing; //OCPP Status: Finishing
  4441. }
  4442. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4443. {
  4444. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4445. }
  4446. 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
  4447. {
  4448. currentStatus = Unavailable; //OCPP Status : Unavailable
  4449. }
  4450. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4451. {
  4452. currentStatus = Faulted; //OCPP Status: Faulted
  4453. }
  4454. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4455. {
  4456. currentStatus = Reserved; //OCPP Status: Reserved
  4457. }
  4458. } //end of the same index
  4459. } // end of for CCS_QUANTITY
  4460. }
  4461. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4462. {
  4463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4464. {
  4465. tempIndex = ((gun_index==2) ? 1: 0);
  4466. }
  4467. else
  4468. {
  4469. tempIndex = gun_index;
  4470. }
  4471. for (int index = 0; index < GB_QUANTITY; index++)
  4472. {
  4473. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4474. {
  4475. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4476. {
  4477. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4478. {
  4479. currentStatus = Preparing; //OCPP Status: Preparing
  4480. }
  4481. else
  4482. {
  4483. currentStatus = Available; //OCPP Status: Available
  4484. }
  4485. }
  4486. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4487. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4488. ) //S_PRECHARGE
  4489. {
  4490. currentStatus = Preparing; //OCPP Status: Preparing
  4491. }
  4492. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4493. {
  4494. currentStatus = Charging; //OCPP Status: Charging
  4495. }
  4496. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4497. {
  4498. currentStatus = Finishing; //OCPP Status: Finishing
  4499. }
  4500. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4501. {
  4502. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4503. }
  4504. 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
  4505. {
  4506. currentStatus = Unavailable; //OCPP Status: Unavailable
  4507. }
  4508. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4509. {
  4510. currentStatus = Faulted; //OCPP Status: Faulted
  4511. }
  4512. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4513. {
  4514. currentStatus = Reserved; //OCPP Status: Reserved
  4515. }
  4516. } //end of the same index
  4517. } // end of for GB_QUANTITY
  4518. }
  4519. else if(gunType[gun_index] == GUN_TYPE_DO)
  4520. {
  4521. tempIndex = gun_index;
  4522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4523. {
  4524. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4525. {
  4526. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4527. {
  4528. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4529. {
  4530. currentStatus = Preparing; //OCPP Status: Preparing
  4531. }
  4532. else
  4533. {
  4534. currentStatus = Available; //OCPP Status: Available
  4535. }
  4536. }
  4537. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4538. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4539. ) //S_PRECHARGE
  4540. {
  4541. currentStatus = Preparing; //OCPP Status: Preparing
  4542. }
  4543. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4544. {
  4545. currentStatus = Charging; //OCPP Status: Charging
  4546. }
  4547. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4548. {
  4549. currentStatus = Finishing; //OCPP Status: Finishing
  4550. }
  4551. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4552. {
  4553. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4554. }
  4555. 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
  4556. {
  4557. currentStatus = Unavailable; //OCPP Status: Unavailable
  4558. }
  4559. 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
  4560. {
  4561. currentStatus = Faulted; //OCPP Status: Faulted
  4562. }
  4563. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4564. {
  4565. currentStatus = Reserved; //OCPP Status: Reserved
  4566. }
  4567. } //end of the same index
  4568. }
  4569. }
  4570. else
  4571. {
  4572. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4573. {
  4574. tempIndex = 2;
  4575. }
  4576. else
  4577. {
  4578. tempIndex = gun_index;
  4579. }
  4580. for (int index = 0; index < AC_QUANTITY; index++)
  4581. {
  4582. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4583. {
  4584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4585. {
  4586. 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))
  4587. {
  4588. currentStatus = Preparing; //OCPP Status: Preparing
  4589. }
  4590. else
  4591. {
  4592. currentStatus = Available; //OCPP Status: Available
  4593. }
  4594. }
  4595. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4596. {
  4597. currentStatus = Preparing; //OCPP Status: Preparing
  4598. }
  4599. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4600. {
  4601. currentStatus = Charging; //OCPP Status: Charging
  4602. }
  4603. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4604. {
  4605. currentStatus = Finishing; //OCPP Status: Finishing
  4606. }
  4607. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4608. {
  4609. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4610. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4611. else
  4612. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4613. }
  4614. 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
  4615. {
  4616. currentStatus = Unavailable; //OCPP Status: Unavailable
  4617. }
  4618. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4619. {
  4620. currentStatus = Faulted; //OCPP Status: Faulted
  4621. }
  4622. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4623. {
  4624. currentStatus = Reserved; //OCPP Status: Reserved
  4625. }
  4626. }//end of the same index
  4627. }//end of for AC_QUANTITY
  4628. }
  4629. //it's option
  4630. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4631. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4632. {
  4633. isStateChanged = FALSE;
  4634. }
  4635. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4636. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4637. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4638. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4639. random_uuid(guid);
  4640. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4641. , MESSAGE_TYPE_CALL
  4642. , guid
  4643. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4644. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4645. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4646. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4647. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4648. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4649. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4650. if((server_sign == TRUE) && isStateChanged)
  4651. {
  4652. LWS_Send(message);
  4653. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4654. 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*/)
  4655. {
  4656. //DEBUG_ERROR("statusNotification mapitem pass");
  4657. result = PASS;
  4658. }
  4659. }
  4660. else
  4661. {
  4662. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4663. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4664. result = PASS;
  4665. }
  4666. return result;
  4667. }
  4668. int sendStopTransactionRequest(int gun_index)
  4669. {
  4670. mtrace();
  4671. int result = FAIL;
  4672. //char message[1500]={0};
  4673. char guid[37]={0};
  4674. char tempdata[65]={0};
  4675. int tempIndex = 0;
  4676. char TempStopTransaction[256];
  4677. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4678. //int idx_sample=0;
  4679. DEBUG_INFO("sendStopTransactionRequest \n");
  4680. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4681. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4682. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4683. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4684. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4685. {
  4686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4687. {
  4688. tempIndex = ((gun_index==2) ? 1: 0);
  4689. }
  4690. else
  4691. {
  4692. tempIndex = gun_index;
  4693. }
  4694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4695. {
  4696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4697. {
  4698. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4699. }
  4700. }// END OF CHAdeMO_QUANTITY
  4701. }
  4702. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4703. {
  4704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4705. {
  4706. tempIndex = ((gun_index==2) ? 1: 0);
  4707. }
  4708. else
  4709. {
  4710. tempIndex = gun_index;
  4711. }
  4712. for (int index = 0; index < CCS_QUANTITY; index++)
  4713. {
  4714. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4715. {
  4716. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4717. }
  4718. }// END OF CCS_QUANTITY
  4719. }
  4720. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4721. {
  4722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4723. {
  4724. tempIndex = ((gun_index==2) ? 1: 0);
  4725. }
  4726. else
  4727. {
  4728. tempIndex = gun_index;
  4729. }
  4730. for (int index = 0; index < GB_QUANTITY; index++)
  4731. {
  4732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4733. {
  4734. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4735. }
  4736. }// END OF GB_QUANTITY
  4737. }
  4738. else if(gunType[gun_index] == GUN_TYPE_DO)
  4739. {
  4740. tempIndex = gun_index;
  4741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4742. {
  4743. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4744. {
  4745. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4746. }
  4747. }// END OF GB_QUANTITY
  4748. }
  4749. else
  4750. {
  4751. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4752. {
  4753. tempIndex = 2;
  4754. }
  4755. else
  4756. {
  4757. tempIndex = gun_index;
  4758. }
  4759. for (int index = 0; index < AC_QUANTITY; index++)
  4760. {
  4761. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4762. {
  4763. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4764. }
  4765. }// END OF AC_QUANTITY
  4766. }
  4767. //====================================== Stop Transaction Time =====================================================
  4768. struct timeval tmnow;
  4769. struct tm *tm;
  4770. char buf[28];//, usec_buf[6];
  4771. gettimeofday(&tmnow, NULL);
  4772. time_t t;
  4773. t = time(NULL);
  4774. /*UTC time and date*/
  4775. tm = gmtime(&t);
  4776. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4778. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4779. random_uuid(guid);
  4780. /***********************************transactionData******************************************************/
  4781. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4783. //=================================
  4784. // Transaction_Begin
  4785. //=================================
  4786. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4787. {
  4788. //============================================ Energy.Active.Import.Interval ================================
  4789. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4792. 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*/]);
  4793. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4794. 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))
  4795. {
  4796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4797. }
  4798. else
  4799. {
  4800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4801. }
  4802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4804. }
  4805. //=================================
  4806. // Transaction_End
  4807. //=================================
  4808. // ================================= Current.Import L1 ===============================================
  4809. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4810. {
  4811. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4812. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4813. {
  4814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4815. {
  4816. tempIndex = ((gun_index==2) ? 1: 0);
  4817. }
  4818. else
  4819. {
  4820. tempIndex = gun_index;
  4821. }
  4822. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4823. {
  4824. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4825. {
  4826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4827. }
  4828. }// End of for CHAdeMO_QUANTITY
  4829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4830. }
  4831. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4832. {
  4833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4834. {
  4835. tempIndex = ((gun_index==2) ? 1: 0);
  4836. }
  4837. else
  4838. {
  4839. tempIndex = gun_index;
  4840. }
  4841. for (int index = 0; index < CCS_QUANTITY; index++)
  4842. {
  4843. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4844. {
  4845. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4846. }
  4847. }// End of for CCS_QUANTITY
  4848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4849. }
  4850. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4851. {
  4852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4853. {
  4854. tempIndex = ((gun_index==2) ? 1: 0);
  4855. }
  4856. else
  4857. {
  4858. tempIndex = gun_index;
  4859. }
  4860. for (int index = 0; index < GB_QUANTITY; index++)
  4861. {
  4862. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4863. {
  4864. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4865. }
  4866. }// End of for GB_QUANTITY
  4867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4868. }
  4869. else if(gunType[gun_index] == GUN_TYPE_DO)
  4870. {
  4871. tempIndex = gun_index;
  4872. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4873. {
  4874. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4875. {
  4876. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4877. }
  4878. }
  4879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4880. }
  4881. else
  4882. {
  4883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4884. {
  4885. tempIndex = 2;
  4886. }
  4887. else
  4888. {
  4889. tempIndex = gun_index;
  4890. }
  4891. for (int index = 0; index < AC_QUANTITY; index++)
  4892. {
  4893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4894. {
  4895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4896. }
  4897. }// End of for AC_QUANTITY
  4898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4899. }
  4900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4905. }
  4906. // ================================= Energy.Active.Import.Interval ==============================================
  4907. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4908. {
  4909. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4910. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4911. {
  4912. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4913. {
  4914. tempIndex = ((gun_index==2) ? 1: 0);
  4915. }
  4916. else
  4917. {
  4918. tempIndex = gun_index;
  4919. }
  4920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4921. {
  4922. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4923. {
  4924. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4925. }
  4926. }// END OF CHAdeMO_QUANTITY
  4927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4928. }
  4929. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4930. {
  4931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4932. {
  4933. tempIndex = ((gun_index==2) ? 1: 0);
  4934. }
  4935. else
  4936. {
  4937. tempIndex = gun_index;
  4938. }
  4939. for (int index = 0; index < CCS_QUANTITY; index++)
  4940. {
  4941. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4942. {
  4943. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4944. }
  4945. }// END OF CCS_QUANTITY
  4946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4947. }
  4948. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4949. {
  4950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4951. {
  4952. tempIndex = ((gun_index==2) ? 1: 0);
  4953. }
  4954. else
  4955. {
  4956. tempIndex = gun_index;
  4957. }
  4958. for (int index = 0; index < GB_QUANTITY; index++)
  4959. {
  4960. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4961. {
  4962. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4963. }
  4964. }// END OF GB_QUANTITY
  4965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4966. }
  4967. else if(gunType[gun_index] == GUN_TYPE_DO)
  4968. {
  4969. tempIndex = gun_index;
  4970. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4971. {
  4972. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4973. {
  4974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4975. }
  4976. }
  4977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4978. }
  4979. else
  4980. {
  4981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4982. {
  4983. tempIndex = 2;
  4984. }
  4985. else
  4986. {
  4987. tempIndex = gun_index;
  4988. }
  4989. for (int index = 0; index < AC_QUANTITY; index++)
  4990. {
  4991. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4992. {
  4993. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4994. }
  4995. }// END OF AC_QUANTITY
  4996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4997. }
  4998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5003. }
  5004. //=================================== Power.Active.Import ==================================================
  5005. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5006. {
  5007. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5008. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5009. {
  5010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5011. {
  5012. tempIndex = ((gun_index==2) ? 1: 0);
  5013. }
  5014. else
  5015. {
  5016. tempIndex = gun_index;
  5017. }
  5018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5019. {
  5020. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5021. {
  5022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5023. }
  5024. } // End for CHAdeMO_QUANTITY
  5025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5026. }
  5027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5028. {
  5029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5030. {
  5031. tempIndex = ((gun_index==2) ? 1: 0);
  5032. }
  5033. else
  5034. {
  5035. tempIndex = gun_index;
  5036. }
  5037. for (int index = 0; index < CCS_QUANTITY; index++)
  5038. {
  5039. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5040. {
  5041. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5042. }
  5043. } // END for CCS_QUANTITY
  5044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5045. }
  5046. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5047. {
  5048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5049. {
  5050. tempIndex = ((gun_index==2) ? 1: 0);
  5051. }
  5052. else
  5053. {
  5054. tempIndex = gun_index;
  5055. }
  5056. for (int index = 0; index < GB_QUANTITY; index++)
  5057. {
  5058. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5059. {
  5060. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5061. }
  5062. }// END for GB_QUANTITY
  5063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5064. }
  5065. else if(gunType[gun_index] == GUN_TYPE_DO)
  5066. {
  5067. tempIndex = gun_index;
  5068. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5069. {
  5070. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5071. {
  5072. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5073. }
  5074. }
  5075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5076. }
  5077. else
  5078. {
  5079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5080. {
  5081. tempIndex = 2;
  5082. }
  5083. else
  5084. {
  5085. tempIndex = gun_index;
  5086. }
  5087. for (int index = 0; index < AC_QUANTITY; index++)
  5088. {
  5089. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5090. {
  5091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5092. }
  5093. } // END for AC_QUANTITY
  5094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5095. }
  5096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5101. }
  5102. //============================ Voltage L1 ====================================
  5103. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5104. {
  5105. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5106. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5107. {
  5108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5109. {
  5110. tempIndex = ((gun_index==2) ? 1: 0);
  5111. }
  5112. else
  5113. {
  5114. tempIndex = gun_index;
  5115. }
  5116. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5117. {
  5118. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5119. {
  5120. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5121. }
  5122. } // END OF FOR CHAdeMO_QUANTITY
  5123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5124. }
  5125. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5126. {
  5127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5128. {
  5129. tempIndex = ((gun_index==2) ? 1: 0);
  5130. }
  5131. else
  5132. {
  5133. tempIndex = gun_index;
  5134. }
  5135. for (int index = 0; index < CCS_QUANTITY; index++)
  5136. {
  5137. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5138. {
  5139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5140. }
  5141. } // END OF FOR CCS_QUANTITY
  5142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5143. }
  5144. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5145. {
  5146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5147. {
  5148. tempIndex = ((gun_index==2) ? 1: 0);
  5149. }
  5150. else
  5151. {
  5152. tempIndex = gun_index;
  5153. }
  5154. for (int index = 0; index < GB_QUANTITY; index++)
  5155. {
  5156. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5157. {
  5158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5159. }
  5160. } // END OF FOR GB_QUANTITY
  5161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5162. }
  5163. else if(gunType[gun_index] == GUN_TYPE_DO)
  5164. {
  5165. tempIndex = gun_index;
  5166. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5167. {
  5168. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5169. {
  5170. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5171. }
  5172. }
  5173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5174. }
  5175. else
  5176. {
  5177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5178. {
  5179. tempIndex = 2;
  5180. }
  5181. else
  5182. {
  5183. tempIndex = gun_index;
  5184. }
  5185. for (int index = 0; index < AC_QUANTITY; index++)
  5186. {
  5187. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5188. {
  5189. 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
  5190. }
  5191. } // END OF FOR AC_QUANTITY
  5192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5193. }
  5194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5199. }
  5200. //====================== End SoC ================================
  5201. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5202. {
  5203. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5204. 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))
  5205. {
  5206. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5207. {
  5208. tempIndex = ((gun_index==2) ? 1: 0);
  5209. }
  5210. else
  5211. {
  5212. tempIndex = gun_index;
  5213. }
  5214. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5215. {
  5216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5217. {
  5218. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5219. {
  5220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5221. }
  5222. }
  5223. }
  5224. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5225. {
  5226. for (int index = 0; index < CCS_QUANTITY; index++)
  5227. {
  5228. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5229. {
  5230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5231. }
  5232. }
  5233. }
  5234. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5235. {
  5236. for (int index = 0; index < GB_QUANTITY; index++)
  5237. {
  5238. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5239. {
  5240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5241. }
  5242. }
  5243. }
  5244. else if(gunType[gun_index] == GUN_TYPE_DO)
  5245. {
  5246. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5247. {
  5248. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5249. {
  5250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5251. }
  5252. }
  5253. }
  5254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5260. } // END FOR DC CASE
  5261. }
  5262. // ================================= Current.Import L2 ===============================================
  5263. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5264. {
  5265. // AC 3 phse L2 current
  5266. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5267. {
  5268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5269. {
  5270. tempIndex = 2;
  5271. }
  5272. else
  5273. {
  5274. tempIndex = gun_index;
  5275. }
  5276. for (int index = 0; index < AC_QUANTITY; index++)
  5277. {
  5278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5279. {
  5280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5281. }
  5282. }// End of for AC_QUANTITY
  5283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5284. }
  5285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5290. }
  5291. // ================================= Current.Import L3 ===============================================
  5292. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5293. {
  5294. // AC 3 phse L3 current
  5295. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5296. {
  5297. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5298. {
  5299. tempIndex = 2;
  5300. }
  5301. else
  5302. {
  5303. tempIndex = gun_index;
  5304. }
  5305. for (int index = 0; index < AC_QUANTITY; index++)
  5306. {
  5307. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5308. {
  5309. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5310. }
  5311. }// End of for AC_QUANTITY
  5312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5313. }
  5314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5319. }
  5320. //============================ Voltage L2 ====================================
  5321. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5322. {
  5323. // AC 3 phse L2 voltage
  5324. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5325. {
  5326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5327. {
  5328. tempIndex = 2;
  5329. }
  5330. else
  5331. {
  5332. tempIndex = gun_index;
  5333. }
  5334. for (int index = 0; index < AC_QUANTITY; index++)
  5335. {
  5336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5337. {
  5338. 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
  5339. }
  5340. } // END OF FOR AC_QUANTITY
  5341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5342. }
  5343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5348. }
  5349. //============================ Voltage L3 ====================================
  5350. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5351. {
  5352. // AC 3 phse L3 voltage
  5353. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5354. {
  5355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5356. {
  5357. tempIndex = 2;
  5358. }
  5359. else
  5360. {
  5361. tempIndex = gun_index;
  5362. }
  5363. for (int index = 0; index < AC_QUANTITY; index++)
  5364. {
  5365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5366. {
  5367. 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
  5368. }
  5369. } // END OF FOR AC_QUANTITY
  5370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5371. }
  5372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5377. }
  5378. //====================== Start SoC ================================
  5379. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5380. {
  5381. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5382. 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))
  5383. {
  5384. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5385. {
  5386. tempIndex = ((gun_index==2) ? 1: 0);
  5387. }
  5388. else
  5389. {
  5390. tempIndex = gun_index;
  5391. }
  5392. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5393. {
  5394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5395. {
  5396. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5397. {
  5398. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5399. }
  5400. }
  5401. }
  5402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5403. {
  5404. for (int index = 0; index < CCS_QUANTITY; index++)
  5405. {
  5406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5407. {
  5408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5409. }
  5410. }
  5411. }
  5412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5413. {
  5414. for (int index = 0; index < GB_QUANTITY; index++)
  5415. {
  5416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5417. {
  5418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5419. }
  5420. }
  5421. }
  5422. else if(gunType[gun_index] == GUN_TYPE_DO)
  5423. {
  5424. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5425. {
  5426. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5427. {
  5428. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5429. }
  5430. }
  5431. }
  5432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5438. } // END FOR DC CASE
  5439. }
  5440. //================================================ Message create ====================================================
  5441. json_object *StopTransaction = json_object_new_object();
  5442. json_object *transactionDatas = json_object_new_array();
  5443. json_object *sampledValues = json_object_new_array();
  5444. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5445. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5446. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5447. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5448. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5449. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5450. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5451. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5452. {
  5453. json_object *transactionData = json_object_new_object();
  5454. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5455. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5456. {
  5457. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5458. {
  5459. json_object *sampledValue = json_object_new_object();
  5460. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5461. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5462. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5463. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5464. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5465. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5466. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5467. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5468. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5469. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5470. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5471. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5472. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5473. json_object_array_add(sampledValues, sampledValue);
  5474. }
  5475. }
  5476. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5477. json_object_array_add(transactionDatas, transactionData);
  5478. }
  5479. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5480. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5481. ,MESSAGE_TYPE_CALL
  5482. ,guid
  5483. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5484. json_object_put(StopTransaction);
  5485. #if 1 // for TempStopTransaction
  5486. //Delete TempStopTransaction
  5487. if((access(TempStopTransaction,F_OK))!=-1)
  5488. {
  5489. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5490. }
  5491. #endif
  5492. #if 1
  5493. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5494. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5495. {
  5496. result = PASS;
  5497. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5498. }
  5499. #endif
  5500. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5501. OCPP_insert_transaction_msg(NO, queuedata);
  5502. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5503. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5504. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5505. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5506. {
  5507. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5508. }
  5509. //for test
  5510. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5511. return result;
  5512. }
  5513. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5514. {
  5515. mtrace();
  5516. int result = FAIL;
  5517. char guid[37]={0};
  5518. char tempdata[65]={0};
  5519. int tempIndex = 0;
  5520. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5521. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5522. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5523. //set value
  5524. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5525. 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) )?
  5526. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5527. -1);
  5528. random_uuid(guid);
  5529. //UTC Date time
  5530. struct timeval tmnow;
  5531. struct tm *tm;
  5532. char buf[28];//, usec_buf[6];
  5533. gettimeofday(&tmnow, NULL);
  5534. time_t t;
  5535. t = time(NULL);
  5536. /*UTC time and date*/
  5537. tm = gmtime(&t);
  5538. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5540. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5541. //********************************(1)Current.Import L1************************************************/
  5542. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5543. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5544. (dataType == ReadingContext_Trigger))
  5545. {
  5546. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5547. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5548. {
  5549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5550. {
  5551. tempIndex = ((gun_index==2) ? 1: 0);
  5552. }
  5553. else
  5554. {
  5555. tempIndex = gun_index;
  5556. }
  5557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5558. {
  5559. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5560. {
  5561. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5562. }
  5563. }
  5564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5565. }
  5566. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5567. {
  5568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5569. {
  5570. tempIndex = ((gun_index==2) ? 1: 0);
  5571. }
  5572. else
  5573. {
  5574. tempIndex = gun_index;
  5575. }
  5576. for (int index = 0; index < CCS_QUANTITY; index++)
  5577. {
  5578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5579. {
  5580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5581. }
  5582. }
  5583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5584. }
  5585. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5586. {
  5587. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5588. {
  5589. tempIndex = ((gun_index==2) ? 1: 0);
  5590. }
  5591. else
  5592. {
  5593. tempIndex = gun_index;
  5594. }
  5595. for (int index = 0; index < GB_QUANTITY; index++)
  5596. {
  5597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5598. {
  5599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5600. }
  5601. }
  5602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5603. }
  5604. else if(gunType[gun_index] == GUN_TYPE_DO)
  5605. {
  5606. tempIndex = gun_index;
  5607. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5608. {
  5609. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5610. {
  5611. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5612. }
  5613. }
  5614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5615. }
  5616. else
  5617. {
  5618. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5619. {
  5620. tempIndex = 2;
  5621. }
  5622. else
  5623. {
  5624. tempIndex = gun_index;
  5625. }
  5626. for (int index = 0; index < AC_QUANTITY; index++)
  5627. {
  5628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5629. {
  5630. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5631. }
  5632. }
  5633. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5634. }
  5635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5640. }
  5641. //********************************(2)Energy.Active.Import.Register ************************************************/
  5642. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5643. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5644. (dataType == ReadingContext_Trigger))
  5645. {
  5646. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5647. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  5658. {
  5659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5660. {
  5661. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5662. }
  5663. }
  5664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5665. }
  5666. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  5677. {
  5678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5679. {
  5680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5681. }
  5682. }
  5683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5684. }
  5685. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5686. {
  5687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5688. {
  5689. tempIndex = ((gun_index==2) ? 1: 0);
  5690. }
  5691. else
  5692. {
  5693. tempIndex = gun_index;
  5694. }
  5695. for (int index = 0; index < GB_QUANTITY; index++)
  5696. {
  5697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5698. {
  5699. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5700. }
  5701. }
  5702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5703. }
  5704. else if(gunType[gun_index] == GUN_TYPE_DO)
  5705. {
  5706. tempIndex = gun_index;
  5707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5708. {
  5709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5710. {
  5711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5712. }
  5713. }
  5714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5715. }
  5716. else
  5717. {
  5718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5719. {
  5720. tempIndex = 2;
  5721. }
  5722. else
  5723. {
  5724. tempIndex = gun_index;
  5725. }
  5726. for (int index = 0; index < AC_QUANTITY; index++)
  5727. {
  5728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5729. {
  5730. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5731. }
  5732. }
  5733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5734. }
  5735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5740. }
  5741. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5742. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5743. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5744. (dataType == ReadingContext_Trigger))
  5745. {
  5746. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5747. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  5758. {
  5759. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5760. {
  5761. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5762. }
  5763. } // END OF FOR CHAdeMO_QUANTITY
  5764. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5765. }
  5766. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  5777. {
  5778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5779. {
  5780. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5781. }
  5782. } // END OF CCS_QUANTITY
  5783. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5784. }
  5785. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5786. {
  5787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5788. {
  5789. tempIndex = ((gun_index==2) ? 1: 0);
  5790. }
  5791. else
  5792. {
  5793. tempIndex = gun_index;
  5794. }
  5795. for (int index = 0; index < GB_QUANTITY; index++)
  5796. {
  5797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5798. {
  5799. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5800. }
  5801. } // END OF GB_QUANTITY
  5802. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5803. }
  5804. else if(gunType[gun_index] == GUN_TYPE_DO)
  5805. {
  5806. tempIndex = gun_index;
  5807. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5808. {
  5809. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5810. {
  5811. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5812. }
  5813. }
  5814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5815. }
  5816. else
  5817. {
  5818. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5819. {
  5820. tempIndex = 2;
  5821. }
  5822. else
  5823. {
  5824. tempIndex = gun_index;
  5825. }
  5826. for (int index = 0; index < AC_QUANTITY; index++)
  5827. {
  5828. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5829. {
  5830. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5831. }
  5832. }
  5833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5834. }
  5835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5840. }
  5841. //********************************(4)Power.Active.Import************************************************/
  5842. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5843. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5844. (dataType == ReadingContext_Trigger))
  5845. {
  5846. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5847. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  5858. {
  5859. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5860. {
  5861. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5862. }
  5863. } // END OF FOR
  5864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5865. }
  5866. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  5877. {
  5878. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5879. {
  5880. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5881. }
  5882. }
  5883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5884. }
  5885. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5886. {
  5887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5888. {
  5889. tempIndex = ((gun_index==2) ? 1: 0);
  5890. }
  5891. else
  5892. {
  5893. tempIndex = gun_index;
  5894. }
  5895. for (int index = 0; index < GB_QUANTITY; index++)
  5896. {
  5897. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5898. {
  5899. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5900. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5901. }
  5902. }
  5903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5904. }
  5905. else if(gunType[gun_index] == GUN_TYPE_DO)
  5906. {
  5907. tempIndex = gun_index;
  5908. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5909. {
  5910. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5911. {
  5912. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5913. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5914. }
  5915. }
  5916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5917. }
  5918. else
  5919. {
  5920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5921. {
  5922. tempIndex = 2;
  5923. }
  5924. else
  5925. {
  5926. tempIndex = gun_index;
  5927. }
  5928. for (int index = 0; index < AC_QUANTITY; index++)
  5929. {
  5930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5931. {
  5932. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5933. }
  5934. }
  5935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5936. }
  5937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5942. }
  5943. //***********************************************(5)VOLTAGE L1******************************************************/
  5944. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5945. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5946. (dataType == ReadingContext_Trigger))
  5947. {
  5948. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5949. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5950. {
  5951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5952. {
  5953. tempIndex = ((gun_index==2) ? 1: 0);
  5954. }
  5955. else
  5956. {
  5957. tempIndex = gun_index;
  5958. }
  5959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5960. {
  5961. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5962. {
  5963. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5964. }
  5965. }
  5966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5967. }
  5968. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5969. {
  5970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5971. {
  5972. tempIndex = ((gun_index==2) ? 1: 0);
  5973. }
  5974. else
  5975. {
  5976. tempIndex = gun_index;
  5977. }
  5978. for (int index = 0; index < CCS_QUANTITY; index++)
  5979. {
  5980. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5981. {
  5982. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5983. }
  5984. }
  5985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5986. }
  5987. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5988. {
  5989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5990. {
  5991. tempIndex = ((gun_index==2) ? 1: 0);
  5992. }
  5993. else
  5994. {
  5995. tempIndex = gun_index;
  5996. }
  5997. for (int index = 0; index < GB_QUANTITY; index++)
  5998. {
  5999. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6000. {
  6001. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6002. }
  6003. }
  6004. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6005. }
  6006. else if(gunType[gun_index] == GUN_TYPE_DO)
  6007. {
  6008. tempIndex = gun_index;
  6009. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6012. {
  6013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6014. }
  6015. }
  6016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6017. }
  6018. else
  6019. {
  6020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6021. {
  6022. tempIndex = 2;
  6023. }
  6024. else
  6025. {
  6026. tempIndex = gun_index;
  6027. }
  6028. for (int index = 0; index < AC_QUANTITY; index++)
  6029. {
  6030. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6031. {
  6032. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6033. }
  6034. }
  6035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6036. }
  6037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6042. }
  6043. //***********************************************(6)SOC******************************************************/
  6044. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  6045. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  6046. (dataType == ReadingContext_Trigger))
  6047. {
  6048. 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))
  6049. {
  6050. //idx_sample=5;
  6051. //sampledValue = NULL;
  6052. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6053. {
  6054. tempIndex = ((gun_index==2) ? 1: 0);
  6055. }
  6056. else
  6057. {
  6058. tempIndex = gun_index;
  6059. }
  6060. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6061. {
  6062. //tempIndex = ((gun_index==2) ? 1: 0);
  6063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6064. {
  6065. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6066. {
  6067. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6068. }
  6069. }
  6070. }
  6071. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6072. {
  6073. //tempIndex = ((gun_index==2) ? 1: 0);
  6074. for (int index = 0; index < CCS_QUANTITY; index++)
  6075. {
  6076. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6077. {
  6078. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6079. }
  6080. }
  6081. }
  6082. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6083. {
  6084. //tempIndex = ((gun_index==2) ? 1: 0);
  6085. for (int index = 0; index < GB_QUANTITY; index++)
  6086. {
  6087. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6088. {
  6089. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6090. }
  6091. }
  6092. }
  6093. else if(gunType[gun_index] == GUN_TYPE_DO)
  6094. {
  6095. //tempIndex = ((gun_index==2) ? 1: 0);
  6096. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6097. {
  6098. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6099. {
  6100. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6101. }
  6102. }
  6103. }
  6104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6106. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6109. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6110. }
  6111. }
  6112. //********************************(7)Current.Import L2************************************************/
  6113. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6114. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6115. (dataType == ReadingContext_Trigger))
  6116. {
  6117. // Only for AC 3 phase
  6118. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6119. {
  6120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6121. {
  6122. tempIndex = 2;
  6123. }
  6124. else
  6125. {
  6126. tempIndex = gun_index;
  6127. }
  6128. for (int index = 0; index < AC_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6131. {
  6132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6133. }
  6134. }
  6135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6136. }
  6137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6142. }
  6143. //********************************(8)Current.Import L3************************************************/
  6144. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6145. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6146. (dataType == ReadingContext_Trigger))
  6147. {
  6148. // Only for AC 3 phase
  6149. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6150. {
  6151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6152. {
  6153. tempIndex = 2;
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. for (int index = 0; index < AC_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6162. {
  6163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6164. }
  6165. }
  6166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6167. }
  6168. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6169. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6170. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6173. }
  6174. //***********************************************(9)VOLTAGE L2******************************************************/
  6175. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6176. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6177. (dataType == ReadingContext_Trigger))
  6178. {
  6179. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6180. {
  6181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6182. {
  6183. tempIndex = 2;
  6184. }
  6185. else
  6186. {
  6187. tempIndex = gun_index;
  6188. }
  6189. for (int index = 0; index < AC_QUANTITY; index++)
  6190. {
  6191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6192. {
  6193. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6194. }
  6195. }
  6196. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6197. }
  6198. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6203. }
  6204. //***********************************************(10)VOLTAGE L3******************************************************/
  6205. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6206. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6207. (dataType == ReadingContext_Trigger))
  6208. {
  6209. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6210. {
  6211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6212. {
  6213. tempIndex = 2;
  6214. }
  6215. else
  6216. {
  6217. tempIndex = gun_index;
  6218. }
  6219. for (int index = 0; index < AC_QUANTITY; index++)
  6220. {
  6221. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6222. {
  6223. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6224. }
  6225. }
  6226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6227. }
  6228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6233. }
  6234. // Message create ====================================================================================================
  6235. if(TRUE)
  6236. {
  6237. json_object *MeterValueReq = json_object_new_object();
  6238. json_object *MeterValues = json_object_new_array();
  6239. json_object *sampledValues = json_object_new_array();
  6240. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6241. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6242. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6243. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6244. {
  6245. json_object *MeterValue = json_object_new_object();
  6246. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6247. {
  6248. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6249. {
  6250. json_object *sampledValue = json_object_new_object();
  6251. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6252. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6253. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6254. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6255. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6256. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6257. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6258. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6259. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6260. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6261. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6262. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6263. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6264. json_object_array_add(sampledValues, sampledValue);
  6265. }
  6266. }
  6267. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6268. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6269. json_object_array_add(MeterValues, MeterValue);
  6270. }
  6271. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6272. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6273. ,gun_index + 1
  6274. ,MESSAGE_TYPE_CALL
  6275. ,guid
  6276. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6277. json_object_put(MeterValueReq);
  6278. }
  6279. // Put request guid to hash map
  6280. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6281. 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*/)
  6282. {
  6283. result = PASS;
  6284. //DEBUG_INFO("MeterValues mapitem pass\n");
  6285. }
  6286. if((dataType != ReadingContext_Trigger) &&
  6287. (dataType != ReadingContext_Sample_Clock) &&
  6288. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  6289. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6290. else
  6291. {
  6292. if(FirstHeartBeat)
  6293. LWS_Send(queuedata +2);
  6294. }
  6295. return result;
  6296. }
  6297. int sendLogStatusNotificationRequest(char *status)
  6298. {
  6299. mtrace();
  6300. int result = PASS;
  6301. char message[4096]={0};
  6302. char guid[37]={0};
  6303. char tempdata[128]={0};
  6304. json_object *LogStatusNotification = json_object_new_object();
  6305. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6306. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6307. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6308. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6309. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6310. random_uuid(guid);
  6311. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6312. json_object_put(LogStatusNotification);
  6313. LWS_Send(message);
  6314. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6315. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6316. {
  6317. result = PASS;
  6318. }
  6319. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6320. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6321. return result;
  6322. }
  6323. int sendSecurityEventNotificationRequest()
  6324. {
  6325. mtrace();
  6326. int result = PASS;
  6327. char message[4096]={0};
  6328. char guid[37]={0};
  6329. char tempdata[128]={0};
  6330. json_object *SecurityEventNotification = json_object_new_object();
  6331. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6332. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6333. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6334. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6335. random_uuid(guid);
  6336. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6337. json_object_put(SecurityEventNotification);
  6338. LWS_Send(message);
  6339. sprintf(tempdata, "SecurityEventNotification,0");
  6340. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6341. {
  6342. result = PASS;
  6343. }
  6344. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6345. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6346. return result;
  6347. }
  6348. int sendSignCertificateRequest()
  6349. {
  6350. mtrace();
  6351. int result = PASS;
  6352. char message[4096]={0};
  6353. char guid[37]={0};
  6354. char tempdata[128]={0};
  6355. json_object *SignCertificate = json_object_new_object();
  6356. DEBUG_INFO("sendSignCertificateRequest...\n");
  6357. // Read csr file content
  6358. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6359. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6360. char *line = NULL;
  6361. size_t len = 0;
  6362. while(getline(&line, &len, fp) != -1)
  6363. {
  6364. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6365. {
  6366. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6367. }
  6368. }
  6369. fclose(fp);
  6370. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6371. random_uuid(guid);
  6372. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6373. json_object_put(SignCertificate);
  6374. LWS_Send(message);
  6375. sprintf(tempdata, "SignCertificate,0");
  6376. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6377. {
  6378. result = PASS;
  6379. }
  6380. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6381. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6382. return result;
  6383. }
  6384. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6385. {
  6386. mtrace();
  6387. int result = PASS;
  6388. char message[110]={0};
  6389. char guid[37]={0};
  6390. char tempdata[65]={0};
  6391. json_object *FirmwareStatusNotification = json_object_new_object();
  6392. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6393. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6394. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6395. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6396. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6397. random_uuid(guid);
  6398. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6399. json_object_put(FirmwareStatusNotification);
  6400. LWS_Send(message);
  6401. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6402. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6403. {
  6404. result = PASS;
  6405. }
  6406. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6407. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6408. return result;
  6409. }
  6410. //==========================================
  6411. // send confirm routine
  6412. //==========================================
  6413. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6414. {
  6415. mtrace();
  6416. int result = FAIL;
  6417. char message[100]={0};
  6418. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6419. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6420. LWS_Send(message);
  6421. result = TRUE;
  6422. return result;
  6423. }
  6424. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6425. {
  6426. mtrace();
  6427. int result = FAIL;
  6428. char message[100]={0};
  6429. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6430. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6431. LWS_Send(message);
  6432. result = TRUE;
  6433. return result;
  6434. }
  6435. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6436. {
  6437. mtrace();
  6438. int result = FAIL;
  6439. char message[100]={0};
  6440. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6441. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6442. LWS_Send(message);
  6443. result = TRUE;
  6444. return result;
  6445. }
  6446. int sendClearCacheConfirmation(char *uuid,char *payload)
  6447. {
  6448. mtrace();
  6449. int result = FAIL;
  6450. char message[500]={0};
  6451. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6452. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6453. LWS_Send(message);
  6454. return result;
  6455. }
  6456. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6457. {
  6458. mtrace();
  6459. int result = FAIL;
  6460. char message[500]={0};
  6461. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6462. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6463. LWS_Send(message);
  6464. return result;
  6465. }
  6466. int sendDataTransferConfirmation(char *uuid,char *payload)
  6467. {
  6468. mtrace();
  6469. char statusStr[20]={0};
  6470. char dataStr[10]={0};
  6471. char sstr[20]={0};
  6472. int c = 0;
  6473. char *loc;
  6474. int result = FAIL;
  6475. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6476. /**********************status**************************/
  6477. loc = strstr(payload, "status");
  6478. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6479. c = 0;
  6480. while (loc[3+strlen("status")+c] != '\"')
  6481. {
  6482. sstr[c] = loc[3+strlen("status")+c];
  6483. c++;
  6484. }
  6485. sstr[c] = '\0';
  6486. strcpy(statusStr, sstr);
  6487. /**********************data**************************/
  6488. loc = strstr(payload, "data");
  6489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6490. c = 0;
  6491. while (loc[3+strlen("data")+c] != '\"')
  6492. {
  6493. sstr[c] = loc[3+strlen("data")+c];
  6494. c++;
  6495. }
  6496. sstr[c] = '\0';
  6497. strcpy(dataStr, sstr);
  6498. return result;
  6499. }
  6500. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6501. {
  6502. mtrace();
  6503. int result = FAIL;
  6504. char message[1000]={0};
  6505. int CompositeScheduleIndex = 0;
  6506. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6507. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6508. if(nPeriod == 0)
  6509. {
  6510. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6511. {
  6512. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6513. ,MESSAGE_TYPE_CALLRESULT
  6514. ,uuid
  6515. ,payload
  6516. ,connectorIdInt);
  6517. }
  6518. else
  6519. {
  6520. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6521. ,MESSAGE_TYPE_CALLRESULT
  6522. ,uuid
  6523. ,payload
  6524. ,connectorIdInt
  6525. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6526. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6527. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6528. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6529. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6530. }
  6531. }
  6532. else
  6533. {
  6534. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6535. ,MESSAGE_TYPE_CALLRESULT
  6536. ,uuid
  6537. ,payload
  6538. ,connectorIdInt
  6539. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6540. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6541. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6542. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6543. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6544. {
  6545. if (idx_sample == 0)
  6546. {
  6547. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6548. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6549. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6550. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6551. }
  6552. else
  6553. {
  6554. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6555. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6556. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6557. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6558. }
  6559. }
  6560. sprintf(message + strlen(message), "]}}]");
  6561. }
  6562. LWS_Send(message);
  6563. result = TRUE;
  6564. return result;
  6565. }
  6566. int sendGetConfigurationConfirmation(char *uuid)
  6567. {
  6568. mtrace();
  6569. int result = FAIL;
  6570. int MaxKeySupported = 0;
  6571. int sentConfigurationNumber= 0;
  6572. int sentunConfigurationNumber= 0;
  6573. char message[4000]={0};
  6574. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6575. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6576. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6577. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6578. ,MESSAGE_TYPE_CALLRESULT
  6579. ,uuid );
  6580. //configuration key
  6581. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6582. {
  6583. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6584. {
  6585. if (sentConfigurationNumber == 0)
  6586. {
  6587. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6588. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6589. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6590. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6591. }
  6592. else
  6593. {
  6594. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6595. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6596. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6597. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6598. }
  6599. sentConfigurationNumber = sentConfigurationNumber + 1;
  6600. }
  6601. }
  6602. sprintf(message + strlen(message), "]");
  6603. if(UnknownKeynum != 0)
  6604. {
  6605. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6606. //unkown key
  6607. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6608. {
  6609. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6610. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6611. if(sentunConfigurationNumber == 0)
  6612. {
  6613. sprintf(message + strlen(message), "\"%s\""
  6614. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6615. }
  6616. else
  6617. {
  6618. sprintf(message + strlen(message), ",\"%s\""
  6619. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6620. }
  6621. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6622. }
  6623. sprintf(message + strlen(message), "]");
  6624. }
  6625. sprintf(message + strlen(message), "}]");
  6626. LWS_Send(message);
  6627. return result;
  6628. }
  6629. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6630. {
  6631. mtrace();
  6632. int result = FAIL;
  6633. char message[400]={0};
  6634. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6635. if(strcmp(payload,"")==0)
  6636. {
  6637. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6638. }
  6639. else
  6640. {
  6641. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6642. }
  6643. LWS_Send(message);
  6644. result = TRUE;
  6645. return result;
  6646. }
  6647. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6648. {
  6649. mtrace();
  6650. int result = FAIL;
  6651. char message[80]={0};
  6652. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6653. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6654. LWS_Send(message);
  6655. result = TRUE;
  6656. return result;
  6657. }
  6658. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6659. {
  6660. mtrace();
  6661. int result = FAIL;
  6662. char message[80]={0};
  6663. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6664. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6665. LWS_Send(message);
  6666. result = TRUE;
  6667. return result;
  6668. }
  6669. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6670. {
  6671. mtrace();
  6672. int result = FAIL;
  6673. char message[80]={0};
  6674. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6675. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6676. LWS_Send(message);
  6677. result = TRUE;
  6678. return result;
  6679. }
  6680. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6681. {
  6682. mtrace();
  6683. int result = FAIL;
  6684. char message[80]={0};
  6685. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6686. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6687. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6688. LWS_Send(message);
  6689. result = TRUE;
  6690. return result;
  6691. }
  6692. int sendResetConfirmation(char *uuid,char *payload)
  6693. {
  6694. mtrace();
  6695. int result = FAIL;
  6696. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6697. char message[80]={0};
  6698. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6699. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6700. LWS_Send(message);
  6701. result = TRUE;
  6702. return result;
  6703. }
  6704. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6705. {
  6706. mtrace();
  6707. int result = FAIL;
  6708. char message[500]={0};
  6709. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6710. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6711. LWS_Send(message);
  6712. result = TRUE;
  6713. return result;
  6714. }
  6715. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6716. {
  6717. mtrace();
  6718. int result = FAIL;
  6719. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6720. char message[80]={0};
  6721. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6722. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6723. LWS_Send(message);
  6724. result = TRUE;
  6725. return result;
  6726. }
  6727. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6728. {
  6729. mtrace();
  6730. int result = FAIL;
  6731. char message[80]={0};
  6732. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6734. LWS_Send(message);
  6735. result = TRUE;
  6736. return result;
  6737. }
  6738. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6739. {
  6740. mtrace();
  6741. int result = FAIL;
  6742. char message[80]={0};
  6743. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6744. DEBUG_INFO("sendUnlockConnectorConfirmation...\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 sendUpdateFirmwareConfirmation(char *uuid)
  6751. {
  6752. mtrace();
  6753. int result = FAIL;
  6754. char message[60]={0};
  6755. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6756. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6757. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6758. LWS_Send(message);
  6759. result = TRUE;
  6760. return result;
  6761. }
  6762. int sendCertificateSignedConfirmation(char *uuid)
  6763. {
  6764. mtrace();
  6765. int result = PASS;
  6766. char message[4096]={0};
  6767. json_object *CertificateSigned = json_object_new_object();
  6768. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6769. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6770. sprintf(message,"[%d,\"%s\",%s]"
  6771. ,MESSAGE_TYPE_CALLRESULT
  6772. ,uuid
  6773. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6774. json_object_put(CertificateSigned);
  6775. LWS_Send(message);
  6776. return result;
  6777. }
  6778. int sendDeleteCertificateConfirmation(char *uuid)
  6779. {
  6780. mtrace();
  6781. int result = PASS;
  6782. char message[4096]={0};
  6783. json_object *DeleteCertificate = json_object_new_object();
  6784. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6785. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6786. sprintf(message,"[%d,\"%s\",%s]"
  6787. ,MESSAGE_TYPE_CALLRESULT
  6788. ,uuid
  6789. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6790. json_object_put(DeleteCertificate);
  6791. LWS_Send(message);
  6792. return result;
  6793. }
  6794. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6795. {
  6796. mtrace();
  6797. int result = PASS;
  6798. char message[4096]={0};
  6799. json_object *ExtendedTriggerMessage = json_object_new_object();
  6800. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6801. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6802. sprintf(message,"[%d,\"%s\",%s]"
  6803. ,MESSAGE_TYPE_CALLRESULT
  6804. ,uuid
  6805. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6806. json_object_put(ExtendedTriggerMessage);
  6807. LWS_Send(message);
  6808. return result;
  6809. }
  6810. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6811. {
  6812. mtrace();
  6813. int result = PASS;
  6814. char message[4096]={0};
  6815. json_object *GetInstalledCertificateIds = json_object_new_object();
  6816. json_object *certificateHashDataDatas = json_object_new_array();
  6817. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6818. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6819. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6820. {
  6821. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6822. {
  6823. json_object *certificateHashData = json_object_new_object();
  6824. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6825. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6826. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6827. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6828. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6829. }
  6830. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6831. }
  6832. else
  6833. {
  6834. json_object_put(certificateHashDataDatas);
  6835. }
  6836. sprintf(message,"[%d,\"%s\",%s]"
  6837. ,MESSAGE_TYPE_CALLRESULT
  6838. ,uuid
  6839. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6840. json_object_put(GetInstalledCertificateIds);
  6841. LWS_Send(message);
  6842. return result;
  6843. }
  6844. int sendGetLogConfirmation(char *uuid)
  6845. {
  6846. mtrace();
  6847. int result = PASS;
  6848. char message[4096]={0};
  6849. json_object *GetLog = json_object_new_object();
  6850. DEBUG_INFO("sendGetLogConfirmation...\n");
  6851. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6852. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6853. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6854. sprintf(message,"[%d,\"%s\",%s]"
  6855. ,MESSAGE_TYPE_CALLRESULT
  6856. ,uuid
  6857. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6858. json_object_put(GetLog);
  6859. LWS_Send(message);
  6860. return result;
  6861. }
  6862. int sendInstallCertificateConfirmation(char *uuid)
  6863. {
  6864. mtrace();
  6865. int result = PASS;
  6866. char message[4096]={0};
  6867. json_object *InstallCertificate = json_object_new_object();
  6868. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6869. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6870. sprintf(message,"[%d,\"%s\",%s]"
  6871. ,MESSAGE_TYPE_CALLRESULT
  6872. ,uuid
  6873. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6874. json_object_put(InstallCertificate);
  6875. LWS_Send(message);
  6876. return result;
  6877. }
  6878. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6879. {
  6880. mtrace();
  6881. int result = PASS;
  6882. char message[4096]={0};
  6883. json_object *SignedUpdateFirmware = json_object_new_object();
  6884. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6885. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6886. sprintf(message,"[%d,\"%s\",%s]"
  6887. ,MESSAGE_TYPE_CALLRESULT
  6888. ,uuid
  6889. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6890. json_object_put(SignedUpdateFirmware);
  6891. LWS_Send(message);
  6892. return result;
  6893. }
  6894. int sendUnknownConfirmation(char *uuid)
  6895. {
  6896. mtrace();
  6897. int result = PASS;
  6898. char message[256]={0};
  6899. DEBUG_INFO("sendUnknownConfirmation...\n");
  6900. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6901. LWS_Send(message);
  6902. return result;
  6903. }
  6904. //==========================================
  6905. // Handle server request routine Start
  6906. //==========================================
  6907. int handleCancelReservationRequest(char *uuid, char *payload)
  6908. {
  6909. mtrace();
  6910. int result = FAIL;
  6911. int gunNO = 0;
  6912. int reservationIdInt = -1;
  6913. char comfirmstr[20];
  6914. DEBUG_INFO("handleCancelReservationRequest...\n");
  6915. json_object *CancelReservation;
  6916. CancelReservation = json_tokener_parse(payload);
  6917. if(!is_error(CancelReservation))
  6918. {
  6919. // Required data
  6920. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6921. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6922. }
  6923. json_object_put(CancelReservation);
  6924. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6925. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6926. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6927. if(reservationIdInt != -1)
  6928. {
  6929. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6930. //check Transaction active
  6931. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6935. {
  6936. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6937. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6938. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6939. {
  6940. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6941. }
  6942. else
  6943. {
  6944. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6945. }
  6946. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6947. goto end;
  6948. }
  6949. }
  6950. for (int index = 0; index < CCS_QUANTITY; index++)
  6951. {
  6952. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6953. {
  6954. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6955. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6956. if(gunType[2] == GUN_TYPE_CCS)
  6957. {
  6958. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6959. }
  6960. else
  6961. {
  6962. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6963. }
  6964. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6965. goto end;
  6966. }
  6967. }
  6968. for (int index = 0; index < GB_QUANTITY; index++)
  6969. {
  6970. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6971. {
  6972. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6973. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6974. if(gunType[2] == GUN_TYPE_GBT)
  6975. {
  6976. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6977. }
  6978. else
  6979. {
  6980. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6981. }
  6982. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6983. goto end;
  6984. }
  6985. }
  6986. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6987. {
  6988. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6989. {
  6990. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6991. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6992. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6993. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6994. goto end;
  6995. }
  6996. }
  6997. for (int index = 0; index < AC_QUANTITY; index++)
  6998. {
  6999. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7000. {
  7001. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7002. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7004. {
  7005. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7006. }
  7007. else
  7008. {
  7009. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7010. }
  7011. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7012. goto end;
  7013. }
  7014. }
  7015. }
  7016. //The reservationId does NOT match the reservationId
  7017. sendCancelReservationConfirmation(uuid, comfirmstr);
  7018. end:
  7019. // Fill in ocpp packet uuid
  7020. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7021. return result;
  7022. }
  7023. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7024. {
  7025. mtrace();
  7026. int result = FAIL;
  7027. int gunIndex = 0;
  7028. char typeStr[16]={0};
  7029. char comfirmstr[20];
  7030. int specificId = FALSE;
  7031. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7032. json_object *ChangeAvailability;
  7033. ChangeAvailability = json_tokener_parse(payload);
  7034. if(!is_error(ChangeAvailability))
  7035. {
  7036. // Required data
  7037. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7038. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7039. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7040. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7041. }
  7042. json_object_put(ChangeAvailability);
  7043. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7044. {
  7045. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7046. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7047. }
  7048. else if(gunIndex == 0)
  7049. {
  7050. for(int i=0; i < gunTotalNumber; i++)
  7051. {
  7052. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7053. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7054. }
  7055. }
  7056. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7057. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7058. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7059. {
  7060. specificId = TRUE;
  7061. }
  7062. if(specificId == FALSE)
  7063. goto end;
  7064. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7065. {
  7066. //----------------------gunIndex is 0 ------------------------------------------------//
  7067. if(gunIndex == 0)
  7068. {
  7069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7070. {
  7071. for(int i=0; i < gunTotalNumber; i++)
  7072. {
  7073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7074. {
  7075. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7076. {
  7077. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7078. {
  7079. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7080. goto end;
  7081. }
  7082. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7083. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7084. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7085. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7086. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7087. {
  7088. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7089. goto end;
  7090. }
  7091. }
  7092. }//END FOR CHAdeMO_QUANTITY
  7093. for (int index = 0; index < CCS_QUANTITY; index++)
  7094. {
  7095. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7096. {
  7097. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7098. {
  7099. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7100. goto end;
  7101. }
  7102. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7103. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7104. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7105. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7106. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7107. {
  7108. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7109. goto end;
  7110. }
  7111. }
  7112. }//END FOR CCS_QUANTITY
  7113. for (int index = 0; index < GB_QUANTITY; index++)
  7114. {
  7115. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7116. {
  7117. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7118. {
  7119. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7120. goto end;
  7121. }
  7122. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7123. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7124. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7125. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7126. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7127. {
  7128. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7129. goto end;
  7130. }
  7131. }
  7132. }// END FOR GB_QUANTITY
  7133. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7134. {
  7135. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7136. {
  7137. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7138. {
  7139. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7140. goto end;
  7141. }
  7142. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7143. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7144. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7145. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7146. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7147. {
  7148. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7149. goto end;
  7150. }
  7151. }
  7152. }// END FOR GENERAL_GUN_QUANTITY
  7153. for (int index = 0; index < AC_QUANTITY; index++)
  7154. {
  7155. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7156. {
  7157. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7158. {
  7159. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7160. goto end;
  7161. }
  7162. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7163. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7164. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7165. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7166. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7167. {
  7168. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7169. goto end;
  7170. }
  7171. }
  7172. }//END FOR AC_QUANTITY
  7173. }// END FOR gunTotalNumber
  7174. }
  7175. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7176. {
  7177. for(int i=0; i < gunTotalNumber; i++)
  7178. {
  7179. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7180. {
  7181. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7182. goto end;
  7183. }
  7184. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7185. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7186. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7187. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7188. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7189. {
  7190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7191. goto end;
  7192. }
  7193. }
  7194. }
  7195. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7196. goto end;
  7197. }
  7198. //----------------------gunIndex is not 0 ------------------------------------------------//
  7199. //check Transaction active
  7200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7201. {
  7202. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7203. {
  7204. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7205. {
  7206. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7207. goto end;
  7208. }
  7209. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7210. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7211. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7212. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7213. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7214. {
  7215. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7216. goto end;
  7217. }
  7218. else
  7219. {
  7220. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7221. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7222. goto end;
  7223. }
  7224. }
  7225. }//END FOR CHAdeMO_QUANTITY
  7226. for (int index = 0; index < CCS_QUANTITY; index++)
  7227. {
  7228. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7229. {
  7230. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7231. {
  7232. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7233. goto end;
  7234. }
  7235. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7236. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7237. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7238. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7239. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7240. {
  7241. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7242. goto end;
  7243. }
  7244. else
  7245. {
  7246. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7247. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7248. goto end;
  7249. }
  7250. }
  7251. }//END FOR CCS_QUANTITY
  7252. for (int index = 0; index < GB_QUANTITY; index++)
  7253. {
  7254. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7255. {
  7256. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7257. {
  7258. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7259. goto end;
  7260. }
  7261. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7262. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7263. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7264. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7265. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7266. {
  7267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7268. goto end;
  7269. }
  7270. else
  7271. {
  7272. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7274. goto end;
  7275. }
  7276. }
  7277. }// END FOR GB_QUANTITY
  7278. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7279. {
  7280. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7281. {
  7282. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7283. {
  7284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7285. goto end;
  7286. }
  7287. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7288. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7289. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7290. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7291. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7292. {
  7293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7294. goto end;
  7295. }
  7296. else
  7297. {
  7298. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7300. goto end;
  7301. }
  7302. }
  7303. }// END FOR GENERAL_GUN_QUANTITY
  7304. for (int index = 0; index < AC_QUANTITY; index++)
  7305. {
  7306. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7307. {
  7308. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7309. {
  7310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7311. goto end;
  7312. }
  7313. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7314. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7315. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7316. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7317. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7318. {
  7319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7320. goto end;
  7321. }
  7322. else
  7323. {
  7324. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7325. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7326. goto end;
  7327. }
  7328. }
  7329. }//END FOR AC_QUANTITY
  7330. }//END FOR AvailabilityTypeStr[Inoperative]
  7331. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7332. {
  7333. //----------------------gunIndex is 0 ------------------------------------------------//
  7334. if(gunIndex == 0)
  7335. {
  7336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7337. {
  7338. for(int i=0; i < gunTotalNumber; i++)
  7339. {
  7340. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7341. {
  7342. 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
  7343. {
  7344. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7345. goto end;
  7346. }
  7347. }//END FOR CHAdeMO_QUANTITY
  7348. for (int index = 0; index < CCS_QUANTITY; index++)
  7349. {
  7350. 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
  7351. {
  7352. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7353. goto end;
  7354. }
  7355. }//END FOR CCS_QUANTITY
  7356. for (int index = 0; index < GB_QUANTITY; index++)
  7357. {
  7358. 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
  7359. {
  7360. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7361. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7362. goto end;
  7363. }
  7364. }// END FOR GB_QUANTITY
  7365. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7366. {
  7367. 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
  7368. {
  7369. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7370. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7371. goto end;
  7372. }
  7373. }// END FOR GENERAL_GUN_QUANTITY
  7374. for (int index = 0; index < AC_QUANTITY; index++)
  7375. {
  7376. 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
  7377. {
  7378. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7379. goto end;
  7380. }
  7381. }//END FOR CHAdeMO_QUANTITY
  7382. }// END FOR gunTotalNumber
  7383. }
  7384. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7385. {
  7386. for(int i=0; i < gunTotalNumber; i++)
  7387. {
  7388. for (int index = 0; index < AC_QUANTITY; index++)
  7389. {
  7390. 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
  7391. {
  7392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7393. goto end;
  7394. }
  7395. }//END FOR CHAdeMO_QUANTITY
  7396. } // END FOR gunTotalNumber
  7397. }
  7398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7399. goto end;
  7400. }
  7401. //----------------------gunIndex is not 0 ------------------------------------------------//
  7402. //check Transaction active
  7403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7404. {
  7405. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7406. {
  7407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7408. goto end;
  7409. }
  7410. }//END FOR CHAdeMO_QUANTITY
  7411. for (int index = 0; index < CCS_QUANTITY; index++)
  7412. {
  7413. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7414. {
  7415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7416. goto end;
  7417. }
  7418. }//END FOR CCS_QUANTITY
  7419. for (int index = 0; index < GB_QUANTITY; index++)
  7420. {
  7421. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7422. {
  7423. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7424. goto end;
  7425. }
  7426. }// END FOR GB_QUANTITY
  7427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7428. {
  7429. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7430. {
  7431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7432. goto end;
  7433. }
  7434. }// END FOR GENERAL_GUN_QUANTITY
  7435. for (int index = 0; index < AC_QUANTITY; index++)
  7436. {
  7437. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7438. {
  7439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7440. goto end;
  7441. }
  7442. }//END FOR AC_QUANTITY
  7443. }//END FOR AvailabilityTypeStr[Operative]
  7444. end:
  7445. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7446. {
  7447. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7448. }
  7449. else
  7450. {
  7451. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7452. }
  7453. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7454. {
  7455. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7456. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7457. }
  7458. else if(gunIndex == 0)
  7459. {
  7460. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7461. {
  7462. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7463. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7464. }
  7465. }
  7466. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7467. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7468. return result;
  7469. }
  7470. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7471. {
  7472. mtrace();
  7473. int result = FAIL;
  7474. char keystr[40]={0};
  7475. char valuestr[256]={0};
  7476. char comfirmstr[20]={0};
  7477. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7478. json_object *ChangeConfiguration;
  7479. ChangeConfiguration = json_tokener_parse(payload);
  7480. if(!is_error(ChangeConfiguration))
  7481. {
  7482. // Required data
  7483. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7484. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7485. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7486. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7487. }
  7488. json_object_put(ChangeConfiguration);
  7489. if((uuid==NULL) || (payload ==NULL) )
  7490. {
  7491. DEBUG_ERROR("Payload is null\n");
  7492. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7493. }
  7494. else
  7495. {
  7496. int status = setKeyValue(keystr, valuestr);
  7497. switch(status)
  7498. {
  7499. case ConfigurationStatus_Accepted:
  7500. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7501. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7502. StoreConfigurationTable();
  7503. break;
  7504. case RebootRequired:
  7505. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7506. StoreConfigurationTable();
  7507. break;
  7508. case NotSupported:
  7509. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7510. break;
  7511. case ConfigurationStatus_Rejected:
  7512. default:
  7513. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7514. break;
  7515. }
  7516. }
  7517. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7518. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7519. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7520. {
  7521. ChageWebSocketPingInterval(atoi(valuestr));
  7522. }
  7523. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7524. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7525. {
  7526. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7527. SetOcppConnStatus(FALSE);
  7528. }
  7529. return result;
  7530. }
  7531. int handleClearCacheRequest(char *uuid, char *payload)
  7532. {
  7533. mtrace();
  7534. int result = FAIL;
  7535. char comfirmstr[20];
  7536. char rmFileCmd[100]={0};
  7537. struct stat stats;
  7538. DEBUG_INFO("handleClearCacheRequest...\n");
  7539. stat("/Storage/OCPP", &stats);
  7540. // Check for directory existence
  7541. if (S_ISDIR(stats.st_mode) == 1)
  7542. {}
  7543. else
  7544. {
  7545. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7546. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7547. system(rmFileCmd);
  7548. }
  7549. if(OCPP_cleanLocalCache())
  7550. {
  7551. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7552. }
  7553. else
  7554. {
  7555. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7556. }
  7557. sendClearCacheConfirmation(uuid, comfirmstr);
  7558. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7559. return result;
  7560. }
  7561. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7562. {
  7563. mtrace();
  7564. int result = FAIL;
  7565. int resultRename;
  7566. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7567. char chargingProfilePurposeStr[26]={0};
  7568. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7569. char tempchargingProfilePurposeStr[26]={0};
  7570. char str[100]={0};
  7571. char fname[200]={0};
  7572. char comfirmstr[20]={0};
  7573. char word[1600]={0};
  7574. int clearflag = FALSE;
  7575. int chargingProfileIdIsNULL = FALSE;
  7576. int connectorIsNULL = FALSE;
  7577. int chargingProfilePurposeIsNULL = FALSE;
  7578. int stackLevelIsNULL = FALSE;
  7579. //int GotoEnd = FALSE;
  7580. FILE *fptr1, *fptr2;
  7581. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7582. int n_chargingProfile=0;
  7583. int isEmptyFile = FALSE;
  7584. char sLineWord[1600]={0};
  7585. char chargingProfiles[10][100]={0};
  7586. int ChargeProfileCount = 0;
  7587. int ch;
  7588. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7589. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7590. json_object *ClearChargingProfile;
  7591. ClearChargingProfile = json_tokener_parse(payload);
  7592. if(!is_error(ClearChargingProfile))
  7593. {
  7594. // Optional data
  7595. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7596. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7597. else
  7598. chargingProfileIdIsNULL = TRUE;
  7599. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7600. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7601. else
  7602. connectorIsNULL = TRUE;
  7603. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7604. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7605. else
  7606. chargingProfilePurposeIsNULL = TRUE;
  7607. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7608. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7609. else
  7610. stackLevelIsNULL = TRUE;
  7611. }
  7612. json_object_put(ClearChargingProfile);
  7613. if(connectorIsNULL == FALSE)
  7614. {
  7615. switch(connectorIdInt)
  7616. {
  7617. case 0:
  7618. if(chargingProfilePurposeIsNULL == TRUE)
  7619. {
  7620. int l = 0;
  7621. strcpy(fname, ChargePointMaxProfile_JSON);
  7622. if((access(fname,F_OK))!=-1)
  7623. {
  7624. strcpy(chargingProfiles[l], fname);
  7625. l = l + 1;
  7626. }
  7627. strcpy(fname, TxDefaultProfile_0_JSON);
  7628. if((access(fname,F_OK))!=-1)
  7629. {
  7630. strcpy(chargingProfiles[l], fname);
  7631. l = l + 1;
  7632. }
  7633. ChargeProfileCount = l;
  7634. }
  7635. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7636. {
  7637. strcpy(fname, ChargePointMaxProfile_JSON);
  7638. if((access(fname,F_OK))!=-1)
  7639. {
  7640. strcpy(chargingProfiles[0], fname);
  7641. ChargeProfileCount = 1;
  7642. }
  7643. }
  7644. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7645. {
  7646. strcpy(fname, TxDefaultProfile_0_JSON);
  7647. if((access(fname,F_OK))!=-1)
  7648. {
  7649. strcpy(chargingProfiles[0], fname);
  7650. ChargeProfileCount = 1;
  7651. }
  7652. }
  7653. break;
  7654. default:
  7655. if(chargingProfilePurposeIsNULL == TRUE)
  7656. {
  7657. int m = 0;
  7658. memset(fname, 0, ARRAY_SIZE(fname));
  7659. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7660. if((access(fname,F_OK))!=-1)
  7661. {
  7662. strcpy(chargingProfiles[m], fname);
  7663. m = m + 1;
  7664. }
  7665. memset(fname, 0, ARRAY_SIZE(fname));
  7666. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7667. if((access(fname,F_OK))!=-1)
  7668. {
  7669. strcpy(chargingProfiles[m], fname);
  7670. m = m + 1;
  7671. }
  7672. ChargeProfileCount = m;
  7673. }
  7674. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7675. {
  7676. //strcpy(fname, TxDefaultProfile_1_JSON);
  7677. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7678. if((access(fname,F_OK))!=-1)
  7679. {
  7680. strcpy(chargingProfiles[0], fname);
  7681. ChargeProfileCount = 1;
  7682. }
  7683. }
  7684. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7685. {
  7686. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7687. if((access(fname,F_OK))!=-1)
  7688. {
  7689. strcpy(chargingProfiles[0], fname);
  7690. ChargeProfileCount = 1;
  7691. }
  7692. //strcpy(fname, TxProfile_1_JSON);
  7693. }
  7694. //strcpy(fname, ChargePointMaxProfile_JSON );
  7695. break;
  7696. }
  7697. }
  7698. else // Check all Charging Profiles
  7699. {
  7700. int i = 0;
  7701. char fnametemp[200]={0};
  7702. ChargeProfileCount = 0;
  7703. //Check ChargePointMaxProfile.json exit
  7704. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7705. {
  7706. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7707. i = i + 1;
  7708. }
  7709. //Check TxDefaultProfile_0.json exit
  7710. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7711. {
  7712. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7713. i = i + 1;
  7714. }
  7715. //Check TxDefaultProfile_%d.json
  7716. for(int j=1; j <= gunTotalNumber; j++)
  7717. {
  7718. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7719. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7720. if((access(fnametemp,F_OK))!=-1)
  7721. {
  7722. strcpy(chargingProfiles[i], fnametemp);
  7723. i = i + 1;
  7724. }
  7725. }
  7726. //Check TxProfile_%d.json
  7727. for(int j=1; j <= gunTotalNumber; j++)
  7728. {
  7729. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7730. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7731. if((access(fnametemp,F_OK))!=-1)
  7732. {
  7733. strcpy(chargingProfiles[i], fnametemp);
  7734. i = i + 1;
  7735. }
  7736. }
  7737. ChargeProfileCount = i;
  7738. }// End connectorIsNULL is TRUE
  7739. if(ChargeProfileCount == 0)
  7740. {
  7741. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7742. goto end;
  7743. }
  7744. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7745. {
  7746. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7747. goto end;
  7748. }
  7749. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7750. {
  7751. memset(str, 0, ARRAY_SIZE(str));
  7752. // clear temp file
  7753. sprintf(str,"rm -f %s",temp);
  7754. system(str);
  7755. for(int k=0; k < ChargeProfileCount; k++)
  7756. {
  7757. memset(str, 0, ARRAY_SIZE(str));
  7758. //clear file in C
  7759. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7760. system(str);
  7761. }
  7762. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7763. goto end;
  7764. }
  7765. else if(connectorIsNULL == TRUE)
  7766. {
  7767. for(int k=0; k < ChargeProfileCount; k++)
  7768. {
  7769. fptr1 = fopen(chargingProfiles[k], "r");
  7770. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7771. //Check Charging Profile Count
  7772. while(fscanf(fptr1, "%s", word) != EOF)
  7773. {
  7774. //DEBUG_INFO("word=%s\n",word);
  7775. if(strstr(word, "chargingProfileId")!= NULL)
  7776. {
  7777. //DEBUG_INFO("test chargingProfileId \n");
  7778. n_chargingProfile = n_chargingProfile + 1;
  7779. //DEBUG_INFO("chargingProfileId Found\n");
  7780. }
  7781. }
  7782. rewind(fptr1);
  7783. //search Charging Profile Element
  7784. //int i= 0;
  7785. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7786. {
  7787. json_object *tmpProfilee;
  7788. tmpProfilee = json_tokener_parse(sLineWord);
  7789. if(!is_error(tmpProfilee))
  7790. {
  7791. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7792. {
  7793. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7794. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7795. }
  7796. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7797. {
  7798. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7799. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7800. }
  7801. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7802. {
  7803. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7804. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7805. }
  7806. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7807. {
  7808. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7809. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7810. }
  7811. }
  7812. json_object_put(tmpProfilee);
  7813. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7814. {
  7815. //------- not write to fptr2-------//
  7816. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7817. //clearflag = TRUE;
  7818. }
  7819. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7820. {
  7821. //------- not write to fptr2-------//
  7822. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7823. }
  7824. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7825. {
  7826. //------- not write to fptr2-------//
  7827. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7828. }
  7829. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7830. {
  7831. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7832. }
  7833. else
  7834. {
  7835. fprintf(fptr2, sLineWord);//writing data into file
  7836. }
  7837. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7838. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7839. if(clearflag == TRUE)
  7840. {
  7841. fclose(fptr1);
  7842. fclose(fptr2);
  7843. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7844. system(str);
  7845. // clear temp file
  7846. sprintf(str,"rm -f %s",temp);
  7847. system(str);
  7848. }
  7849. else
  7850. {
  7851. fclose(fptr1);
  7852. fclose(fptr2);
  7853. memset(str, 0, ARRAY_SIZE(str));
  7854. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7855. system(str);
  7856. resultRename = rename(temp, chargingProfiles[k]);
  7857. if(resultRename == 0)
  7858. {
  7859. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7860. }
  7861. else
  7862. {
  7863. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7864. }
  7865. if(comfirmstr[0]== 0)
  7866. {
  7867. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7868. }
  7869. //Check chargingProfile is empty file
  7870. /*------ Read the file ----------------*/
  7871. fptr1=fopen(chargingProfiles[k],"r");
  7872. ch=fgetc(fptr1);
  7873. rewind(fptr1);
  7874. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7875. if(ch!=EOF)
  7876. {
  7877. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7878. {
  7879. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7880. if(sLineWord[0]=='\0')
  7881. {
  7882. isEmptyFile = TRUE;
  7883. break;
  7884. }
  7885. else
  7886. {
  7887. isEmptyFile = FALSE;
  7888. break;
  7889. }
  7890. }
  7891. }
  7892. else
  7893. isEmptyFile = TRUE;
  7894. fclose(fptr1);
  7895. if(isEmptyFile == TRUE)
  7896. {
  7897. memset(str, 0, ARRAY_SIZE(str));
  7898. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7899. system(str);
  7900. }
  7901. }
  7902. }// End of while(int k=0; k < ChargePointCount; k++)
  7903. }
  7904. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7905. {
  7906. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7907. for(int k=0; k < ChargeProfileCount; k++)
  7908. {
  7909. fptr1 = fopen(chargingProfiles[k], "r");
  7910. fptr2 = fopen(temp, "w+");
  7911. //Check Charging Profile Count
  7912. while(fscanf(fptr1, "%s", word) != EOF)
  7913. {
  7914. //DEBUG_INFO("word=%s\n",word);
  7915. if(strstr(word, "chargingProfileId")!= NULL)
  7916. {
  7917. n_chargingProfile = n_chargingProfile + 1;
  7918. }
  7919. }
  7920. rewind(fptr1);
  7921. //search Charging Profile Element
  7922. //int i= 0;
  7923. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7924. {
  7925. json_object *tmpProfilee;
  7926. tmpProfilee = json_tokener_parse(sLineWord);
  7927. if(!is_error(tmpProfilee))
  7928. {
  7929. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7930. {
  7931. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7932. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7933. }
  7934. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7935. {
  7936. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7937. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7938. }
  7939. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7940. {
  7941. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7942. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7943. }
  7944. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7945. {
  7946. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7947. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7948. }
  7949. }
  7950. json_object_put(tmpProfilee);
  7951. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7952. {
  7953. //------- not write to fptr2-------//
  7954. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7955. //clearflag = TRUE;
  7956. }
  7957. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7958. {
  7959. //------- not write to fptr2-------//
  7960. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7961. }
  7962. else if(stackLevelIsNULL == TRUE)
  7963. {
  7964. //Clear Whole File
  7965. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7966. clearflag = TRUE;
  7967. break;
  7968. }
  7969. else
  7970. {
  7971. fprintf(fptr2, sLineWord);//writing data into file
  7972. }
  7973. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7974. }
  7975. if(clearflag == TRUE)
  7976. {
  7977. fclose(fptr1);
  7978. fclose(fptr2);
  7979. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7980. system(str);
  7981. // clear temp file
  7982. sprintf(str,"rm -f %s",temp);
  7983. system(str);
  7984. }
  7985. else
  7986. {
  7987. fclose(fptr1);
  7988. fclose(fptr2);
  7989. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7990. system(str);
  7991. resultRename = rename(temp, chargingProfiles[k]);
  7992. if(resultRename == 0)
  7993. {
  7994. DEBUG_INFO("File ChargingProfile renamed successfully");
  7995. }
  7996. else
  7997. {
  7998. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7999. }
  8000. if(comfirmstr[0]== 0)
  8001. {
  8002. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8003. }
  8004. //Check chargingProfile is empty file
  8005. /*------ Read the file ----------------*/
  8006. fptr1=fopen(chargingProfiles[k],"r");
  8007. ch=fgetc(fptr1);
  8008. rewind(fptr1);
  8009. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8010. if(ch!=EOF)
  8011. {
  8012. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8013. {
  8014. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8015. if(sLineWord[0]=='\0')
  8016. {
  8017. isEmptyFile = TRUE;
  8018. break;
  8019. }
  8020. else
  8021. {
  8022. isEmptyFile = FALSE;
  8023. break;
  8024. }
  8025. }
  8026. }
  8027. else
  8028. isEmptyFile = TRUE;
  8029. fclose(fptr1);
  8030. if(isEmptyFile == TRUE)
  8031. {
  8032. memset(str, 0, ARRAY_SIZE(str));
  8033. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8034. system(str);
  8035. }
  8036. /*------- End of reading ---------------*/
  8037. }
  8038. } // while(int k=0; k < ChargeProfileCount; k++)
  8039. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8040. end:
  8041. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8042. {
  8043. if(connectorIdInt == 0)
  8044. {
  8045. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8046. {
  8047. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8048. }
  8049. }
  8050. else
  8051. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8052. }
  8053. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8054. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8055. return result;
  8056. }
  8057. void createFirmwareVersionByDataTransfer(void)
  8058. {
  8059. json_object *FirmwareDataTransfer = json_object_new_object();
  8060. // AC & DC model
  8061. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8062. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8063. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8064. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8065. // DC model
  8066. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8067. {
  8068. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8069. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8070. (gunType[3] != GUN_TYPE_UNKNOWN))
  8071. {
  8072. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8073. }
  8074. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8075. {
  8076. // DS DM DW
  8077. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8078. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8079. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8080. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8081. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8082. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8083. }
  8084. else
  8085. {
  8086. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8087. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8088. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8089. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8090. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8091. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8092. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8093. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8094. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8095. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8096. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8097. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8098. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8099. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8100. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8101. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8102. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8103. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8104. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8105. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8106. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8107. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8108. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8109. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8110. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8111. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8112. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8113. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8114. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8115. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8116. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8117. }
  8118. }
  8119. // 4G model
  8120. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8121. {
  8122. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8123. }
  8124. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8125. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8126. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8127. json_object_put(FirmwareDataTransfer);
  8128. }
  8129. int handleDataTransferRequest(char *uuid, char *payload)
  8130. {
  8131. mtrace();
  8132. json_object *response = json_object_new_object();
  8133. int result = FAIL;
  8134. char tempvendorId[255]={0};
  8135. char tempmessageId[50]={0};
  8136. char tempdata[512]={0};
  8137. char message[2048]={0};
  8138. DEBUG_INFO("handleDataTransferRequest...\n");
  8139. if((uuid != NULL) && (payload != NULL))
  8140. {
  8141. json_object *DataTransfer;
  8142. DataTransfer = json_tokener_parse(payload);
  8143. if(!is_error(DataTransfer))
  8144. {
  8145. // Required data
  8146. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8147. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8148. // Optional data
  8149. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8150. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8151. if(json_object_object_get(DataTransfer, "data") != NULL)
  8152. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8153. result = PASS;
  8154. }
  8155. json_object_put(DataTransfer);
  8156. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8157. {
  8158. // Send all moudle firmware version on EVSE
  8159. createFirmwareVersionByDataTransfer();
  8160. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8161. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8162. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8163. json_object_put(response);
  8164. }
  8165. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8166. {
  8167. system("/usr/bin/run_tmate_restart.sh &");
  8168. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8169. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8170. json_object_put(response);
  8171. }
  8172. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8173. {
  8174. json_object *data;
  8175. data = json_tokener_parse(tempdata);
  8176. if(!is_error(data))
  8177. {
  8178. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8179. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8180. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8181. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8182. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8183. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8184. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8185. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8186. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8187. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8188. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8189. }
  8190. else
  8191. {
  8192. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8193. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8194. }
  8195. json_object_put(data);
  8196. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8197. json_object_put(response);
  8198. }
  8199. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8200. {
  8201. json_object *data;
  8202. data = json_tokener_parse(tempdata);
  8203. if(!is_error(data))
  8204. {
  8205. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8206. if(json_object_object_get(data, "idToken") != NULL)
  8207. {
  8208. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8209. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8210. }
  8211. if(json_object_object_get(data, "price") != NULL)
  8212. {
  8213. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8214. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8215. }
  8216. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8217. }
  8218. else
  8219. {
  8220. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8221. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8222. }
  8223. json_object_put(data);
  8224. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8225. json_object_put(response);
  8226. }
  8227. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8228. {
  8229. json_object *data;
  8230. data = json_tokener_parse(tempdata);
  8231. if(!is_error(data))
  8232. {
  8233. if(json_object_object_get(data, "txId") != NULL)
  8234. {
  8235. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8236. for(int idx = 0;idx<gunTotalNumber;idx++)
  8237. {
  8238. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8239. {
  8240. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8241. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8242. if(json_object_object_get(data, "description") != NULL)
  8243. {
  8244. // California pricing V1.0
  8245. DEBUG_INFO("California pricing V1.0\n");
  8246. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8247. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8248. }
  8249. else
  8250. {
  8251. // California pricing V1.1
  8252. DEBUG_INFO("California pricing V1.1\n");
  8253. if(json_object_object_get(data, "timestamp") != NULL)
  8254. {
  8255. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8256. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8257. }
  8258. if(json_object_object_get(data, "meterValue") != NULL)
  8259. {
  8260. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8261. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8262. }
  8263. if(json_object_object_get(data, "cost") != NULL)
  8264. {
  8265. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8266. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8267. }
  8268. if(json_object_object_get(data, "state") != NULL)
  8269. {
  8270. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8271. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8272. }
  8273. if(json_object_object_get(data, "chargingPrice") != NULL)
  8274. {
  8275. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8276. {
  8277. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8278. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8279. }
  8280. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8281. {
  8282. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8283. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8284. }
  8285. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8286. {
  8287. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8288. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8289. }
  8290. }
  8291. if(json_object_object_get(data, "idlePrice") != NULL)
  8292. {
  8293. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8294. {
  8295. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8296. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8297. }
  8298. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8299. {
  8300. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8301. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8302. }
  8303. }
  8304. if(json_object_object_get(data, "nextPeriod") != NULL)
  8305. {
  8306. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8307. {
  8308. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8309. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8310. }
  8311. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8312. {
  8313. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8314. {
  8315. 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")));
  8316. 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"));
  8317. }
  8318. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8319. {
  8320. 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")));
  8321. 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"));
  8322. }
  8323. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8324. {
  8325. 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")));
  8326. 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"));
  8327. }
  8328. }
  8329. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8330. {
  8331. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8332. {
  8333. 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")));
  8334. 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"));
  8335. }
  8336. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8337. {
  8338. 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")));
  8339. 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"));
  8340. }
  8341. }
  8342. }
  8343. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8344. {
  8345. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8346. {
  8347. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8348. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8349. }
  8350. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8351. {
  8352. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8353. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8354. }
  8355. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8356. {
  8357. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8358. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8359. }
  8360. }
  8361. }
  8362. }
  8363. }
  8364. }
  8365. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8366. }
  8367. else
  8368. {
  8369. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8370. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8371. }
  8372. json_object_put(data);
  8373. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8374. json_object_put(response);
  8375. }
  8376. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8377. {
  8378. json_object *data;
  8379. data = json_tokener_parse(tempdata);
  8380. if(!is_error(data))
  8381. {
  8382. if(json_object_object_get(data, "txId") != NULL)
  8383. {
  8384. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8385. for(int idx = 0;idx<gunTotalNumber;idx++)
  8386. {
  8387. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8388. {
  8389. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8390. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8391. if(json_object_object_get(data, "description") != NULL)
  8392. {
  8393. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8394. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8395. }
  8396. }
  8397. }
  8398. }
  8399. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8400. }
  8401. else
  8402. {
  8403. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8404. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8405. }
  8406. json_object_put(data);
  8407. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8408. json_object_put(response);
  8409. }
  8410. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8411. {
  8412. json_object *data;
  8413. data = json_tokener_parse(tempdata);
  8414. if(!is_error(data))
  8415. {
  8416. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8417. if(json_object_object_get(data, "Content_Type") != NULL)
  8418. {
  8419. 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))
  8420. {
  8421. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8422. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8423. {
  8424. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8425. }
  8426. }
  8427. else
  8428. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8429. }
  8430. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8431. }
  8432. else
  8433. {
  8434. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8435. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8436. }
  8437. json_object_put(data);
  8438. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8439. json_object_put(response);
  8440. }
  8441. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8442. {
  8443. json_object *data;
  8444. data = json_tokener_parse(tempdata);
  8445. if(!is_error(data))
  8446. {
  8447. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8448. if(json_object_object_get(data, "Page_Index") != NULL)
  8449. {
  8450. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8451. }
  8452. if(json_object_object_get(data, "Duration") != NULL)
  8453. {
  8454. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8455. }
  8456. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8457. }
  8458. else
  8459. {
  8460. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8461. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8462. }
  8463. json_object_put(data);
  8464. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8465. json_object_put(response);
  8466. }
  8467. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8468. {
  8469. json_object *data;
  8470. data = json_tokener_parse(tempdata);
  8471. if(!is_error(data))
  8472. {
  8473. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8474. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8475. {
  8476. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8477. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8478. else
  8479. {
  8480. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8481. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8482. }
  8483. }
  8484. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8485. {
  8486. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8487. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8488. else
  8489. {
  8490. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8491. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8492. }
  8493. }
  8494. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8495. {
  8496. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8497. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8498. else
  8499. {
  8500. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8501. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8502. }
  8503. }
  8504. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8505. {
  8506. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8507. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8508. else
  8509. {
  8510. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8511. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8512. }
  8513. }
  8514. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8515. {
  8516. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8517. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8518. else
  8519. {
  8520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8521. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8522. }
  8523. }
  8524. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8525. {
  8526. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8527. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8528. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8529. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8530. else
  8531. {
  8532. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8533. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8534. }
  8535. }
  8536. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8537. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  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
  8549. {
  8550. // Can not find valid message id
  8551. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8552. }
  8553. }
  8554. else
  8555. {
  8556. // Payload is null
  8557. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8558. }
  8559. LWS_Send(message);
  8560. return result;
  8561. }
  8562. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8563. {
  8564. mtrace();
  8565. int result = FAIL;
  8566. int connectorIdInt, durationInt;
  8567. char chargingRateUnitStr[4]={0};
  8568. char comfirmstr[20];
  8569. int confirmPeriods = 0;
  8570. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8571. json_object *GetCompositeSchedule;
  8572. GetCompositeSchedule = json_tokener_parse(payload);
  8573. if(!is_error(GetCompositeSchedule))
  8574. {
  8575. // Required data
  8576. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8577. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8578. else
  8579. connectorIdInt = -1;
  8580. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8581. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8582. else
  8583. durationInt = 86400;
  8584. // Optional data
  8585. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8586. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8587. }
  8588. json_object_put(GetCompositeSchedule);
  8589. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8590. if((connectorIdInt == 0) ||
  8591. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8592. {
  8593. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8594. struct StructChargingProfile tmpProfile[1];
  8595. if(strstr(chargingRateUnitStr, "W") != NULL)
  8596. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8597. else
  8598. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8599. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8600. {
  8601. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8602. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8603. }
  8604. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8605. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8606. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8607. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8608. {
  8609. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8610. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8611. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8612. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8613. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8614. {
  8615. confirmPeriods = idx;
  8616. break;
  8617. }
  8618. }
  8619. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8620. {
  8621. confirmPeriods += 1;
  8622. }
  8623. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8624. }
  8625. else
  8626. {
  8627. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8628. }
  8629. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8630. return result;
  8631. }
  8632. int handleGetConfigurationRequest(char *uuid, char *payload)
  8633. {
  8634. mtrace();
  8635. int result = FAIL;
  8636. int MaxKeySupported = 0;
  8637. int n_keys = 0;
  8638. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8639. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8640. json_object *GetConfiguration;
  8641. GetConfiguration = json_tokener_parse(payload);
  8642. if(!is_error(GetConfiguration))
  8643. {
  8644. // Optional data
  8645. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8646. {
  8647. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8648. {
  8649. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8650. n_keys = idx + 1;
  8651. }
  8652. }
  8653. }
  8654. json_object_put(GetConfiguration);
  8655. UnknownKeynum = 0;
  8656. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8657. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8658. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8659. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8660. if(n_keys != 0)
  8661. {
  8662. for(int i=0;i<n_keys;i++)
  8663. {
  8664. getKeyValue(requestKey[i]);
  8665. }
  8666. }
  8667. else
  8668. {
  8669. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8670. getKeyValue("");
  8671. }
  8672. processUnkownKey();
  8673. sendGetConfigurationConfirmation(uuid);
  8674. return result;
  8675. }
  8676. static char fnamePlusPath[100]={0};
  8677. static char fnamePWithNoPath[60]={0};
  8678. void checkUploadLog(void)
  8679. {
  8680. FILE *fp;
  8681. /* Open the command for reading. */
  8682. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8683. if (fp == NULL) {
  8684. DEBUG_WARN("Failed to run command\n" );
  8685. exit(1);
  8686. }
  8687. int ftppathlen = 0;
  8688. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8689. int i = 0;
  8690. /* Read the output a line at a time - output it. */
  8691. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8692. if(i==0)
  8693. {
  8694. ftppathlen = strlen(fnamePlusPath);
  8695. DEBUG_INFO("%s\n", fnamePlusPath);
  8696. fnamePlusPath[ftppathlen]='\0';
  8697. break;
  8698. }
  8699. i= i+1;
  8700. }
  8701. /* close */
  8702. pclose(fp);
  8703. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8704. {
  8705. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8706. {
  8707. fnamePlusPath[k]='\0';
  8708. }
  8709. }
  8710. i=1;
  8711. //char fname[60]={0};
  8712. while(i < ftppathlen)
  8713. {
  8714. int len=ftppathlen-i;
  8715. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8716. {
  8717. DEBUG_INFO("compare '/' all right\n");
  8718. break;
  8719. }
  8720. i=i+1;
  8721. }
  8722. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8723. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8724. fnamePWithNoPath[i+1] = '\0';
  8725. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8726. {
  8727. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8728. {
  8729. fnamePWithNoPath[j]='\0';
  8730. }
  8731. }
  8732. FILE* fp1 = fopen(fnamePlusPath, "r");
  8733. if (fp1)
  8734. {
  8735. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8736. // file exists
  8737. fclose(fp1);
  8738. }
  8739. else
  8740. {
  8741. // file doesn't exist
  8742. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8743. }
  8744. }
  8745. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8746. {
  8747. mtrace();
  8748. int result = FAIL;
  8749. time_t CurrentTime;
  8750. struct tm *tm;
  8751. pthread_t th_Status;
  8752. CurrentTime = time(NULL);
  8753. tm = localtime(&CurrentTime);
  8754. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  8755. 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);
  8756. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8757. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8758. return result;
  8759. }
  8760. void* GetDiagnosticsProcess(void* data)
  8761. {
  8762. pthread_detach(pthread_self());
  8763. mtrace();
  8764. int retriesInt=0, retryIntervalInt=0;
  8765. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8766. 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};
  8767. int port=0;
  8768. int isSuccess = FALSE;
  8769. char cmdBuf[2048];
  8770. struct tm *tmNow;
  8771. time_t CurrentTime;
  8772. struct tm tmStart;
  8773. struct tm tmStop;
  8774. CurrentTime = time(NULL);
  8775. tmNow=localtime(&CurrentTime);
  8776. uint16_t targetYear, targetMonth;
  8777. json_object *GetDiagnostics;
  8778. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8779. GetDiagnostics = json_tokener_parse(data);
  8780. if(!is_error(GetDiagnostics))
  8781. {
  8782. // Required data
  8783. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8784. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8785. // Optional data
  8786. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8787. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8788. else
  8789. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8790. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8791. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8792. else
  8793. retryIntervalInt = 30;
  8794. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8795. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8796. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8797. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8798. }
  8799. json_object_put(GetDiagnostics);
  8800. // Pack log to compress file
  8801. 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) &&
  8802. (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))
  8803. {
  8804. // Pack system log
  8805. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8806. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8807. targetYear = tmStart.tm_year;
  8808. targetMonth = tmStart.tm_mon;
  8809. do
  8810. {
  8811. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8812. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8813. if(targetMonth+1>=13)
  8814. {
  8815. targetYear += 1;
  8816. targetMonth = 1;
  8817. }
  8818. else
  8819. {
  8820. targetMonth += 1;
  8821. }
  8822. }while((targetYear < (tmNow->tm_year+1900)) ||
  8823. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8824. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8825. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8826. system(cmdBuf);
  8827. // Pack charging & event log
  8828. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8829. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8830. targetYear = tmStart.tm_year;
  8831. targetMonth = tmStart.tm_mon;
  8832. do
  8833. {
  8834. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8835. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8836. if(targetMonth+1>=13)
  8837. {
  8838. targetYear += 1;
  8839. targetMonth = 1;
  8840. }
  8841. else
  8842. {
  8843. targetMonth += 1;
  8844. }
  8845. }while((targetYear < (tmNow->tm_year+1900)) ||
  8846. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8847. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8848. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8849. system(cmdBuf);
  8850. // Combine log file
  8851. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8852. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8853. }
  8854. else
  8855. {
  8856. system("exec /root/logPackTools 'log' 6");
  8857. }
  8858. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8859. system(cmdBuf);
  8860. checkUploadLog();
  8861. //****************location*******************/
  8862. if(strcmp(locationstr,"")==0)
  8863. {
  8864. DEBUG_INFO("location is <Empty>!\n");
  8865. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8866. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8867. goto end;
  8868. }
  8869. memset(protocol, 0, ARRAY_SIZE(protocol));
  8870. memset(user, 0, ARRAY_SIZE(user) );
  8871. memset(password, 0, ARRAY_SIZE(password));
  8872. memset(host, 0, ARRAY_SIZE(host));
  8873. memset(path, 0, ARRAY_SIZE(path));
  8874. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8875. memset(host1, 0, ARRAY_SIZE(host1));
  8876. memset(path1, 0, ARRAY_SIZE(path1));
  8877. /*location: ftp://user:password@host:port/path*/
  8878. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8879. if((access(fnamePlusPath,F_OK))!=-1)
  8880. {
  8881. DEBUG_INFO("fnamePlusPath exist.\n");
  8882. }
  8883. else
  8884. {
  8885. DEBUG_INFO("fnamePlusPath not exist!\n");
  8886. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8887. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8888. goto end;
  8889. }
  8890. if(strchr(locationstr,'@')==NULL)
  8891. {
  8892. sscanf(locationstr,
  8893. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8894. protocol, host, &port, path);
  8895. strcpy(user,"anonymous");
  8896. strcpy(password,"");
  8897. }
  8898. else
  8899. {
  8900. //DEBUG_INFO("pch=%s\n", pch);
  8901. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8902. protocol, user, password, host, &port, path);
  8903. }
  8904. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8905. {
  8906. DEBUG_INFO("protocol is not ftp/http ! \n");
  8907. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8908. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8909. goto end;
  8910. }
  8911. if(strncmp(locationstr,"http", 4) == 0)
  8912. {
  8913. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8914. sprintf(ftppath,"/%s", path);
  8915. do
  8916. {
  8917. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8918. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8919. sleep(3);
  8920. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8921. if(!isSuccess)
  8922. {
  8923. DEBUG_INFO("Diagnostics fail.\n");
  8924. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8925. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8926. sleep(retryIntervalInt);
  8927. }
  8928. else
  8929. {
  8930. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8931. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8932. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8933. }
  8934. retriesInt--;
  8935. }while((isSuccess == 0)&&(retriesInt >= 0));
  8936. }
  8937. else
  8938. {
  8939. sscanf(host,"%[^/]%s",host1, path1);
  8940. if(strlen(path) > 0)
  8941. sprintf(ftppath,"/%s", path);
  8942. else
  8943. sprintf(ftppath,"/%s", path1);
  8944. int ftppathlen=strlen(ftppath);
  8945. int i=1;
  8946. char filenametemp[50];
  8947. while(i < ftppathlen)
  8948. {
  8949. int len=ftppathlen-i;
  8950. if(ftppath[len]== 47) // '/' ascll code: 47
  8951. {
  8952. DEBUG_INFO("find '/' all right\n");
  8953. break;
  8954. }
  8955. i=i+1;
  8956. }
  8957. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8958. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8959. filenametemp[i+1] = 0;
  8960. if(port == 0)
  8961. port = 21;
  8962. do
  8963. {
  8964. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8965. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8966. sleep(3);
  8967. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8968. if(!isSuccess)
  8969. {
  8970. DEBUG_INFO("Diagnostics fail.\n");
  8971. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8972. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8973. sleep(retryIntervalInt);
  8974. }
  8975. else
  8976. {
  8977. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8978. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8979. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8980. }
  8981. retriesInt--;
  8982. }while((!isSuccess)&&(retriesInt >= 0));
  8983. }
  8984. end:
  8985. system("rm -f /mnt/*");
  8986. sleep(5);
  8987. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8988. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8989. pthread_exit(NULL);
  8990. }
  8991. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8992. {
  8993. mtrace();
  8994. int result = FAIL;
  8995. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8996. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8997. {
  8998. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8999. locallistVersion = -1;
  9000. }
  9001. else
  9002. {
  9003. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9004. OCPP_getListVerion();
  9005. }
  9006. //from db.OCPP_getListVerion
  9007. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9008. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9009. sendGetLocalListVersionConfirmation(uuid,"");
  9010. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9011. return result;
  9012. }
  9013. int handleRemoteStartRequest(char *uuid, char *payload)
  9014. {
  9015. mtrace();
  9016. int result = FAIL;
  9017. int connectorIdInt=-1;
  9018. int tempIndex = 0;
  9019. int connectorIdIsNULL, chargingProfileIsNULL;
  9020. char comfirmstr[20]={0};
  9021. char cmdBuf[512];
  9022. json_object *RemoteStartTransaction;
  9023. FILE *fp;
  9024. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9025. if(server_pending == TRUE)
  9026. {
  9027. return 0;
  9028. }
  9029. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9030. RemoteStartTransaction = json_tokener_parse(payload);
  9031. if(!is_error(RemoteStartTransaction))
  9032. {
  9033. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9034. {
  9035. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9036. }
  9037. else
  9038. {
  9039. connectorIdIsNULL = TRUE;
  9040. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9041. {
  9042. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9043. {
  9044. connectorIdIsNULL = FALSE;
  9045. connectorIdInt = (gun_index+1);
  9046. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9047. break;
  9048. }
  9049. }
  9050. }
  9051. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt != -1))
  9052. {
  9053. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9054. // Required data
  9055. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9056. // Optional data
  9057. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9058. {
  9059. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9060. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9061. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9062. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9063. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9064. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9065. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9066. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9067. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9068. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9069. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9070. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9071. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9072. {
  9073. 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")));
  9074. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9075. 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"));
  9076. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9077. 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"));
  9078. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9079. 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")));
  9080. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9081. {
  9082. 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++)
  9083. {
  9084. 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"));
  9085. 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"));
  9086. 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)
  9087. 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"));
  9088. }
  9089. }
  9090. }
  9091. }
  9092. else
  9093. {
  9094. chargingProfileIsNULL = TRUE;
  9095. }
  9096. }
  9097. }
  9098. else
  9099. {
  9100. connectorIdIsNULL = TRUE;
  9101. }
  9102. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9103. {
  9104. DEBUG_WARN("Connector id is NULL\n.");
  9105. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9106. goto end;
  9107. }
  9108. /*
  9109. enum _SYSTEM_STATUS
  9110. {
  9111. S_BOOTING = 0,
  9112. S_IDLE, = 1
  9113. S_AUTHORIZING, = 2
  9114. S_REASSIGN_CHECK, = 3
  9115. S_REASSIGN, = 4
  9116. S_PRECHARGE, = 5
  9117. S_PREPARING_FOR_EV, = 6
  9118. S_PREPARING_FOR_EVSE, = 7
  9119. S_CHARGING, = 8
  9120. S_TERMINATING, = 9
  9121. S_COMPLETE, = 10
  9122. S_ALARM, = 11
  9123. S_FAULT = 12
  9124. }
  9125. */
  9126. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9127. {
  9128. //check Transaction active
  9129. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9130. {
  9131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9132. {
  9133. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9134. }
  9135. else
  9136. {
  9137. tempIndex = connectorIdInt -1;
  9138. }
  9139. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9140. {
  9141. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9142. {
  9143. 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))
  9144. {
  9145. //Reserved
  9146. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9147. }
  9148. 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))
  9149. {
  9150. //Reserved
  9151. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9153. goto end;
  9154. }
  9155. else
  9156. {
  9157. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9158. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9159. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9160. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9161. {
  9162. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9163. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9164. goto end;
  9165. }
  9166. }//END FOR ELSE
  9167. }
  9168. }// END FOR CHAdeMO_QUANTITY
  9169. }
  9170. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9171. {
  9172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9173. {
  9174. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9175. }
  9176. else
  9177. {
  9178. tempIndex = connectorIdInt -1;
  9179. }
  9180. for (int index = 0; index < CCS_QUANTITY; index++)
  9181. {
  9182. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9183. {
  9184. 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))
  9185. {
  9186. //Reserved
  9187. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9188. }
  9189. 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))
  9190. {
  9191. //Reserved
  9192. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9193. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9194. goto end;
  9195. }
  9196. else
  9197. {
  9198. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9199. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9200. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9201. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9202. {
  9203. DEBUG_WARN("CCS connector not allow start\n.");
  9204. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9205. goto end;
  9206. }
  9207. }// END FOR ELSE
  9208. }
  9209. }// END FOR CCS_QUANTITY
  9210. }
  9211. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9212. {
  9213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9214. {
  9215. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9216. }
  9217. else
  9218. {
  9219. tempIndex = connectorIdInt -1;
  9220. }
  9221. for (int index = 0; index < GB_QUANTITY; index++)
  9222. {
  9223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9224. {
  9225. 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))
  9226. {
  9227. //Reserved
  9228. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9229. }
  9230. 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))
  9231. {
  9232. //Reserved
  9233. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9234. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9235. goto end;
  9236. }
  9237. else
  9238. {
  9239. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9240. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9241. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9242. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9243. {
  9244. DEBUG_WARN("GB connector not allow start\n.");
  9245. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9246. goto end;
  9247. }
  9248. }// END FOR ELSE
  9249. }
  9250. } // END FOR GB_QUANTITY
  9251. }
  9252. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9253. {
  9254. tempIndex = connectorIdInt -1;
  9255. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9256. {
  9257. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9258. {
  9259. 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))
  9260. {
  9261. //Reserved
  9262. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9263. }
  9264. 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))
  9265. {
  9266. //Reserved
  9267. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9268. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9269. goto end;
  9270. }
  9271. else
  9272. {
  9273. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9274. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9275. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9276. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9277. {
  9278. DEBUG_WARN("GB connector not allow start\n.");
  9279. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9280. goto end;
  9281. }
  9282. }// END FOR ELSE
  9283. }
  9284. } // END FOR GB_QUANTITY
  9285. }
  9286. else
  9287. {
  9288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9289. {
  9290. tempIndex = 2;
  9291. }
  9292. else
  9293. {
  9294. tempIndex = connectorIdInt -1;
  9295. }
  9296. for (int index = 0; index < AC_QUANTITY; index++)
  9297. {
  9298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9299. {
  9300. 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))
  9301. {
  9302. //Reserved
  9303. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9304. }
  9305. 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))
  9306. {
  9307. //Reserved
  9308. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9309. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9310. goto end;
  9311. }
  9312. else
  9313. {
  9314. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9315. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9316. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9317. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9318. {
  9319. DEBUG_WARN("AC connector not allow start\n.");
  9320. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9321. goto end;
  9322. }
  9323. }//END FOR ELSE
  9324. }
  9325. }// END FOR AC_QUANTITY
  9326. }
  9327. if(chargingProfileIsNULL == FALSE)
  9328. {
  9329. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9330. {
  9331. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9332. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9333. //memset idTag
  9334. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9335. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9336. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9337. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9338. // Save profile to file
  9339. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9340. system(cmdBuf);
  9341. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9342. fp = fopen(cmdBuf, "w");
  9343. 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));
  9344. fclose(fp);
  9345. }
  9346. else
  9347. {
  9348. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9349. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9350. }
  9351. }
  9352. else
  9353. {
  9354. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9355. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9356. //memset idTag
  9357. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9358. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9359. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9360. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9361. }
  9362. }
  9363. else
  9364. {
  9365. DEBUG_WARN("Connector id over\n.");
  9366. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9367. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9368. }
  9369. end:
  9370. json_object_put(RemoteStartTransaction);
  9371. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9372. {
  9373. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9374. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9375. }
  9376. //OCPP send RemoteStartConfirmation by first.
  9377. sendRemoteStartConfirmation(uuid, comfirmstr);
  9378. return result;
  9379. }
  9380. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9381. {
  9382. mtrace();
  9383. int result = FAIL;
  9384. int match = FALSE;
  9385. int GunNO = 0;
  9386. int tempIndex = 0;
  9387. int transactionIdInt=0;
  9388. int transactionIdIsNULL= TRUE;
  9389. char comfirmstr[20];
  9390. json_object *RemoteStopTransaction;
  9391. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9392. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9393. if(server_pending == TRUE)
  9394. {
  9395. return 0;
  9396. }
  9397. RemoteStopTransaction = json_tokener_parse(payload);
  9398. if(!is_error(RemoteStopTransaction))
  9399. {
  9400. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9401. {
  9402. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9403. transactionIdIsNULL = FALSE;
  9404. }
  9405. }
  9406. json_object_put(RemoteStopTransaction);
  9407. if(transactionIdIsNULL == FALSE)
  9408. {
  9409. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9410. {
  9411. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9412. {
  9413. //check Transaction active
  9414. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9415. {
  9416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9417. {
  9418. tempIndex = ((gun_index==2) ? 1: 0);
  9419. }
  9420. else
  9421. {
  9422. tempIndex = gun_index;
  9423. }
  9424. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9425. {
  9426. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9427. {
  9428. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9429. {
  9430. match = TRUE;
  9431. GunNO = gun_index;
  9432. }
  9433. }
  9434. }// END FOR CHAdeMO_QUANTITY
  9435. }
  9436. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9437. {
  9438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9439. {
  9440. tempIndex = ((gun_index==2) ? 1: 0);
  9441. }
  9442. else
  9443. {
  9444. tempIndex = gun_index;
  9445. }
  9446. for (int index = 0; index < CCS_QUANTITY; index++)
  9447. {
  9448. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9449. {
  9450. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9451. {
  9452. match = TRUE;
  9453. GunNO = gun_index;
  9454. }
  9455. }
  9456. }// END FOR CCS_QUANTITY
  9457. }
  9458. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9459. {
  9460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9461. {
  9462. tempIndex = ((gun_index==2) ? 1: 0);
  9463. }
  9464. else
  9465. {
  9466. tempIndex = gun_index;
  9467. }
  9468. for (int index = 0; index < GB_QUANTITY; index++)
  9469. {
  9470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9471. {
  9472. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9473. {
  9474. match = TRUE;
  9475. GunNO = gun_index;
  9476. }
  9477. }
  9478. }// END FOR GB_QUANTITY
  9479. }
  9480. else if(gunType[gun_index] == GUN_TYPE_DO)
  9481. {
  9482. tempIndex = gun_index;
  9483. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9484. {
  9485. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9486. {
  9487. 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
  9488. {
  9489. match = TRUE;
  9490. GunNO = gun_index;
  9491. }
  9492. }
  9493. }// END FOR GB_QUANTITY
  9494. }
  9495. else
  9496. {
  9497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9498. {
  9499. tempIndex = 2;
  9500. }
  9501. else
  9502. {
  9503. tempIndex = gun_index;
  9504. }
  9505. for (int index = 0; index < AC_QUANTITY; index++)
  9506. {
  9507. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9508. {
  9509. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[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. } // END FOR AC ELSE
  9517. }// CHECK IF ResponseTransactionId == transactionIdInt
  9518. }//END FOR
  9519. if( match == TRUE)
  9520. {
  9521. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9522. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9523. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9524. }
  9525. else
  9526. {
  9527. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9528. }
  9529. }
  9530. else
  9531. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9532. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9533. return result;
  9534. }
  9535. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9536. {
  9537. mtrace();
  9538. int result = FAIL;
  9539. int connectorIdInt=0, reservationIdInt=0;
  9540. int tempIndex = 0;
  9541. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9542. char comfirmstr[20]={0};
  9543. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9544. int c = 0;
  9545. char *loc;
  9546. //char *ptr;
  9547. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9548. strcpy(sstrtemp, stringtrimspace(payload));
  9549. //***(1)connectorId ****/
  9550. c=0;
  9551. loc = strstr(sstrtemp, "connectorId");
  9552. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9553. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9554. {
  9555. sstr[c] = loc[strlen("connectorId")+2+c];
  9556. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9557. c++;
  9558. }
  9559. sstr[c] = '\0';
  9560. connectorIdInt = atoi(sstr);
  9561. //***(2)expiryDate ****/
  9562. loc = strstr(sstrtemp, "expiryDate");
  9563. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9564. c = 0;
  9565. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9566. {
  9567. sstr[c] = loc[3+strlen("expiryDate")+c];
  9568. c++;
  9569. }
  9570. sstr[c] = '\0';
  9571. strcpy(expiryDatestr, sstr);
  9572. //***(3)idTag ****/
  9573. loc = strstr(sstrtemp, "idTag");
  9574. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9575. c = 0;
  9576. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9577. {
  9578. sstr[c] = loc[3+strlen("idTag")+c];
  9579. c++;
  9580. }
  9581. sstr[c] = '\0';
  9582. strcpy(idTagstr, sstr);
  9583. //***(4)parentIdTag ****/
  9584. loc = strstr(sstrtemp, "parentIdTag");
  9585. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9586. c = 0;
  9587. if(loc == NULL)
  9588. {
  9589. strcpy(parentIdTagstr, "");
  9590. }
  9591. else
  9592. {
  9593. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9594. {
  9595. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9596. c++;
  9597. }
  9598. sstr[c] = '\0';
  9599. strcpy(parentIdTagstr, sstr);
  9600. }
  9601. //***(5)reservationId ****/
  9602. c=0;
  9603. loc = strstr(sstrtemp, "reservationId");
  9604. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9605. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9606. {
  9607. sstr[c] = loc[strlen("reservationId")+2+c];
  9608. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9609. c++;
  9610. }
  9611. sstr[c] = '\0';
  9612. reservationIdInt = atoi(sstr);
  9613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9614. /*
  9615. enum SYSTEM_STATUS
  9616. {
  9617. SYS_MODE_BOOTING = 0,
  9618. SYS_MODE_IDLE = 1,
  9619. SYS_MODE_AUTHORIZING = 2,
  9620. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9621. SYS_MODE_REASSIGN = 4,
  9622. SYS_MODE_PREPARING = 5,
  9623. SYS_MODE_PREPARE_FOR_EV = 6,
  9624. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9625. SYS_MODE_CHARGING = 8,
  9626. SYS_MODE_TERMINATING = 9,
  9627. SYS_MODE_COMPLETE = 10,
  9628. SYS_MODE_ALARM = 11,
  9629. SYS_MODE_FAULT = 12,
  9630. SYS_MODE_RESERVATION = 13,
  9631. SYS_MODE_BOOKING = 14,
  9632. SYS_MODE_MAINTAIN = 15,
  9633. SYS_MODE_DEBUG = 16,
  9634. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9635. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9636. SYS_MODE_UPDATE = 19
  9637. };
  9638. */
  9639. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9640. {
  9641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9642. goto end;
  9643. }
  9644. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9645. {
  9646. //check Transaction active
  9647. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9648. {
  9649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9650. {
  9651. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9652. }
  9653. else
  9654. {
  9655. tempIndex = connectorIdInt -1;
  9656. }
  9657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9658. {
  9659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9660. {
  9661. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9662. {
  9663. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9664. {
  9665. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9666. {
  9667. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9669. }
  9670. 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'))
  9671. {
  9672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9673. }
  9674. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9675. {
  9676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9677. }
  9678. else
  9679. {
  9680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9681. }
  9682. }
  9683. 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
  9684. {
  9685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9686. }
  9687. }
  9688. else
  9689. {
  9690. //replace reservation
  9691. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9693. }
  9694. }
  9695. } // END FOR CHAdeMO_QUANTITY
  9696. }
  9697. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9698. {
  9699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9700. {
  9701. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9702. }
  9703. else
  9704. {
  9705. tempIndex = connectorIdInt -1;
  9706. }
  9707. for (int index = 0; index < CCS_QUANTITY; index++)
  9708. {
  9709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9710. {
  9711. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9712. {
  9713. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9714. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9715. {
  9716. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9717. {
  9718. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9720. }
  9721. 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'))
  9722. {
  9723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9724. }
  9725. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9726. {
  9727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9728. }
  9729. else
  9730. {
  9731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9732. }
  9733. }
  9734. 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
  9735. {
  9736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9737. }
  9738. }
  9739. else
  9740. {
  9741. //replace reservation
  9742. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9744. }
  9745. }
  9746. } // END FOR CCS_QUANTITY
  9747. }
  9748. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9749. {
  9750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9751. {
  9752. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9753. }
  9754. else
  9755. {
  9756. tempIndex = connectorIdInt -1;
  9757. }
  9758. for (int index = 0; index < GB_QUANTITY; index++)
  9759. {
  9760. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9761. {
  9762. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9763. {
  9764. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9765. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9766. {
  9767. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9768. {
  9769. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9771. }
  9772. 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'))
  9773. {
  9774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9775. }
  9776. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9777. {
  9778. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9779. }
  9780. else
  9781. {
  9782. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9783. }
  9784. }
  9785. 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
  9786. {
  9787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9788. }
  9789. }
  9790. else
  9791. {
  9792. //replace reservation
  9793. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9795. }
  9796. }
  9797. }// END FOR GB_QUANTITY
  9798. }
  9799. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9800. {
  9801. tempIndex = connectorIdInt -1;
  9802. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9803. {
  9804. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9805. {
  9806. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9807. {
  9808. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9809. 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
  9810. {
  9811. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9812. {
  9813. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9815. }
  9816. 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'))
  9817. {
  9818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9819. }
  9820. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9821. {
  9822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9823. }
  9824. else
  9825. {
  9826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9827. }
  9828. }
  9829. 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
  9830. {
  9831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9832. }
  9833. }
  9834. else
  9835. {
  9836. //replace reservation
  9837. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9839. }
  9840. }
  9841. }// END FOR GB_QUANTITY
  9842. }
  9843. else
  9844. {
  9845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9846. {
  9847. tempIndex = 2;
  9848. }
  9849. else
  9850. {
  9851. tempIndex = (connectorIdInt -1);
  9852. }
  9853. for (int index = 0; index < AC_QUANTITY; index++)
  9854. {
  9855. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9856. {
  9857. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9858. {
  9859. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9860. {
  9861. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9862. {
  9863. 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))
  9864. {
  9865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9866. }
  9867. else
  9868. {
  9869. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9871. }
  9872. }
  9873. 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'))
  9874. {
  9875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9876. }
  9877. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9878. {
  9879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9880. }
  9881. else
  9882. {
  9883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9884. }
  9885. }
  9886. 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
  9887. {
  9888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9889. }
  9890. }
  9891. else
  9892. {
  9893. //replace reservation
  9894. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9896. }
  9897. }
  9898. } // END FOR AC_QUANTITY
  9899. }
  9900. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9901. }
  9902. else if(connectorIdInt == 0)
  9903. {
  9904. //check Transaction active
  9905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9906. {
  9907. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9908. {
  9909. 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'))
  9910. {
  9911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9912. goto end;
  9913. }
  9914. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9915. {
  9916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9917. goto end;
  9918. }
  9919. 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
  9920. {
  9921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9922. goto end;
  9923. }
  9924. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9925. {
  9926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9927. goto end;
  9928. }
  9929. }
  9930. }// END FOR CHAdeMO_QUANTITY
  9931. for (int index = 0; index < CCS_QUANTITY; index++)
  9932. {
  9933. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9934. {
  9935. 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'))
  9936. {
  9937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9938. goto end;
  9939. }
  9940. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9941. {
  9942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9943. goto end;
  9944. }
  9945. 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
  9946. {
  9947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9948. goto end;
  9949. }
  9950. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9951. {
  9952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9953. goto end;
  9954. }
  9955. }
  9956. } // END FOR CCS_QUANTITY
  9957. for (int index = 0; index < GB_QUANTITY; index++)
  9958. {
  9959. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9960. {
  9961. 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'))
  9962. {
  9963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9964. goto end;
  9965. }
  9966. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9967. {
  9968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9969. goto end;
  9970. }
  9971. 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
  9972. {
  9973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9974. goto end;
  9975. }
  9976. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9977. {
  9978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9979. goto end;
  9980. }
  9981. }
  9982. } // END FOR GB_QUANTITY
  9983. for (int index = 0; index < AC_QUANTITY; index++)
  9984. {
  9985. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9986. {
  9987. 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'))
  9988. {
  9989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9990. goto end;
  9991. }
  9992. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9993. {
  9994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9995. goto end;
  9996. }
  9997. 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
  9998. {
  9999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10000. goto end;
  10001. }
  10002. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10003. {
  10004. 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))
  10005. {
  10006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10007. goto end;
  10008. }
  10009. }
  10010. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10011. {
  10012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10013. goto end;
  10014. }
  10015. }
  10016. }// END FOR AC_QUANTITY
  10017. //The connectorId is 0
  10018. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10020. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10021. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10022. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10023. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10024. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10025. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10026. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10027. result = TRUE;
  10028. return result;
  10029. }
  10030. else
  10031. {
  10032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10033. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10034. }
  10035. if(strcmp(comfirmstr,"Accepted") == 0)
  10036. {
  10037. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10038. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10039. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10040. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10041. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10042. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10043. result = TRUE;
  10044. return result;
  10045. }
  10046. end:
  10047. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10048. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10049. return result;
  10050. }
  10051. int handleResetRequest(char *uuid, char *payload)
  10052. {
  10053. mtrace();
  10054. int result = FAIL;
  10055. char sstr[10]={0},sstrtemp[30]={ 0 };
  10056. char typestr[10]={0};
  10057. char comfirmstr[20]={0};
  10058. int c = 0;
  10059. char *loc;
  10060. DEBUG_INFO("handleResetRequest...\n");
  10061. strcpy(sstrtemp, stringtrimspace(payload));
  10062. loc = strstr(sstrtemp, "type");
  10063. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10064. c = 0;
  10065. while (loc[3+strlen("type")+c] != '\"')
  10066. {
  10067. sstr[c] = loc[3+strlen("type")+c];
  10068. c++;
  10069. }
  10070. sstr[c] = '\0';
  10071. strcpy(typestr,sstr);
  10072. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10073. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10074. {
  10075. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10076. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10077. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10078. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10079. }
  10080. else
  10081. {
  10082. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10083. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10084. result = PASS;
  10085. }
  10086. sendResetConfirmation(uuid, comfirmstr);
  10087. return result;
  10088. }
  10089. int handleSendLocalListRequest(char *uuid, char *payload)
  10090. {
  10091. mtrace();
  10092. int result = FAIL;
  10093. char comfirmstr[20];
  10094. int checkState_Faulted = FALSE;
  10095. json_object *SendLocalList;
  10096. DEBUG_INFO("handleSendLocalListRequest...\n");
  10097. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10098. {
  10099. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10100. goto end;
  10101. }
  10102. //check Charge Point state
  10103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10104. {
  10105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10106. {
  10107. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10108. }
  10109. }
  10110. for (int index = 0; index < CCS_QUANTITY; index++)
  10111. {
  10112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10113. {
  10114. checkState_Faulted = TRUE; //OCPP Status
  10115. }
  10116. }
  10117. for (int index = 0; index < GB_QUANTITY; index++)
  10118. {
  10119. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10120. {
  10121. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10122. }
  10123. }
  10124. //check Charge Point state
  10125. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10126. {
  10127. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10128. {
  10129. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10130. }
  10131. }
  10132. //check Charge Point state
  10133. for (int index = 0; index < AC_QUANTITY; index++)
  10134. {
  10135. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10136. {
  10137. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10138. }
  10139. }
  10140. if(checkState_Faulted == TRUE)
  10141. {
  10142. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10143. goto end;
  10144. }
  10145. // Parsing payload
  10146. SendLocalList = json_tokener_parse(payload);
  10147. if(!is_error(SendLocalList))
  10148. {
  10149. // Required data
  10150. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10151. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10152. // Optional data
  10153. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10154. {
  10155. //Check UpdateType
  10156. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10157. {
  10158. //Local list full update
  10159. DEBUG_INFO("Local list full update.\n");
  10160. OCPP_getListVerion();
  10161. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10162. {
  10163. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10164. goto end;
  10165. }
  10166. OCPP_cleanLocalList();
  10167. }
  10168. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10169. {
  10170. //Local list different update
  10171. DEBUG_INFO("Local list different update.\n");
  10172. OCPP_getListVerion();
  10173. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10174. {
  10175. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10176. goto end;
  10177. }
  10178. }
  10179. else
  10180. {
  10181. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10182. goto end;
  10183. }
  10184. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  10185. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10186. {
  10187. 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")));
  10188. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10189. {
  10190. 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")));
  10191. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10192. 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")));
  10193. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10194. 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")));
  10195. }
  10196. // Add to db
  10197. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10198. {
  10199. //Local list full update
  10200. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10201. idx,
  10202. ShmOCPP16Data->SendLocalList.ListVersion,
  10203. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10204. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10205. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10207. // update list
  10208. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10209. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10210. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10211. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10212. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10213. }
  10214. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10215. {
  10216. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10217. idx,
  10218. ShmOCPP16Data->SendLocalList.ListVersion,
  10219. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10220. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10221. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10222. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10223. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10224. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10225. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10226. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10227. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10228. }
  10229. }
  10230. }
  10231. else
  10232. {
  10233. //Check UpdateType
  10234. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10235. {
  10236. //Local list full update
  10237. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10238. OCPP_cleanLocalList();
  10239. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10240. goto end;
  10241. }
  10242. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10243. {
  10244. //Local list different update
  10245. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10246. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10247. goto end;
  10248. }
  10249. }
  10250. result = PASS;
  10251. }
  10252. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10253. end:
  10254. json_object_put(SendLocalList);
  10255. sendSendLocalListConfirmation(uuid, comfirmstr);
  10256. return result;
  10257. }
  10258. #define MAX 200
  10259. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10260. {
  10261. mtrace();
  10262. int result = FAIL;
  10263. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10264. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10265. char chargingProfilePurposeStr[30]={0};
  10266. char chargingProfileKindStr[16]={0};
  10267. char recurrencyKindStr[10]={0};
  10268. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10269. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10270. int chargingSchedulePeriodCount = 0;
  10271. char comfirmstr[20]={0};
  10272. int meet= FALSE;
  10273. FILE *fptr1;
  10274. char filename[MAX]={0};
  10275. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10276. char rmFileCmd[50]={0};
  10277. char tempchargingProfilePurposeStr[30]={0};
  10278. char word[1600]={0};
  10279. int n_chargingProfile = 0;
  10280. json_object *SetChargingProfile;
  10281. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10282. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10283. SetChargingProfile = json_tokener_parse(payload);
  10284. if(!is_error(SetChargingProfile))
  10285. {
  10286. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10287. {
  10288. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10289. if(connectorIdInt == 0)
  10290. {
  10291. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10292. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10293. }
  10294. else
  10295. {
  10296. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10297. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10298. }
  10299. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10300. }
  10301. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10302. {
  10303. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10304. {
  10305. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10306. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10307. {
  10308. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10309. }
  10310. else
  10311. {
  10312. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10313. }
  10314. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10315. }
  10316. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10317. {
  10318. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10319. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10320. {
  10321. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10322. }
  10323. else
  10324. {
  10325. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10326. }
  10327. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10328. }
  10329. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10330. {
  10331. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10332. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10333. {
  10334. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10335. }
  10336. else
  10337. {
  10338. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10339. }
  10340. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10341. }
  10342. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10343. {
  10344. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10345. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10346. {
  10347. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10348. }
  10349. else
  10350. {
  10351. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10352. }
  10353. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10354. }
  10355. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10356. {
  10357. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10358. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10359. {
  10360. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10361. }
  10362. else
  10363. {
  10364. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10365. }
  10366. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10367. }
  10368. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10369. {
  10370. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10371. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10372. {
  10373. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10374. }
  10375. else
  10376. {
  10377. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10378. }
  10379. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10380. }
  10381. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10382. {
  10383. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10384. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10385. {
  10386. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10387. }
  10388. else
  10389. {
  10390. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10391. }
  10392. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10393. }
  10394. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10395. {
  10396. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10397. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10398. {
  10399. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10400. }
  10401. else
  10402. {
  10403. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10404. }
  10405. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10406. }
  10407. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10408. {
  10409. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10410. {
  10411. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10412. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10413. {
  10414. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10415. }
  10416. else
  10417. {
  10418. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10419. }
  10420. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10421. }
  10422. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10423. {
  10424. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10425. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10426. {
  10427. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10428. }
  10429. else
  10430. {
  10431. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10432. }
  10433. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10434. }
  10435. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10436. {
  10437. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10438. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10439. {
  10440. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10441. }
  10442. else
  10443. {
  10444. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10445. }
  10446. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10447. }
  10448. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10449. {
  10450. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10451. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10452. {
  10453. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10454. }
  10455. else
  10456. {
  10457. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10458. }
  10459. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10460. }
  10461. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10462. {
  10463. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10464. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10465. if(chargingSchedulePeriodCount <= 10)
  10466. {
  10467. 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++)
  10468. {
  10469. 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)
  10470. {
  10471. 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"));
  10472. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10473. {
  10474. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10475. }
  10476. else
  10477. {
  10478. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10479. }
  10480. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10481. }
  10482. 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)
  10483. {
  10484. 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"));
  10485. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10486. {
  10487. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10488. }
  10489. else
  10490. {
  10491. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10492. }
  10493. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10494. }
  10495. 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)
  10496. {
  10497. 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"));
  10498. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10499. {
  10500. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10501. }
  10502. else
  10503. {
  10504. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10505. }
  10506. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10507. }
  10508. }
  10509. }
  10510. }
  10511. }
  10512. }
  10513. }
  10514. json_object_put(SetChargingProfile);
  10515. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10516. {
  10517. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10518. goto end;
  10519. }
  10520. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10521. {
  10522. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10523. if(connectorIdInt != 0)
  10524. {
  10525. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10526. goto end;
  10527. }
  10528. strcpy(filename, ChargePointMaxProfile_JSON );
  10529. fptr1 = fopen(filename, "r");
  10530. if (!fptr1)
  10531. {
  10532. //file not exist
  10533. DEBUG_INFO("Unable to open the input file!!\n");
  10534. fptr1 = fopen(filename, "w+");
  10535. }
  10536. else
  10537. {
  10538. //Check Charging Profile Count
  10539. while(fscanf(fptr1, "%s", word) != EOF)
  10540. {
  10541. //DEBUG_INFO("word=%s\n",word);
  10542. if(strstr(word, "chargingProfileId")!= NULL)
  10543. {
  10544. //DEBUG_INFO("test chargingProfileId \n");
  10545. n_chargingProfile = n_chargingProfile + 1;
  10546. //DEBUG_INFO("chargingProfileId Found\n");
  10547. }
  10548. }
  10549. }
  10550. fclose(fptr1);
  10551. }
  10552. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10553. {
  10554. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10555. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10556. {
  10557. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10558. goto end;
  10559. }
  10560. memset(filename, 0, ARRAY_SIZE(filename));
  10561. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10562. fptr1 = fopen(filename, "r");
  10563. if (!fptr1)
  10564. {
  10565. //file not exist
  10566. //DEBUG_INFO("Unable to open the input file!!\n");
  10567. fptr1 = fopen(filename, "w+");
  10568. }
  10569. else
  10570. {
  10571. //Check Charging Profile Count
  10572. while(fscanf(fptr1, "%s", word) != EOF)
  10573. {
  10574. //DEBUG_INFO("word=%s\n",word);
  10575. if(strstr(word, "chargingProfileId")!= NULL)
  10576. {
  10577. //DEBUG_INFO("test chargingProfileId \n");
  10578. n_chargingProfile = n_chargingProfile + 1;
  10579. //DEBUG_INFO("chargingProfileId Found\n");
  10580. }
  10581. }
  10582. }
  10583. fclose(fptr1);
  10584. }
  10585. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10586. {
  10587. //printf("set chargingProfile 1-4\n");
  10588. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10589. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10590. if(connectorIdInt == 0)
  10591. {
  10592. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10593. goto end;
  10594. }
  10595. int tempIndex = 0;
  10596. //check Transaction active
  10597. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10598. {
  10599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10600. {
  10601. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10602. }
  10603. else
  10604. {
  10605. tempIndex = connectorIdInt -1;
  10606. }
  10607. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10608. {
  10609. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10610. {
  10611. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10612. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10613. {
  10614. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10615. {
  10616. meet = TRUE;
  10617. break;
  10618. }
  10619. }
  10620. }
  10621. }
  10622. }
  10623. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10624. {
  10625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10626. {
  10627. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10628. }
  10629. else
  10630. {
  10631. tempIndex = connectorIdInt -1;
  10632. }
  10633. for (int index = 0; index < CCS_QUANTITY; index++)
  10634. {
  10635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10636. {
  10637. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10638. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10639. {
  10640. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10641. {
  10642. meet = TRUE;
  10643. break;
  10644. }
  10645. }
  10646. }
  10647. }
  10648. }
  10649. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10650. {
  10651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10652. {
  10653. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10654. }
  10655. else
  10656. {
  10657. tempIndex = connectorIdInt -1;
  10658. }
  10659. for (int index = 0; index < GB_QUANTITY; index++)
  10660. {
  10661. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10662. {
  10663. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10664. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10665. {
  10666. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10667. {
  10668. meet = TRUE;
  10669. break;
  10670. }
  10671. }
  10672. }
  10673. }
  10674. }
  10675. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10676. {
  10677. tempIndex = connectorIdInt -1;
  10678. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10679. {
  10680. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10681. {
  10682. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10683. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10684. {
  10685. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10686. {
  10687. meet = TRUE;
  10688. break;
  10689. }
  10690. }
  10691. }
  10692. }
  10693. }
  10694. else
  10695. {
  10696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10697. {
  10698. tempIndex = 2;
  10699. }
  10700. else
  10701. {
  10702. tempIndex = (connectorIdInt -1);
  10703. }
  10704. for (int index = 0; index < AC_QUANTITY; index++)
  10705. {
  10706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10707. {
  10708. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10709. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10710. {
  10711. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10712. {
  10713. meet = TRUE;
  10714. break;
  10715. }
  10716. }
  10717. }
  10718. }
  10719. }
  10720. //check Transaction active
  10721. if(meet == FALSE)
  10722. {
  10723. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10724. goto end;
  10725. }
  10726. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10727. {
  10728. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10729. goto end;
  10730. }
  10731. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10732. fptr1 = fopen(filename, "r");
  10733. if (!fptr1)
  10734. {
  10735. //file not exist
  10736. DEBUG_INFO("Unable to open the input file!!\n");
  10737. fptr1 = fopen(filename, "w+");
  10738. }
  10739. else
  10740. {
  10741. //Check Charging Profile Count
  10742. while(fscanf(fptr1, "%s", word) != EOF)
  10743. {
  10744. //DEBUG_INFO("word=%s\n",word);
  10745. if(strstr(word, "chargingProfileId")!= NULL)
  10746. {
  10747. //DEBUG_INFO("test chargingProfileId \n");
  10748. n_chargingProfile = n_chargingProfile + 1;
  10749. //DEBUG_INFO("chargingProfileId Found\n");
  10750. }
  10751. }
  10752. }
  10753. fclose(fptr1);
  10754. }
  10755. // Check ChargeProfileMaxStackLevel
  10756. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10757. {
  10758. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10759. goto end;
  10760. }
  10761. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10762. {
  10763. int i = 0;
  10764. char fnametemp[200]={0};
  10765. n_chargingProfile = 0;
  10766. //Check ChargePointMaxProfile.json exit
  10767. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10768. {
  10769. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10770. //Check Charging Profile Count
  10771. while(fscanf(fptr1, "%s", word) != EOF)
  10772. {
  10773. //DEBUG_INFO("word=%s\n",word);
  10774. if(strstr(word, "chargingProfileId")!= NULL)
  10775. {
  10776. //DEBUG_INFO("test chargingProfileId \n");
  10777. n_chargingProfile = n_chargingProfile + 1;
  10778. i = i + 1;
  10779. //DEBUG_INFO("chargingProfileId Found\n");
  10780. }
  10781. memset(word, 0, ARRAY_SIZE(word));
  10782. }
  10783. fclose(fptr1);
  10784. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10785. }
  10786. //Check TxDefaultProfile_0.json exit
  10787. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10788. {
  10789. i = 0;
  10790. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10791. //Check Charging Profile Count
  10792. while(fscanf(fptr1, "%s", word) != EOF)
  10793. {
  10794. //DEBUG_INFO("word=%s\n",word);
  10795. if(strstr(word, "chargingProfileId")!= NULL)
  10796. {
  10797. //DEBUG_INFO("test chargingProfileId \n");
  10798. n_chargingProfile = n_chargingProfile + 1;
  10799. i = i + 1;
  10800. //DEBUG_INFO("chargingProfileId Found\n");
  10801. }
  10802. memset(word, 0, ARRAY_SIZE(word));
  10803. }
  10804. fclose(fptr1);
  10805. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10806. }
  10807. //Check TxDefaultProfile_%d.json
  10808. for(int j=1; j <= gunTotalNumber; j++)
  10809. {
  10810. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10811. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10812. if((access(fnametemp,F_OK))!=-1)
  10813. {
  10814. i = 0;
  10815. fptr1 = fopen(fnametemp, "r");
  10816. //Check Charging Profile Count
  10817. while(fscanf(fptr1, "%s", word) != EOF)
  10818. {
  10819. //DEBUG_INFO("word=%s\n",word);
  10820. if(strstr(word, "chargingProfileId")!= NULL)
  10821. {
  10822. //DEBUG_INFO("test chargingProfileId \n");
  10823. n_chargingProfile = n_chargingProfile + 1;
  10824. i = i + 1;
  10825. //DEBUG_INFO("chargingProfileId Found\n");
  10826. }
  10827. memset(word, 0, ARRAY_SIZE(word));
  10828. }
  10829. fclose(fptr1);
  10830. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10831. }
  10832. }
  10833. //Check TxProfile_%d.json
  10834. for(int j=1; j <= gunTotalNumber; j++)
  10835. {
  10836. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10837. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10838. if((access(fnametemp,F_OK))!=-1)
  10839. {
  10840. i = 0;
  10841. fptr1 = fopen(fnametemp, "r");
  10842. //Check Charging Profile Count
  10843. while(fscanf(fptr1, "%s", word) != EOF)
  10844. {
  10845. //DEBUG_INFO("word=%s\n",word);
  10846. if(strstr(word, "chargingProfileId")!= NULL)
  10847. {
  10848. //DEBUG_INFO("test chargingProfileId \n");
  10849. n_chargingProfile = n_chargingProfile + 1;
  10850. i = i + 1;
  10851. //DEBUG_INFO("chargingProfileId Found\n");
  10852. }
  10853. memset(word, 0, ARRAY_SIZE(word));
  10854. }
  10855. fclose(fptr1);
  10856. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10857. }
  10858. }
  10859. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10860. {
  10861. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10862. goto end;
  10863. }
  10864. }
  10865. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10866. //**********************************Write to File********************************************************/
  10867. FILE *infile;
  10868. FILE *outfile;
  10869. infile = fopen (filename, "r");
  10870. outfile = fopen (tempfile, "w");
  10871. int d =0;
  10872. d = fgetc(infile);
  10873. rewind(infile);
  10874. if(d == EOF)
  10875. {
  10876. // Profile is empty
  10877. fprintf(outfile,"%s\n",payload);
  10878. fclose(infile);
  10879. fclose(outfile);
  10880. sprintf(rmFileCmd,"rm -f %s",filename);
  10881. system(rmFileCmd);
  10882. rename(tempfile, filename);
  10883. }
  10884. else
  10885. {
  10886. // Profile is not empty
  10887. char buf[2048]={0};
  10888. int ChargingProfileAdded = FALSE;
  10889. while (fgets(buf, sizeof(buf), infile) != NULL)
  10890. {
  10891. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10892. json_object *tmpChargingProfile;
  10893. tmpChargingProfile = json_tokener_parse(buf);
  10894. if(!is_error(SetChargingProfile))
  10895. {
  10896. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10897. {
  10898. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10899. }
  10900. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10901. {
  10902. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10903. {
  10904. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10905. }
  10906. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10907. {
  10908. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10909. }
  10910. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10911. {
  10912. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10913. }
  10914. }
  10915. }
  10916. json_object_put(tmpChargingProfile);
  10917. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10918. {
  10919. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10920. {
  10921. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10922. if(ChargingProfileAdded == FALSE)
  10923. {
  10924. fprintf(outfile,"%s\n",payload);
  10925. ChargingProfileAdded = TRUE;
  10926. }
  10927. }
  10928. else
  10929. {
  10930. if(tempstackLevelInt < stackLevelInt)
  10931. {
  10932. if(ChargingProfileAdded == FALSE)
  10933. {
  10934. fprintf(outfile,"%s\n",buf);
  10935. fprintf(outfile,"%s\n",payload);
  10936. ChargingProfileAdded = TRUE;
  10937. }
  10938. else
  10939. {
  10940. fprintf(outfile,"%s\n",buf);
  10941. }
  10942. }
  10943. else
  10944. {
  10945. if(ChargingProfileAdded == FALSE)
  10946. {
  10947. fprintf(outfile,"%s\n",buf);
  10948. fprintf(outfile,"%s\n",payload);
  10949. ChargingProfileAdded = TRUE;
  10950. }
  10951. else
  10952. {
  10953. fprintf(outfile,"%s\n",buf);
  10954. }
  10955. }
  10956. }
  10957. }
  10958. else
  10959. {
  10960. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10961. {
  10962. if(ChargingProfileAdded == FALSE)
  10963. {
  10964. fprintf(outfile,"%s\n",buf);
  10965. fprintf(outfile,"%s\n",payload);
  10966. ChargingProfileAdded = TRUE;
  10967. }
  10968. else
  10969. {
  10970. fprintf(outfile,"%s\n",buf);
  10971. }
  10972. }
  10973. else if(tempstackLevelInt < stackLevelInt)
  10974. {
  10975. if(ChargingProfileAdded == FALSE)
  10976. {
  10977. fprintf(outfile,"%s\n",buf);
  10978. fprintf(outfile,"%s\n",payload);
  10979. ChargingProfileAdded = TRUE;
  10980. }
  10981. else
  10982. {
  10983. fprintf(outfile,"%s\n",buf);
  10984. }
  10985. }
  10986. else
  10987. {
  10988. if(ChargingProfileAdded == FALSE)
  10989. {
  10990. fprintf(outfile,"%s\n",buf);
  10991. fprintf(outfile,"%s\n",payload);
  10992. ChargingProfileAdded = TRUE;
  10993. }
  10994. else
  10995. {
  10996. fprintf(outfile,"%s\n",buf);
  10997. }
  10998. }
  10999. }
  11000. } // end of while loop
  11001. fclose(infile);
  11002. fclose(outfile);
  11003. sprintf(rmFileCmd,"rm -f %s",filename);
  11004. system(rmFileCmd);
  11005. rename(tempfile, filename);
  11006. }
  11007. sleep(1);
  11008. result = TRUE;
  11009. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11010. end:
  11011. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11012. {
  11013. if(connectorIdInt == 0)
  11014. {
  11015. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11016. {
  11017. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11018. }
  11019. }
  11020. else
  11021. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11022. }
  11023. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11024. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11025. return result;
  11026. }
  11027. int handleTriggerMessageRequest(char *uuid, char *payload)
  11028. {
  11029. mtrace();
  11030. int result = FAIL;
  11031. int connectorIdIsNULL = FALSE;
  11032. int connectorIdInt =0;
  11033. char sstr[40]={0},sstrtemp[100]={ 0 };
  11034. char requestedMessagestr[40]={0};
  11035. char comfirmstr[20]={0};
  11036. int c = 0;
  11037. char *loc;
  11038. DEBUG_INFO("handleTriggerMessageRequest\n");
  11039. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11040. strcpy(sstrtemp, stringtrimspace(payload));
  11041. c = 0;
  11042. loc = strstr(sstrtemp, "requestedMessage");
  11043. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11044. {
  11045. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11046. c++;
  11047. }
  11048. sstr[c] = '\0';
  11049. strcpy(requestedMessagestr, sstr);
  11050. c = 0;
  11051. loc = strstr(sstrtemp, "connectorId");
  11052. if(loc == NULL)
  11053. {
  11054. connectorIdIsNULL = TRUE;
  11055. }
  11056. else
  11057. {
  11058. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11059. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11060. {
  11061. sstr[c] = loc[strlen("connectorId")+2+c];
  11062. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11063. c++;
  11064. }
  11065. sstr[c] = '\0';
  11066. connectorIdInt = atoi(sstr);
  11067. }
  11068. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11069. {
  11070. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11071. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11072. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11073. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11074. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11075. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11076. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11077. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11078. {
  11079. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11080. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11081. return TRUE;
  11082. }
  11083. else
  11084. {
  11085. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11086. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11087. }
  11088. }
  11089. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11090. {
  11091. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11092. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11093. return TRUE;
  11094. }
  11095. //==========================
  11096. // Trigger message
  11097. //==========================
  11098. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11099. {
  11100. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11101. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11102. {
  11103. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11104. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11105. }
  11106. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11107. }
  11108. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11109. {
  11110. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11111. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11112. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11113. }
  11114. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11115. {
  11116. //sendBootNotificationRequest();
  11117. server_sign = FALSE;
  11118. }
  11119. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11120. {
  11121. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11122. }
  11123. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11124. {
  11125. if(connectorIdIsNULL == FALSE)
  11126. {
  11127. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11128. {
  11129. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11130. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11131. }
  11132. }
  11133. else
  11134. {
  11135. for(int idx=0;idx< gunTotalNumber;idx++)
  11136. {
  11137. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11138. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11139. }
  11140. }
  11141. }
  11142. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11143. {
  11144. if(connectorIdIsNULL == FALSE)
  11145. {
  11146. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11147. {
  11148. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11149. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11150. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11151. }
  11152. }
  11153. else
  11154. {
  11155. for(int idx=0;idx< gunTotalNumber;idx++)
  11156. {
  11157. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11158. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11159. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11160. }
  11161. }
  11162. }
  11163. return result;
  11164. }
  11165. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11166. {
  11167. mtrace();
  11168. int result = FAIL;
  11169. int connectorIdInt =0;
  11170. char comfirmstr[20]={0};
  11171. int tempIndex = 0;
  11172. json_object *UnlockConnector;
  11173. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11174. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11175. UnlockConnector = json_tokener_parse(payload);
  11176. if(!is_error(UnlockConnector))
  11177. {
  11178. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11179. {
  11180. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11181. }
  11182. }
  11183. json_object_put(UnlockConnector);
  11184. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11185. if(gunTotalNumber == 0)
  11186. {
  11187. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11188. goto end;
  11189. }
  11190. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11191. {
  11192. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11193. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11194. goto end;
  11195. }
  11196. else
  11197. {
  11198. //check Transaction active
  11199. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11200. {
  11201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11202. {
  11203. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11204. }
  11205. else
  11206. {
  11207. tempIndex = connectorIdInt -1;
  11208. }
  11209. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11210. {
  11211. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11212. {
  11213. //stop Transaction
  11214. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11215. }
  11216. }
  11217. }
  11218. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11219. {
  11220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11221. {
  11222. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11223. }
  11224. else
  11225. {
  11226. tempIndex = connectorIdInt -1;
  11227. }
  11228. for (int index = 0; index < CCS_QUANTITY; index++)
  11229. {
  11230. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11231. {
  11232. //stop Transaction
  11233. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11234. }
  11235. }
  11236. }
  11237. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11238. {
  11239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11240. {
  11241. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11242. }
  11243. else
  11244. {
  11245. tempIndex = connectorIdInt -1;
  11246. }
  11247. for (int index = 0; index < GB_QUANTITY; index++)
  11248. {
  11249. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11250. {
  11251. //stop Transaction
  11252. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11253. }
  11254. }
  11255. }
  11256. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11257. {
  11258. tempIndex = connectorIdInt -1;
  11259. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11260. {
  11261. 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)))
  11262. {
  11263. //stop Transaction
  11264. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11265. }
  11266. }
  11267. }
  11268. else
  11269. {
  11270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11271. {
  11272. tempIndex = 2;
  11273. }
  11274. else
  11275. {
  11276. tempIndex = connectorIdInt-1;
  11277. }
  11278. for (int index = 0; index < AC_QUANTITY; index++)
  11279. {
  11280. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11281. {
  11282. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11283. }
  11284. }
  11285. }
  11286. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11287. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11288. result = TRUE;
  11289. return result;
  11290. }
  11291. end:
  11292. //json_object_put(obj); --- remove temporally
  11293. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11294. return result;
  11295. }
  11296. static char UpdateFirmwarepayloadData[300]={0};
  11297. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11298. {
  11299. mtrace();
  11300. int result = FAIL;
  11301. pthread_t t;
  11302. sendUpdateFirmwareConfirmation(uuid);
  11303. memset(UpdateFirmwarepayloadData, 0, 300);
  11304. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11305. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11306. ////pthread_join(t, NULL); //
  11307. //pthread_detach(t);
  11308. //sendUpdateFirmwareConfirmation(uuid);
  11309. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11310. return result;
  11311. }
  11312. void *UpdateFirmwareProcess(void *data)
  11313. {
  11314. pthread_detach(pthread_self());
  11315. mtrace();
  11316. int retriesInt =0, retryIntervalInt=0;
  11317. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11318. int port=0;
  11319. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11320. int isSuccess = 0;
  11321. char ftpbuf[1024];
  11322. char temp[1024];
  11323. char * pch;
  11324. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11325. json_object *UpdateFirmware;
  11326. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11327. if(!is_error(UpdateFirmware))
  11328. {
  11329. // Required data
  11330. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11331. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11332. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11333. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11334. // Optional data
  11335. if(json_object_object_get(UpdateFirmware, "retries"))
  11336. {
  11337. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11338. }
  11339. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11340. {
  11341. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11342. }
  11343. }
  11344. json_object_put(UpdateFirmware);
  11345. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11346. memset(path, 0, ARRAY_SIZE(path));
  11347. // Wait retrieveData
  11348. if(strlen(retrieveDatestr) > 10)
  11349. {
  11350. do
  11351. {
  11352. sleep(1);
  11353. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11354. }
  11355. // Ready to download
  11356. system("rm -f /mnt/*");
  11357. if(strncmp(locationstr,"http", 4) == 0)
  11358. {
  11359. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11360. sprintf(ftppath,"/%s", path);
  11361. DEBUG_INFO("locationstr: %s\n", locationstr);
  11362. DEBUG_INFO("protocol: %s\n",protocol);
  11363. DEBUG_INFO("host: %s\n",host);
  11364. DEBUG_INFO("path: %s\n",path);
  11365. DEBUG_INFO("ftppath: %s\n",ftppath);
  11366. int ftppathlen=strlen(ftppath);
  11367. int i=1;
  11368. char filenametemp[50];
  11369. while(i < ftppathlen)
  11370. {
  11371. int len=ftppathlen-i;
  11372. if(ftppath[len]== 47) // '/' ascll code: 47
  11373. {
  11374. DEBUG_INFO("compare '/' all right\n");
  11375. break;
  11376. }
  11377. i=i+1;
  11378. }
  11379. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11380. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11381. filenametemp[i+1] = 0;
  11382. do
  11383. {
  11384. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11385. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11386. sleep(1);
  11387. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11388. if(!isSuccess)
  11389. {
  11390. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11391. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11392. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11393. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11394. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11395. }
  11396. else
  11397. {
  11398. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11399. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11400. }
  11401. retriesInt--;
  11402. }while((isSuccess == 0)&&(retriesInt >= 0));
  11403. }
  11404. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11405. {
  11406. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11407. memset(temp, 0, ARRAY_SIZE(temp));
  11408. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11409. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11410. int ftppathlen=strlen(ftpbuf);
  11411. int i=1;
  11412. char filenametemp[50];
  11413. while(i < ftppathlen)
  11414. {
  11415. int len=ftppathlen-i;
  11416. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11417. {
  11418. DEBUG_INFO(" compare '/' all right\n");
  11419. break;
  11420. }
  11421. i=i+1;
  11422. }
  11423. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11424. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11425. filenametemp[i+1] = 0;
  11426. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11427. pch=strchr(temp,'@');
  11428. if(pch==NULL)
  11429. {
  11430. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11431. protocol, host, &port, path);
  11432. strcpy(user,"anonymous");
  11433. strcpy(password,"");
  11434. }
  11435. else
  11436. {
  11437. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11438. protocol, user, password, host, &port, path);
  11439. }
  11440. sscanf(host,"%[^/]%s",host1, path1);
  11441. sprintf(ftppath,"%s", path1);
  11442. //DEBUG_INFO("protocol =%s\n",protocol);
  11443. //DEBUG_INFO("user =%s\n",user);
  11444. //DEBUG_INFO("password =%s\n",password);
  11445. //DEBUG_INFO("host1 =%s\n",host1);
  11446. //DEBUG_INFO("port =%d\n",port);
  11447. //DEBUG_INFO("path1 =%s\n",path1);
  11448. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11449. //ftpFile(host, user, password, port, ftppath, fname);
  11450. //download firmware pthred
  11451. if(port == 0)
  11452. {
  11453. port = 21;
  11454. }
  11455. do
  11456. {
  11457. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11458. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11459. sleep(1);
  11460. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11461. if(!isSuccess)
  11462. {
  11463. //BulldogUtil.sleepMs(interval*1000);
  11464. DEBUG_INFO("Update firmware request and download file fail.\n");
  11465. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11466. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11467. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11468. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11469. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11470. }
  11471. else
  11472. {
  11473. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11474. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11475. }
  11476. retriesInt--;
  11477. }while((!isSuccess)&&(retriesInt >= 0));
  11478. }
  11479. else
  11480. {
  11481. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11482. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11483. sleep(1);
  11484. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11485. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11486. }
  11487. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11488. pthread_exit(NULL);
  11489. }
  11490. int handleCertificateSignedRequest(char *uuid, char *payload)
  11491. {
  11492. mtrace();
  11493. int result = PASS;
  11494. json_object *CertificateSigned;
  11495. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11496. CertificateSigned = json_tokener_parse(payload);
  11497. if(!is_error(CertificateSigned))
  11498. {
  11499. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11500. }
  11501. json_object_put(CertificateSigned);
  11502. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11503. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11504. fclose(fp);
  11505. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11506. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11507. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11508. sendCertificateSignedConfirmation(uuid);
  11509. return result;
  11510. }
  11511. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11512. {
  11513. mtrace();
  11514. int result = PASS;
  11515. json_object *DeleteCertificate;
  11516. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11517. DeleteCertificate = json_tokener_parse(payload);
  11518. if(!is_error(DeleteCertificate))
  11519. {
  11520. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11521. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11522. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11523. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11524. }
  11525. json_object_put(DeleteCertificate);
  11526. /*
  11527. * TODO: Delete certificateSigned process
  11528. */
  11529. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11530. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11531. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11532. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11533. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11534. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11535. sendDeleteCertificateConfirmation(uuid);
  11536. return result;
  11537. }
  11538. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11539. {
  11540. mtrace();
  11541. int result = PASS;
  11542. json_object *ExtendedTriggerMessage;
  11543. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11544. ExtendedTriggerMessage = json_tokener_parse(payload);
  11545. if(!is_error(ExtendedTriggerMessage))
  11546. {
  11547. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11548. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11549. {
  11550. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11551. }
  11552. else
  11553. {
  11554. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11555. }
  11556. }
  11557. json_object_put(ExtendedTriggerMessage);
  11558. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11559. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11560. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11561. {
  11562. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11563. }
  11564. else
  11565. {
  11566. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11567. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11568. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11569. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11570. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11571. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11572. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11573. {
  11574. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11575. }
  11576. else
  11577. {
  11578. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11579. }
  11580. }
  11581. sendExtendedTriggerMessageConfirmation(uuid);
  11582. //==========================
  11583. // Trigger message
  11584. //==========================
  11585. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11586. {
  11587. //sendBootNotificationRequest();
  11588. server_sign = FALSE;
  11589. }
  11590. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11591. {
  11592. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11593. }
  11594. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11595. {
  11596. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11597. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11598. {
  11599. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11600. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11601. }
  11602. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11603. }
  11604. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11605. {
  11606. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11607. }
  11608. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11609. {
  11610. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11611. {
  11612. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11613. }
  11614. else
  11615. {
  11616. for(int idx=0;idx< gunTotalNumber;idx++)
  11617. {
  11618. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11619. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11620. }
  11621. }
  11622. }
  11623. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11624. {
  11625. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11626. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11627. {
  11628. 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\" &");
  11629. }
  11630. }
  11631. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11632. {
  11633. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11634. {
  11635. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11636. }
  11637. else
  11638. {
  11639. for(int idx=0;idx< gunTotalNumber;idx++)
  11640. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11641. }
  11642. }
  11643. return result;
  11644. }
  11645. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11646. {
  11647. mtrace();
  11648. int result = PASS;
  11649. json_object *GetInstalledCertificateIds;
  11650. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11651. GetInstalledCertificateIds = json_tokener_parse(payload);
  11652. if(!is_error(GetInstalledCertificateIds))
  11653. {
  11654. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11655. }
  11656. json_object_put(GetInstalledCertificateIds);
  11657. /*
  11658. * TODO: Return installed certificate process
  11659. */
  11660. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11661. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11662. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11663. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11664. sendGetInstalledCertificateIdsConfirmation(uuid);
  11665. return result;
  11666. }
  11667. int handleGetLogRequest(char *uuid, char *payload)
  11668. {
  11669. mtrace();
  11670. int result = PASS;
  11671. json_object *GetLog;
  11672. DEBUG_INFO("handleGetLogRequest...\n");
  11673. GetLog = json_tokener_parse(payload);
  11674. if(!is_error(GetLog))
  11675. {
  11676. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11677. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11678. if(json_object_object_get(GetLog, "retries") != NULL)
  11679. {
  11680. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11681. }
  11682. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11683. {
  11684. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11685. }
  11686. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11687. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11688. {
  11689. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11690. }
  11691. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11692. {
  11693. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11694. }
  11695. }
  11696. json_object_put(GetLog);
  11697. /*
  11698. * TODO: Upload log process
  11699. */
  11700. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11701. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11702. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11703. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11704. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11705. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11706. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11707. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11708. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11709. sendGetLogConfirmation(uuid);
  11710. return result;
  11711. }
  11712. int handleInstallCertificateRequest(char *uuid, char *payload)
  11713. {
  11714. mtrace();
  11715. int result = PASS;
  11716. json_object *InstallCertificate;
  11717. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11718. InstallCertificate = json_tokener_parse(payload);
  11719. if(!is_error(InstallCertificate))
  11720. {
  11721. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11722. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11723. /*
  11724. * TODO: Install certificate process
  11725. */
  11726. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11727. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11728. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11729. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11730. sendInstallCertificateConfirmation(uuid);
  11731. }
  11732. json_object_put(InstallCertificate);
  11733. return result;
  11734. }
  11735. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11736. {
  11737. mtrace();
  11738. int result = PASS;
  11739. json_object *SignedUpdateFirmware;
  11740. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11741. SignedUpdateFirmware = json_tokener_parse(payload);
  11742. if(!is_error(SignedUpdateFirmware))
  11743. {
  11744. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11745. {
  11746. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11747. }
  11748. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11749. {
  11750. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11751. }
  11752. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11753. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11754. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11755. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11756. {
  11757. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11758. }
  11759. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11760. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11761. }
  11762. json_object_put(SignedUpdateFirmware);
  11763. /*
  11764. * TODO: Upgrade firmware process
  11765. */
  11766. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11767. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11768. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11769. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11770. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11771. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11772. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11773. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11774. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11775. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11776. sendInstallCertificateConfirmation(uuid);
  11777. return result;
  11778. }
  11779. int handleUnknownRequest(char *uuid, char *payload)
  11780. {
  11781. mtrace();
  11782. int result = PASS;
  11783. DEBUG_INFO("handleUnknownRequest...\n");
  11784. sendUnknownConfirmation(uuid);
  11785. result = PASS;
  11786. return result;
  11787. }
  11788. //==========================================
  11789. // Handle server response routine
  11790. //==========================================
  11791. void handleAuthorizeResponse(char *payload, int gun_index)
  11792. {
  11793. mtrace();
  11794. char expiryDatestr[30]={0};
  11795. char parentIdTagstr[20]={0};
  11796. char statusstr[20]={0};
  11797. int expiryDateISNULL=FALSE;
  11798. int parentIdTagISNULL=FALSE;
  11799. DEBUG_INFO("handleAuthorizeResponse...\n");
  11800. json_object *Authorize;
  11801. Authorize = json_tokener_parse(payload);
  11802. if(!is_error(Authorize))
  11803. {
  11804. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11805. {
  11806. // Required data
  11807. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11808. // Optional data
  11809. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11810. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11811. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11812. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11813. }
  11814. }
  11815. json_object_put(Authorize);
  11816. if(expiryDateISNULL == FALSE)
  11817. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11818. if(parentIdTagISNULL == FALSE)
  11819. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11820. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11821. //Update idTag information to authorization cache if supproted
  11822. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11823. {
  11824. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11825. }
  11826. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11827. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11828. authorizeRetryTimes = 0;
  11829. }
  11830. void handleBootNotificationResponse(char *payload, int gun_index)
  11831. {
  11832. mtrace();
  11833. char statusStr[12]={0};
  11834. char currentTimeStr[30]={0};
  11835. int intervalInt = 0;
  11836. DEBUG_INFO("handleBootNotificationResponse...\n");
  11837. json_object *BootNotification;
  11838. BootNotification = json_tokener_parse(payload);
  11839. if(!is_error(BootNotification))
  11840. {
  11841. // Required data
  11842. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11843. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11844. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11845. }
  11846. json_object_put(BootNotification);
  11847. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11848. BootNotificationInterval = intervalInt;
  11849. HeartBeatWaitTime = intervalInt;
  11850. //write back to ShmOCPP16Data->BootNotification
  11851. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11852. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11853. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11854. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11855. {
  11856. server_sign = TRUE;
  11857. server_pending =FALSE;
  11858. }
  11859. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11860. {
  11861. server_pending = TRUE;
  11862. }
  11863. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11864. srand(time(NULL));
  11865. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11866. SetOcppConnStatus(TRUE);
  11867. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11868. }
  11869. void handleDataTransferResponse(char *payload, int gun_index)
  11870. {
  11871. char sstr[160]={0};//sstr[200]={ 0 };
  11872. int c = 0;
  11873. char *loc;
  11874. DEBUG_INFO("handleDataTransferResponse ...\n");
  11875. loc = strstr(payload, "status");
  11876. c = 0;
  11877. while (loc[3+strlen("status")+c] != '\"')
  11878. {
  11879. sstr[c] = loc[3+strlen("status")+c];
  11880. c++;
  11881. }
  11882. sstr[c] = '\0';
  11883. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11884. }
  11885. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11886. {
  11887. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11888. //struct json_object *obj;
  11889. // obj = json_tokener_parse(payload);
  11890. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11891. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11892. //No fields are defined.
  11893. }
  11894. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11895. {
  11896. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11897. //struct json_object *obj;
  11898. // obj = json_tokener_parse(payload);
  11899. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11900. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11901. //No fields are defined.
  11902. }
  11903. void handleHeartbeatResponse(char *payload, int gun_index)
  11904. {
  11905. mtrace();
  11906. DEBUG_INFO("handleHeartbeatResponse...\n");
  11907. json_object *Heartbeat;
  11908. Heartbeat = json_tokener_parse(payload);
  11909. if(!is_error(Heartbeat))
  11910. {
  11911. // Required data
  11912. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11913. }
  11914. json_object_put(Heartbeat);
  11915. if(FirstHeartBeat == 0)
  11916. {
  11917. FirstHeartBeat = 1;
  11918. DEBUG_INFO("FirstHeartBeat \n");
  11919. }
  11920. HeartBeatWithNOResponse = 0;
  11921. clientTime.Heartbeat=time((time_t*)NULL);
  11922. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11923. }
  11924. void handleMeterValuesResponse(char *payload, int gun_index)
  11925. {
  11926. mtrace();
  11927. DEBUG_INFO("handleMeterValuesResponse...\n");
  11928. }
  11929. void handleStartTransactionResponse(char *payload, int gun_index)
  11930. {
  11931. mtrace();
  11932. //int transactionIdInt = 0;
  11933. FILE *outfile;
  11934. char data[100]={0};
  11935. DEBUG_INFO("handleStartTransactionResponse...\n");
  11936. json_object *StartTransaction;
  11937. StartTransaction = json_tokener_parse(payload);
  11938. if(!is_error(StartTransaction))
  11939. {
  11940. // Required data
  11941. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11942. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11943. // Optional data
  11944. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11945. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11946. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11947. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11948. }
  11949. json_object_put(StartTransaction);
  11950. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11951. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11952. //-----------Start : write to the Queue TransactionId file -----------------//
  11953. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11954. {}
  11955. else
  11956. {
  11957. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11958. if(log == NULL)
  11959. {
  11960. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11961. return ;
  11962. }
  11963. else
  11964. {
  11965. fclose(log);
  11966. }
  11967. }
  11968. // open file for writing
  11969. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11970. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11971. {
  11972. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11973. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11974. fputs(data, outfile);
  11975. fclose (outfile);
  11976. }
  11977. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11978. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11979. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11980. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11981. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11982. }
  11983. void handleStatusNotificationResponse(char *payload, int gun_index)
  11984. {
  11985. mtrace();
  11986. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11987. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11988. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11989. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11990. }
  11991. void handleStopTransactionnResponse(char *payload, int gun_index)
  11992. {
  11993. mtrace();
  11994. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11995. json_object *StopTransaction;
  11996. StopTransaction = json_tokener_parse(payload);
  11997. if(!is_error(StopTransaction))
  11998. {
  11999. // Optional data
  12000. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12001. {
  12002. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12003. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12005. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12007. }
  12008. }
  12009. json_object_put(StopTransaction);
  12010. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12011. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12012. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12013. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12014. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12015. }
  12016. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12017. {
  12018. mtrace();
  12019. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12020. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12021. }
  12022. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12023. {
  12024. mtrace();
  12025. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12026. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12027. }
  12028. void handleSignCertificateResponse(char *payload, int gun_index)
  12029. {
  12030. mtrace();
  12031. DEBUG_INFO("handleSignCertificateResponse...\n");
  12032. json_object *SignCertificate;
  12033. SignCertificate = json_tokener_parse(payload);
  12034. if(!is_error(SignCertificate))
  12035. {
  12036. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12037. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12038. }
  12039. json_object_put(SignCertificate);
  12040. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12041. }
  12042. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12043. {
  12044. mtrace();
  12045. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12046. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12047. }
  12048. //==========================================
  12049. // Handle Error routine
  12050. //==========================================
  12051. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12052. {
  12053. mtrace();
  12054. #ifdef SystemLogMessage
  12055. DEBUG_INFO("errorCode: %s\n", errorCode);
  12056. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12057. DEBUG_INFO("errorDetails: %s\n", payload);
  12058. #endif
  12059. }
  12060. //===============================================
  12061. // Common routine
  12062. //===============================================
  12063. int initialConfigurationTable(void)
  12064. {
  12065. //clock_t start_t, end_t, total_t;
  12066. FILE *fp;
  12067. FILE *outfile;
  12068. char str[512]={0};
  12069. char sstr[256]={0};
  12070. int c = 0;
  12071. char *loc;
  12072. int confVersion = 6;
  12073. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12074. //start_t = clock();
  12075. //printf("Starting of the program, start_t = %ld\n", start_t);
  12076. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12077. // Check configuration file size is correct
  12078. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12079. {
  12080. struct stat st;
  12081. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12082. if(st.st_size < 3100)
  12083. {
  12084. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12085. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12086. }
  12087. }
  12088. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12089. {
  12090. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12091. if(outfile == NULL)
  12092. {
  12093. DEBUG_INFO("Error opening file\n");
  12094. return FALSE;
  12095. }
  12096. /*Core Profile*/
  12097. //AllowOfflineTxForUnknownId
  12098. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12102. //AuthorizationCacheEnabled
  12103. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12107. //AuthorizeRemoteTxRequests
  12108. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12112. //BlinkRepeat
  12113. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12117. //ClockAlignedDataInterval
  12118. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12122. //ConnectionTimeOut
  12123. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12127. //GetConfigurationMaxKeys
  12128. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12132. // HeartbeatInterval
  12133. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12137. // LightIntensity
  12138. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12142. // LocalAuthorizeOffline
  12143. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12147. // LocalPreAuthorize
  12148. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12152. // MaxEnergyOnInvalidId
  12153. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12157. // MeterValuesAlignedData
  12158. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12162. else
  12163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12165. // MeterValuesAlignedDataMaxLength
  12166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  12170. else
  12171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  12172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12173. // MeterValuesSampledData
  12174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12178. else
  12179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12181. // MeterValuesSampledDataMaxLength
  12182. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  12186. else
  12187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  12188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12189. // MeterValueSampleInterval
  12190. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12194. // MinimumStatusDuration
  12195. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12198. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12200. // NumberOfConnectors
  12201. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12204. {
  12205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12206. }
  12207. else
  12208. {
  12209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12210. }
  12211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12212. // ResetRetries
  12213. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12217. // ConnectorPhaseRotation
  12218. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12222. // ConnectorPhaseRotationMaxLength
  12223. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12227. // StopTransactionOnEVSideDisconnect
  12228. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12232. // StopTransactionOnInvalidId
  12233. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12237. // StopTxnAlignedData
  12238. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12242. // StopTxnAlignedDataMaxLength
  12243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12247. // StopTxnSampledData
  12248. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12252. else
  12253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12255. // StopTxnSampledDataMaxLength
  12256. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12259. {
  12260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12261. }
  12262. else
  12263. {
  12264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12265. }
  12266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12267. // SupportedFeatureProfiles
  12268. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12272. // SupportedFeatureProfilesMaxLength
  12273. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12277. // TransactionMessageAttempts
  12278. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12281. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12283. // TransactionMessageRetryInterval
  12284. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12287. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12289. // UnlockConnectorOnEVSideDisconnect
  12290. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12294. // WebSocketPingInterval
  12295. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12299. // QueueOffLineStartTransactionMessage
  12300. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12304. // AuthorizationKey
  12305. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12309. // SecurityProfile
  12310. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12314. // DefaultPrice
  12315. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12319. // CustomDisplayCostAndPrice
  12320. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12324. // CustomIdleFeeAfterStop
  12325. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12329. // TimeOffset
  12330. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12334. // NextTimeOffsetTransitionDateTime
  12335. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12339. // TimeOffsetNextTransition
  12340. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12344. // Configuration Version
  12345. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12349. //* Local Auth List Management Profile*/
  12350. #if 0
  12351. //For OCTT Test Case
  12352. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12355. #endif
  12356. #if 1
  12357. //LocalAuthListEnabled
  12358. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12362. #endif
  12363. //LocalAuthListMaxLength
  12364. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12368. //SendLocalListMaxLength
  12369. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12373. //ReserveConnectorZeroSupported
  12374. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12378. //* Smart Charging Profile */
  12379. //ChargeProfileMaxStackLevel
  12380. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12384. // ChargingScheduleAllowedChargingRateUnit
  12385. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12389. // ChargingScheduleMaxPeriods
  12390. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12394. // ConnectorSwitch3to1PhaseSupported
  12395. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12399. // MaxChargingProfilesInstalled
  12400. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12404. fclose(outfile);
  12405. }
  12406. else
  12407. {
  12408. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12409. char keystr[60]={0};
  12410. char readonlystr[10]={0};
  12411. char valuestr[256]={0};
  12412. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12413. if(fp == NULL) {
  12414. DEBUG_INFO("Error opening file");
  12415. return FALSE;
  12416. }
  12417. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12418. {
  12419. //DEBUG_INFO("Get Configuration \n");
  12420. if(strlen(str) > 0)
  12421. {
  12422. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12423. //*************************key*********************************/
  12424. if(strstr(str, "key") != NULL)
  12425. {
  12426. loc = strstr(str, "key");
  12427. c = 0;
  12428. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12429. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12430. {
  12431. sstr[c] = loc[strlen("key")+3+c];
  12432. c++;
  12433. }
  12434. sstr[c] = '\0';
  12435. strcpy(keystr,sstr);
  12436. }
  12437. //*************************readonly*********************************/
  12438. if(strstr(str, "readonly") != NULL)
  12439. {
  12440. loc = strstr(str, "readonly");
  12441. c = 0;
  12442. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12443. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12444. {
  12445. sstr[c] = loc[strlen("readonly")+2+c];
  12446. c++;
  12447. }
  12448. sstr[c] = '\0';
  12449. strcpy(readonlystr,sstr);
  12450. }
  12451. //*************************value*********************************/
  12452. if(strstr(str, "value") != NULL)
  12453. {
  12454. loc = strstr(str, "value");
  12455. c = 0;
  12456. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12457. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12458. {
  12459. sstr[c] = loc[strlen("value")+3+c];
  12460. c++;
  12461. }
  12462. sstr[c] = '\0';
  12463. strcpy(valuestr,sstr);
  12464. }
  12465. // DEBUG_INFO("keystr=%s\n",keystr);
  12466. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12467. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12468. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12469. {
  12470. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12471. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12473. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12474. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12475. }
  12476. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12477. {
  12478. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12479. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12481. }
  12482. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12483. {
  12484. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12486. }
  12487. if(strcmp(keystr, "BlinkRepeat") == 0)
  12488. {
  12489. //Charger.BlinkRepeat = Integer.parseInt(value);
  12490. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12492. }
  12493. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12494. {
  12495. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12497. }
  12498. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12499. {
  12500. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12502. }
  12503. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12504. {
  12505. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12507. }
  12508. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12509. {
  12510. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12512. HeartBeatWaitTime = atoi(valuestr);
  12513. }
  12514. if(strcmp(keystr, "LightIntensity") == 0)
  12515. {
  12516. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12518. }
  12519. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12520. {
  12521. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12523. }
  12524. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12525. {
  12526. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12528. }
  12529. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12530. {
  12531. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12533. }
  12534. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12535. {
  12536. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12538. }
  12539. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12540. {
  12541. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12543. }
  12544. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12545. {
  12546. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12548. }
  12549. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12550. {
  12551. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12553. }
  12554. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12555. {
  12556. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12558. }
  12559. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12560. {
  12561. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12563. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12564. }
  12565. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12566. {
  12567. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12569. }
  12570. if(strcmp(keystr, "ResetRetries") == 0)
  12571. {
  12572. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12574. }
  12575. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12576. {
  12577. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12579. }
  12580. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12581. {
  12582. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12584. }
  12585. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12586. {
  12587. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12589. }
  12590. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12591. {
  12592. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12594. }
  12595. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12596. {
  12597. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12599. }
  12600. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12601. {
  12602. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12604. }
  12605. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12606. {
  12607. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12609. }
  12610. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12611. {
  12612. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12614. }
  12615. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12616. {
  12617. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12619. }
  12620. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12621. {
  12622. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12624. }
  12625. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12626. {
  12627. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12629. TransactionMessageAttemptsValue = atoi(valuestr);
  12630. }
  12631. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12632. {
  12633. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12635. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12636. }
  12637. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12638. {
  12639. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12641. }
  12642. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12643. {
  12644. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12646. }
  12647. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12648. {
  12649. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12651. }
  12652. if(strcmp(keystr, "AuthorizationKey") == 0)
  12653. {
  12654. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12655. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12657. }
  12658. if(strcmp(keystr, "SecurityProfile") == 0)
  12659. {
  12660. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12662. }
  12663. if(strcmp(keystr, "DefaultPrice") == 0)
  12664. {
  12665. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12667. }
  12668. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12669. {
  12670. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12672. }
  12673. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12674. {
  12675. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12677. }
  12678. if(strcmp(keystr, "TimeOffset") == 0)
  12679. {
  12680. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12682. }
  12683. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12684. {
  12685. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12687. }
  12688. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12689. {
  12690. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12692. }
  12693. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12694. {
  12695. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12697. }
  12698. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12699. {
  12700. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12702. }
  12703. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12704. {
  12705. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12707. }
  12708. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12709. {
  12710. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12712. }
  12713. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12714. {
  12715. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12717. }
  12718. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12719. {
  12720. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12722. }
  12723. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12724. {
  12725. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12727. }
  12728. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12729. {
  12730. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12732. }
  12733. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12734. {
  12735. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12737. }
  12738. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12739. {
  12740. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12742. }
  12743. }
  12744. }
  12745. fclose(fp);
  12746. }
  12747. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12748. {
  12749. return PASS;
  12750. }
  12751. else
  12752. {
  12753. return FAIL;
  12754. }
  12755. }
  12756. void StoreConfigurationTable(void)
  12757. {
  12758. FILE *outfile;
  12759. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12760. if(outfile == NULL)
  12761. {
  12762. DEBUG_INFO("Error opening file");
  12763. return ;
  12764. }
  12765. /*Core Profile*/
  12766. //AllowOfflineTxForUnknownId
  12767. /*
  12768. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12769. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12772. */
  12773. //DEBUG_INFO("data=%s\n",data);
  12774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12775. //AuthorizationCacheEnabled
  12776. /*
  12777. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12780. */
  12781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12782. //AuthorizeRemoteTxRequests
  12783. /*
  12784. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12787. */
  12788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12789. //BlinkRepeat
  12790. /*
  12791. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12794. */
  12795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12796. //ClockAlignedDataInterval
  12797. /*
  12798. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12801. */
  12802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12803. //ConnectionTimeOut
  12804. /*
  12805. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12808. */
  12809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12810. //GetConfigurationMaxKeys
  12811. /*
  12812. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12815. */
  12816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12817. // HeartbeatInterval
  12818. /*
  12819. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12822. */
  12823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12824. // LightIntensity
  12825. /*
  12826. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12829. */
  12830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12831. // LocalAuthorizeOffline
  12832. /*
  12833. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12836. */
  12837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12838. // LocalPreAuthorize
  12839. /*
  12840. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12843. */
  12844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12845. // MaxEnergyOnInvalidId
  12846. /*
  12847. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12850. */
  12851. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12853. // MeterValuesAlignedData
  12854. /*
  12855. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12858. */
  12859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12860. // MeterValuesAlignedDataMaxLength
  12861. /*
  12862. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12865. */
  12866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12867. // MeterValuesSampledData
  12868. /*
  12869. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12872. */
  12873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12874. // MeterValuesSampledDataMaxLength
  12875. /*
  12876. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12879. */
  12880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12881. // MeterValueSampleInterval
  12882. /*
  12883. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12886. */
  12887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12888. // MinimumStatusDuration
  12889. /*
  12890. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12893. */
  12894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12895. // NumberOfConnectors
  12896. /*
  12897. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12900. {
  12901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12902. }
  12903. else
  12904. {
  12905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12906. }
  12907. */
  12908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12909. // ResetRetries
  12910. /*
  12911. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12914. */
  12915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12916. // ConnectorPhaseRotation
  12917. /*
  12918. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12921. */
  12922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12923. // ConnectorPhaseRotationMaxLength
  12924. /*
  12925. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12928. */
  12929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12930. // StopTransactionOnEVSideDisconnect
  12931. /*
  12932. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12935. */
  12936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12937. // StopTransactionOnInvalidId
  12938. /*
  12939. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12942. */
  12943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12944. // StopTxnAlignedData
  12945. /*
  12946. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12949. */
  12950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12951. // StopTxnAlignedDataMaxLength
  12952. /*
  12953. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12956. */
  12957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12958. // StopTxnSampledData
  12959. /*
  12960. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12963. */
  12964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12965. // StopTxnSampledDataMaxLength
  12966. /*
  12967. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12970. */
  12971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12972. // SupportedFeatureProfiles
  12973. /*
  12974. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12977. */
  12978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12979. // SupportedFeatureProfilesMaxLength
  12980. /*
  12981. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12984. */
  12985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12986. // TransactionMessageAttempts
  12987. /*
  12988. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12991. */
  12992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12993. // TransactionMessageRetryInterval
  12994. /*
  12995. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12998. */
  12999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13000. // UnlockConnectorOnEVSideDisconnect
  13001. /*
  13002. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13005. */
  13006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13007. // WebSocketPingInterval
  13008. /*
  13009. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13012. */
  13013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13014. // QueueOffLineStartTransactionMessage
  13015. /*
  13016. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  13017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  13018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  13019. */
  13020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  13021. // AuthorizationKey
  13022. /*
  13023. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13026. */
  13027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13028. // SecurityProfile
  13029. /*
  13030. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13033. */
  13034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13035. // DefaultPrice
  13036. /*
  13037. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13040. */
  13041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13042. // CustomDisplayCostAndPrice
  13043. /*
  13044. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13047. */
  13048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13049. // CustomIdleFeeAfterStop
  13050. /*
  13051. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13054. */
  13055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13056. // TimeOffset
  13057. /*
  13058. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13061. */
  13062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13063. // NextTimeOffsetTransitionDateTime
  13064. /*
  13065. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13068. */
  13069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13070. // TimeOffsetNextTransition
  13071. /*
  13072. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13075. */
  13076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13077. // ConfigurationVersion
  13078. /*
  13079. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13082. */
  13083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13084. //* Local Auth List Management Profile*/
  13085. //LocalAuthListEnabled
  13086. /*
  13087. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13090. */
  13091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13092. //LocalAuthListMaxLength
  13093. /*
  13094. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13097. */
  13098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13099. //SendLocalListMaxLength
  13100. /*
  13101. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13104. */
  13105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13106. //ReserveConnectorZeroSupported
  13107. /*
  13108. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13111. */
  13112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13113. //* Smart Charging Profile */
  13114. //ChargeProfileMaxStackLevel
  13115. /*
  13116. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13119. */
  13120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13121. // ChargingScheduleAllowedChargingRateUnit
  13122. /*
  13123. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13126. */
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13128. // ChargingScheduleMaxPeriods
  13129. /*
  13130. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13133. */
  13134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13135. // ConnectorSwitch3to1PhaseSupported
  13136. /*
  13137. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13140. */
  13141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13142. // MaxChargingProfilesInstalled
  13143. /*
  13144. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13147. */
  13148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13149. fclose(outfile);
  13150. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13151. }
  13152. void getKeyValue(char *keyReq)
  13153. {
  13154. int isEmpty = FALSE;
  13155. int isKnowKey = FALSE;
  13156. DEBUG_INFO("keyReq = %s\n", keyReq);
  13157. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13158. isEmpty = TRUE;
  13159. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13160. {
  13161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13164. {
  13165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13166. }
  13167. else
  13168. {
  13169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13170. }
  13171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13172. isKnowKey = TRUE;
  13173. }
  13174. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13175. {
  13176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13179. {
  13180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13181. }
  13182. else
  13183. {
  13184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13185. }
  13186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13187. isKnowKey = TRUE;
  13188. }
  13189. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13190. {
  13191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13194. {
  13195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13196. }
  13197. else
  13198. {
  13199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13200. }
  13201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13202. isKnowKey = TRUE;
  13203. }
  13204. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13205. {
  13206. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13209. {
  13210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13211. }
  13212. else
  13213. {
  13214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13215. }
  13216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13217. isKnowKey = TRUE;
  13218. }
  13219. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13220. {
  13221. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13224. {
  13225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13226. }
  13227. else
  13228. {
  13229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13230. }
  13231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13232. isKnowKey = TRUE;
  13233. }
  13234. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13235. {
  13236. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13239. {
  13240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13241. }
  13242. else
  13243. {
  13244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13245. }
  13246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13247. isKnowKey = TRUE;
  13248. }
  13249. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13250. {
  13251. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13254. {
  13255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13256. }
  13257. else
  13258. {
  13259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13260. }
  13261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13262. isKnowKey = TRUE;
  13263. }
  13264. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13265. {
  13266. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13269. {
  13270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13271. }
  13272. else
  13273. {
  13274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13275. }
  13276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13277. isKnowKey = TRUE;
  13278. }
  13279. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13280. {
  13281. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13284. {
  13285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13286. }
  13287. else
  13288. {
  13289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13290. }
  13291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13292. isKnowKey = TRUE;
  13293. }
  13294. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13295. {
  13296. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13299. {
  13300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13301. }
  13302. else
  13303. {
  13304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13305. }
  13306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13307. isKnowKey = TRUE;
  13308. }
  13309. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13310. {
  13311. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13314. {
  13315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13316. }
  13317. else
  13318. {
  13319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13320. }
  13321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13322. isKnowKey = TRUE;
  13323. }
  13324. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13325. {
  13326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13329. {
  13330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13331. }
  13332. else
  13333. {
  13334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13335. }
  13336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13337. isKnowKey = TRUE;
  13338. }
  13339. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13340. {
  13341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13344. {
  13345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13346. }
  13347. else
  13348. {
  13349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13350. }
  13351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13352. isKnowKey = TRUE;
  13353. }
  13354. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13355. {
  13356. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13359. {
  13360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13361. }
  13362. else
  13363. {
  13364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13365. }
  13366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13367. isKnowKey = TRUE;
  13368. }
  13369. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13370. {
  13371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13374. {
  13375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13376. }
  13377. else
  13378. {
  13379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13380. }
  13381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13382. isKnowKey = TRUE;
  13383. }
  13384. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13385. {
  13386. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13388. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13389. {
  13390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13391. }
  13392. else
  13393. {
  13394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13395. }
  13396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13397. isKnowKey = TRUE;
  13398. }
  13399. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13400. {
  13401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13404. {
  13405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13406. }
  13407. else
  13408. {
  13409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13410. }
  13411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13412. isKnowKey = TRUE;
  13413. }
  13414. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13415. {
  13416. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13419. {
  13420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13421. }
  13422. else
  13423. {
  13424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13425. }
  13426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13427. isKnowKey = TRUE;
  13428. }
  13429. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13430. {
  13431. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13434. {
  13435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13436. }
  13437. else
  13438. {
  13439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13440. }
  13441. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13443. isKnowKey = TRUE;
  13444. }
  13445. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13446. {
  13447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13450. {
  13451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13452. }
  13453. else
  13454. {
  13455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13456. }
  13457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13458. isKnowKey = TRUE;
  13459. }
  13460. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13461. {
  13462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13465. {
  13466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13467. }
  13468. else
  13469. {
  13470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13471. }
  13472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13473. isKnowKey = TRUE;
  13474. }
  13475. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13476. {
  13477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13480. {
  13481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13482. }
  13483. else
  13484. {
  13485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13486. }
  13487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13488. isKnowKey = TRUE;
  13489. }
  13490. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13491. {
  13492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13495. {
  13496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13497. }
  13498. else
  13499. {
  13500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13501. }
  13502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13503. isKnowKey = TRUE;
  13504. }
  13505. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13506. {
  13507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13510. {
  13511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13512. }
  13513. else
  13514. {
  13515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13516. }
  13517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13518. isKnowKey = TRUE;
  13519. }
  13520. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13521. {
  13522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13525. {
  13526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13527. }
  13528. else
  13529. {
  13530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13531. }
  13532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13533. isKnowKey = TRUE;
  13534. }
  13535. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13536. {
  13537. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13540. {
  13541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13542. }
  13543. else
  13544. {
  13545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13546. }
  13547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13548. isKnowKey = TRUE;
  13549. }
  13550. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13551. {
  13552. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13555. {
  13556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13557. }
  13558. else
  13559. {
  13560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13561. }
  13562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13563. isKnowKey = TRUE;
  13564. }
  13565. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13566. {
  13567. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13570. {
  13571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13572. }
  13573. else
  13574. {
  13575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13576. }
  13577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13578. isKnowKey = TRUE;
  13579. }
  13580. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13581. {
  13582. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13585. {
  13586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13587. }
  13588. else
  13589. {
  13590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13591. }
  13592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13593. isKnowKey = TRUE;
  13594. }
  13595. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13596. {
  13597. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13599. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13600. {
  13601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13602. }
  13603. else
  13604. {
  13605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13606. }
  13607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13608. isKnowKey = TRUE;
  13609. }
  13610. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13611. {
  13612. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13614. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13615. {
  13616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13617. }
  13618. else
  13619. {
  13620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13621. }
  13622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13623. isKnowKey = TRUE;
  13624. }
  13625. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13626. {
  13627. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13630. {
  13631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13632. }
  13633. else
  13634. {
  13635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13636. }
  13637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13638. isKnowKey = TRUE;
  13639. }
  13640. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13641. {
  13642. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13645. {
  13646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13647. }
  13648. else
  13649. {
  13650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13651. }
  13652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13653. isKnowKey = TRUE;
  13654. }
  13655. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13656. {
  13657. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13660. {
  13661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13662. }
  13663. else
  13664. {
  13665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13666. }
  13667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13668. isKnowKey = TRUE;
  13669. }
  13670. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13671. {
  13672. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13675. {
  13676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13677. }
  13678. else
  13679. {
  13680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13681. }
  13682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13683. isKnowKey = TRUE;
  13684. }
  13685. /*
  13686. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13687. {
  13688. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13691. {
  13692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13693. }
  13694. else
  13695. {
  13696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13697. }
  13698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13699. isKnowKey = TRUE;
  13700. }*/
  13701. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13702. {
  13703. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13706. {
  13707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13708. }
  13709. else
  13710. {
  13711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13712. }
  13713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13714. isKnowKey = TRUE;
  13715. }
  13716. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13717. {
  13718. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13721. {
  13722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13723. }
  13724. else
  13725. {
  13726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13727. }
  13728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13729. isKnowKey = TRUE;
  13730. }
  13731. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13732. {
  13733. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13736. {
  13737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13738. }
  13739. else
  13740. {
  13741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13742. }
  13743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13744. isKnowKey = TRUE;
  13745. }
  13746. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13747. {
  13748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13751. {
  13752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13753. }
  13754. else
  13755. {
  13756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13757. }
  13758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13759. isKnowKey = TRUE;
  13760. }
  13761. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13762. {
  13763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13766. {
  13767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13768. }
  13769. else
  13770. {
  13771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13772. }
  13773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13774. isKnowKey = TRUE;
  13775. }
  13776. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13777. {
  13778. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13781. {
  13782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13783. }
  13784. else
  13785. {
  13786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13787. }
  13788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13789. isKnowKey = TRUE;
  13790. }
  13791. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13792. {
  13793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13796. {
  13797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13798. }
  13799. else
  13800. {
  13801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13802. }
  13803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13804. isKnowKey = TRUE;
  13805. }
  13806. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13807. {
  13808. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13811. {
  13812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13813. }
  13814. else
  13815. {
  13816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13817. }
  13818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13819. isKnowKey = TRUE;
  13820. }
  13821. #if 1
  13822. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13823. {
  13824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13826. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13827. {
  13828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13829. }
  13830. else
  13831. {
  13832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13833. }
  13834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13835. isKnowKey = TRUE;
  13836. }
  13837. #endif
  13838. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13839. {
  13840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13842. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13843. {
  13844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13845. }
  13846. else
  13847. {
  13848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13849. }
  13850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13851. isKnowKey = TRUE;
  13852. }
  13853. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13854. {
  13855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13857. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13858. {
  13859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13860. }
  13861. else
  13862. {
  13863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13864. }
  13865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13866. isKnowKey = TRUE;
  13867. }
  13868. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13869. {
  13870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13872. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13873. {
  13874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13875. }
  13876. else
  13877. {
  13878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13879. }
  13880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13881. isKnowKey = TRUE;
  13882. }
  13883. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13884. {
  13885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13887. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13888. {
  13889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13890. }
  13891. else
  13892. {
  13893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13894. }
  13895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13896. isKnowKey = TRUE;
  13897. }
  13898. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13899. {
  13900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13902. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13903. {
  13904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13905. }
  13906. else
  13907. {
  13908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13909. }
  13910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13911. isKnowKey = TRUE;
  13912. }
  13913. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13914. {
  13915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13917. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13918. {
  13919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13920. }
  13921. else
  13922. {
  13923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13924. }
  13925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13926. isKnowKey = TRUE;
  13927. }
  13928. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13929. {
  13930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13932. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13933. {
  13934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13935. }
  13936. else
  13937. {
  13938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13939. }
  13940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13941. isKnowKey = TRUE;
  13942. }
  13943. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13944. {
  13945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13947. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13948. {
  13949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13950. }
  13951. else
  13952. {
  13953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13954. }
  13955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13956. isKnowKey = TRUE;
  13957. }
  13958. //=========================================================
  13959. if(!isEmpty && !isKnowKey)
  13960. {
  13961. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13962. strcpy(unknownkey[UnknownKeynum], keyReq);
  13963. UnknownKeynum = UnknownKeynum + 1;
  13964. }
  13965. }
  13966. void processUnkownKey(void)
  13967. {
  13968. DEBUG_INFO("processUnkownKey...\n");
  13969. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13970. for(int index=0; index < UnknownKeynum; index++)
  13971. {
  13972. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13973. {
  13974. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13975. }
  13976. }
  13977. }
  13978. int setKeyValue(char *key, char *value)
  13979. {
  13980. int isSuccess = NotSupported;
  13981. int check_ascii=0;
  13982. char str[256]={0};
  13983. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13984. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13985. {
  13986. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13988. {
  13989. strcpy(str, (const char*)value);
  13990. for(int i = 0; str[i]; i++){
  13991. str[i] = tolower(str[i]);
  13992. }
  13993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13994. isSuccess = ConfigurationStatus_Accepted;
  13995. }
  13996. else
  13997. {
  13998. isSuccess = ConfigurationStatus_Rejected;
  13999. }
  14000. }
  14001. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14002. {
  14003. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14005. {
  14006. strcpy(str, (const char*)value);
  14007. for(int i = 0; str[i]; i++){
  14008. str[i] = tolower(str[i]);
  14009. }
  14010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14011. isSuccess = ConfigurationStatus_Accepted;
  14012. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14013. }
  14014. else
  14015. {
  14016. isSuccess = ConfigurationStatus_Rejected;
  14017. }
  14018. }
  14019. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14020. {
  14021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14022. {
  14023. strcpy(str, (const char*)value);
  14024. for(int i = 0; str[i]; i++)
  14025. {
  14026. str[i] = tolower(str[i]);
  14027. }
  14028. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14030. isSuccess = ConfigurationStatus_Accepted;
  14031. }
  14032. else
  14033. {
  14034. isSuccess = ConfigurationStatus_Rejected;
  14035. }
  14036. }
  14037. if(strcmp(key, "BlinkRepeat") == 0)
  14038. {
  14039. //Charger.BlinkRepeat = Integer.parseInt(value);
  14040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14041. {
  14042. check_ascii = value[0];
  14043. if( (check_ascii < 48) || (check_ascii > 57) )
  14044. {
  14045. isSuccess = ConfigurationStatus_Rejected;
  14046. }
  14047. else
  14048. {
  14049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14050. isSuccess = ConfigurationStatus_Accepted;
  14051. }
  14052. }
  14053. else
  14054. {
  14055. isSuccess = ConfigurationStatus_Rejected;
  14056. }
  14057. }
  14058. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14059. {
  14060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14061. {
  14062. check_ascii = value[0];
  14063. if( (check_ascii < 48) || (check_ascii > 57) )
  14064. {
  14065. isSuccess = ConfigurationStatus_Rejected;
  14066. }
  14067. else
  14068. {
  14069. if((atoi(value) == 0) || (atoi(value) >= 10))
  14070. {
  14071. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14073. isSuccess = ConfigurationStatus_Accepted;
  14074. }
  14075. else
  14076. isSuccess = ConfigurationStatus_Rejected;
  14077. }
  14078. }
  14079. else
  14080. {
  14081. isSuccess = ConfigurationStatus_Rejected;
  14082. }
  14083. }
  14084. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14085. {
  14086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14087. {
  14088. check_ascii = value[0];
  14089. if( (check_ascii < 48) || (check_ascii > 57) )
  14090. {
  14091. isSuccess = ConfigurationStatus_Rejected;
  14092. }
  14093. else
  14094. {
  14095. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14097. isSuccess = ConfigurationStatus_Accepted;
  14098. }
  14099. }
  14100. else
  14101. {
  14102. isSuccess = ConfigurationStatus_Rejected;
  14103. }
  14104. }
  14105. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14106. {
  14107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14108. {
  14109. check_ascii = value[0];
  14110. if( (check_ascii < 48) || (check_ascii > 57) )
  14111. {
  14112. isSuccess = ConfigurationStatus_Rejected;
  14113. }
  14114. else
  14115. {
  14116. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14118. isSuccess = ConfigurationStatus_Accepted;
  14119. }
  14120. }
  14121. else
  14122. {
  14123. isSuccess = ConfigurationStatus_Rejected;
  14124. }
  14125. }
  14126. if(strcmp(key, "HeartbeatInterval") == 0)
  14127. {
  14128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14129. {
  14130. check_ascii = value[0];
  14131. if( (check_ascii < 48) || (check_ascii > 57) )
  14132. {
  14133. isSuccess = ConfigurationStatus_Rejected;
  14134. }
  14135. else
  14136. {
  14137. if((atoi(value) == 0) || (atoi(value) >= 10))
  14138. {
  14139. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14141. HeartBeatWaitTime = atoi(value);
  14142. isSuccess = ConfigurationStatus_Accepted;
  14143. }
  14144. else
  14145. {
  14146. isSuccess = ConfigurationStatus_Rejected;
  14147. }
  14148. }
  14149. }
  14150. else
  14151. {
  14152. isSuccess = ConfigurationStatus_Rejected;
  14153. }
  14154. }
  14155. if(strcmp(key, "LightIntensity") == 0)
  14156. {
  14157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14158. {
  14159. check_ascii = value[0];
  14160. if( (check_ascii < 48) || (check_ascii > 57) )
  14161. {
  14162. isSuccess = ConfigurationStatus_Rejected;
  14163. }
  14164. else
  14165. {
  14166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14167. isSuccess = ConfigurationStatus_Accepted;
  14168. }
  14169. }
  14170. else
  14171. {
  14172. isSuccess = ConfigurationStatus_Rejected;
  14173. }
  14174. }
  14175. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14176. {
  14177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14178. {
  14179. strcpy(str, (const char*)value);
  14180. for(int i = 0; str[i]; i++)
  14181. {
  14182. str[i] = tolower(str[i]);
  14183. }
  14184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14185. isSuccess = ConfigurationStatus_Accepted;
  14186. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14187. }
  14188. else
  14189. {
  14190. isSuccess = ConfigurationStatus_Rejected;
  14191. }
  14192. }
  14193. if(strcmp(key, "LocalPreAuthorize") == 0)
  14194. {
  14195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14196. {
  14197. strcpy(str, (const char*)value);
  14198. for(int i = 0; str[i]; i++)
  14199. {
  14200. str[i] = tolower(str[i]);
  14201. }
  14202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14203. isSuccess = ConfigurationStatus_Accepted;
  14204. }
  14205. else
  14206. {
  14207. isSuccess = ConfigurationStatus_Rejected;
  14208. }
  14209. }
  14210. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14211. {
  14212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14213. {
  14214. check_ascii = value[0];
  14215. if( (check_ascii < 48) || (check_ascii > 57) )
  14216. {
  14217. isSuccess = ConfigurationStatus_Rejected;
  14218. }
  14219. else
  14220. {
  14221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14222. isSuccess = ConfigurationStatus_Accepted;
  14223. }
  14224. }
  14225. else
  14226. {
  14227. isSuccess = ConfigurationStatus_Rejected;
  14228. }
  14229. }
  14230. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14231. {
  14232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14233. {
  14234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14235. isSuccess = ConfigurationStatus_Accepted;
  14236. }
  14237. else
  14238. {
  14239. isSuccess = ConfigurationStatus_Rejected;
  14240. }
  14241. }
  14242. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14243. {
  14244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14245. {
  14246. check_ascii = value[0];
  14247. if( (check_ascii < 48) || (check_ascii > 57) )
  14248. {
  14249. isSuccess = ConfigurationStatus_Rejected;
  14250. }
  14251. else
  14252. {
  14253. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14255. isSuccess = ConfigurationStatus_Accepted;
  14256. }
  14257. }
  14258. else
  14259. {
  14260. isSuccess = ConfigurationStatus_Rejected;
  14261. }
  14262. }
  14263. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14264. {
  14265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14266. {
  14267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14268. isSuccess = ConfigurationStatus_Accepted;
  14269. }
  14270. else
  14271. {
  14272. isSuccess = ConfigurationStatus_Rejected;
  14273. }
  14274. }
  14275. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14276. {
  14277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14278. {
  14279. check_ascii = value[0];
  14280. if( (check_ascii < 48) || (check_ascii > 57) )
  14281. {
  14282. isSuccess = ConfigurationStatus_Rejected;
  14283. }
  14284. else
  14285. {
  14286. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14288. isSuccess = ConfigurationStatus_Accepted;
  14289. }
  14290. }
  14291. else
  14292. {
  14293. isSuccess = ConfigurationStatus_Rejected;
  14294. }
  14295. }
  14296. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14297. {
  14298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14299. {
  14300. check_ascii = value[0];
  14301. if( (check_ascii < 48) || (check_ascii > 57) )
  14302. {
  14303. isSuccess = ConfigurationStatus_Rejected;
  14304. }
  14305. else
  14306. {
  14307. if((atoi(value) == 0) || (atoi(value) >= 10))
  14308. {
  14309. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14311. isSuccess = ConfigurationStatus_Accepted;
  14312. }
  14313. else
  14314. {
  14315. isSuccess = ConfigurationStatus_Rejected;
  14316. }
  14317. }
  14318. }
  14319. else
  14320. {
  14321. isSuccess = ConfigurationStatus_Rejected;
  14322. }
  14323. }
  14324. if(strcmp(key, "MinimumStatusDuration") == 0)
  14325. {
  14326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14327. {
  14328. check_ascii = value[0];
  14329. if( (check_ascii < 48) || (check_ascii > 57) )
  14330. {
  14331. isSuccess = ConfigurationStatus_Rejected;
  14332. }
  14333. else
  14334. {
  14335. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14336. {
  14337. isSuccess = ConfigurationStatus_Rejected;
  14338. }
  14339. else
  14340. {
  14341. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14343. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14344. isSuccess = ConfigurationStatus_Accepted;
  14345. }
  14346. }
  14347. }
  14348. else
  14349. {
  14350. isSuccess = ConfigurationStatus_Rejected;
  14351. }
  14352. }
  14353. if(strcmp(key, "NumberOfConnectors") == 0)
  14354. {
  14355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14356. {
  14357. check_ascii = value[0];
  14358. if( (check_ascii < 48) || (check_ascii > 57) )
  14359. {
  14360. isSuccess = ConfigurationStatus_Rejected;
  14361. }
  14362. else
  14363. {
  14364. //Charger.ResetRetries = Integer.parseInt(value);
  14365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14366. isSuccess = ConfigurationStatus_Accepted;
  14367. }
  14368. }
  14369. else
  14370. {
  14371. isSuccess = ConfigurationStatus_Rejected;
  14372. }
  14373. }
  14374. if(strcmp(key, "ResetRetries") == 0)
  14375. {
  14376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14377. {
  14378. check_ascii = value[0];
  14379. if( (check_ascii < 48) || (check_ascii > 57) )
  14380. {
  14381. isSuccess = ConfigurationStatus_Rejected;
  14382. }
  14383. else
  14384. {
  14385. //Charger.ResetRetries = Integer.parseInt(value);
  14386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14387. isSuccess = ConfigurationStatus_Accepted;
  14388. }
  14389. }
  14390. else
  14391. {
  14392. isSuccess = ConfigurationStatus_Rejected;
  14393. }
  14394. }
  14395. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14396. {
  14397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14398. {
  14399. strcpy(str, (const char*)value);
  14400. for(int i = 0; str[i]; i++)
  14401. {
  14402. str[i] = tolower(str[i]);
  14403. }
  14404. if(strcmp(str, "notapplicable")== 0)
  14405. {
  14406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14407. isSuccess = ConfigurationStatus_Accepted;
  14408. }
  14409. else if(strcmp(str, "unknown")== 0)
  14410. {
  14411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14412. isSuccess = ConfigurationStatus_Accepted;
  14413. }
  14414. else if(strcmp(str, "rst")== 0)
  14415. {
  14416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14417. isSuccess = ConfigurationStatus_Accepted;
  14418. }
  14419. else if(strcmp(str, "rts")== 0)
  14420. {
  14421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14422. isSuccess = ConfigurationStatus_Accepted;
  14423. }
  14424. else if(strcmp(str, "srt")== 0)
  14425. {
  14426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14427. isSuccess = ConfigurationStatus_Accepted;
  14428. }
  14429. else if(strcmp(str, "str")== 0)
  14430. {
  14431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14432. isSuccess = ConfigurationStatus_Accepted;
  14433. }
  14434. else if(strcmp(str, "trs")== 0)
  14435. {
  14436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14437. isSuccess = ConfigurationStatus_Accepted;
  14438. }
  14439. else if(strcmp(str, "tsr")== 0)
  14440. {
  14441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14442. isSuccess = ConfigurationStatus_Accepted;
  14443. }
  14444. else
  14445. {
  14446. isSuccess = ConfigurationStatus_Rejected;
  14447. }
  14448. }
  14449. else
  14450. {
  14451. isSuccess = ConfigurationStatus_Rejected;
  14452. }
  14453. }
  14454. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14455. {
  14456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14457. {
  14458. check_ascii = value[0];
  14459. if( (check_ascii < 48) || (check_ascii > 57) )
  14460. {
  14461. isSuccess = ConfigurationStatus_Rejected;
  14462. }
  14463. else
  14464. {
  14465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14466. isSuccess = ConfigurationStatus_Accepted;
  14467. }
  14468. }
  14469. else
  14470. {
  14471. isSuccess = ConfigurationStatus_Rejected;
  14472. }
  14473. }
  14474. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14475. {
  14476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14477. {
  14478. strcpy(str, (const char*)value);
  14479. for(int i = 0; str[i]; i++)
  14480. {
  14481. str[i] = tolower(str[i]);
  14482. }
  14483. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14485. isSuccess = ConfigurationStatus_Accepted;
  14486. }
  14487. else
  14488. {
  14489. isSuccess = ConfigurationStatus_Rejected;
  14490. }
  14491. }
  14492. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14493. {
  14494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14495. {
  14496. strcpy(str, (const char*)value);
  14497. for(int i = 0; str[i]; i++)
  14498. {
  14499. str[i] = tolower(str[i]);
  14500. }
  14501. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14503. isSuccess = ConfigurationStatus_Accepted;
  14504. }
  14505. else
  14506. {
  14507. isSuccess = ConfigurationStatus_Rejected;
  14508. }
  14509. }
  14510. if(strcmp(key, "StopTxnAlignedData") == 0)
  14511. {
  14512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14513. {
  14514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14515. isSuccess = ConfigurationStatus_Accepted;
  14516. }
  14517. else
  14518. {
  14519. isSuccess = ConfigurationStatus_Rejected;
  14520. }
  14521. }
  14522. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14523. {
  14524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14525. {
  14526. check_ascii = value[0];
  14527. if( (check_ascii < 48) || (check_ascii > 57) )
  14528. {
  14529. isSuccess = ConfigurationStatus_Rejected;
  14530. }
  14531. else
  14532. {
  14533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14534. isSuccess = ConfigurationStatus_Accepted;
  14535. }
  14536. }
  14537. else
  14538. {
  14539. isSuccess = ConfigurationStatus_Rejected;
  14540. }
  14541. }
  14542. if(strcmp(key, "StopTxnSampledData") == 0)
  14543. {
  14544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14545. {
  14546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14547. isSuccess = ConfigurationStatus_Accepted;
  14548. }
  14549. else
  14550. {
  14551. isSuccess = ConfigurationStatus_Rejected;
  14552. }
  14553. }
  14554. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14555. {
  14556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14557. {
  14558. check_ascii = value[0];
  14559. if( (check_ascii < 48) || (check_ascii > 57) )
  14560. {
  14561. isSuccess = ConfigurationStatus_Rejected;
  14562. }
  14563. else
  14564. {
  14565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14566. isSuccess = ConfigurationStatus_Accepted;
  14567. }
  14568. }
  14569. else
  14570. {
  14571. isSuccess = ConfigurationStatus_Rejected;
  14572. }
  14573. }
  14574. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14575. {
  14576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14577. {
  14578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14579. isSuccess = ConfigurationStatus_Accepted;
  14580. }
  14581. else
  14582. {
  14583. isSuccess = ConfigurationStatus_Rejected;
  14584. }
  14585. }
  14586. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14587. {
  14588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14589. {
  14590. check_ascii = value[0];
  14591. if( (check_ascii < 48) || (check_ascii > 57) )
  14592. {
  14593. isSuccess = ConfigurationStatus_Rejected;
  14594. }
  14595. else
  14596. {
  14597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14598. isSuccess = ConfigurationStatus_Accepted;
  14599. }
  14600. }
  14601. else
  14602. {
  14603. isSuccess = ConfigurationStatus_Rejected;
  14604. }
  14605. }
  14606. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14607. {
  14608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14609. {
  14610. check_ascii = value[0];
  14611. if( (check_ascii < 48) || (check_ascii > 57) )
  14612. {
  14613. isSuccess = ConfigurationStatus_Rejected;
  14614. }
  14615. else
  14616. {
  14617. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14619. TransactionMessageAttemptsValue = atoi(value);
  14620. isSuccess = ConfigurationStatus_Accepted;
  14621. }
  14622. }
  14623. else
  14624. {
  14625. isSuccess = ConfigurationStatus_Rejected;
  14626. }
  14627. }
  14628. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14629. {
  14630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14631. {
  14632. check_ascii = value[0];
  14633. if( (check_ascii < 48) || (check_ascii > 57) )
  14634. {
  14635. isSuccess = ConfigurationStatus_Rejected;
  14636. }
  14637. else
  14638. {
  14639. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14641. TransactionMessageRetryIntervalValue = atoi(value);
  14642. isSuccess = ConfigurationStatus_Accepted;
  14643. }
  14644. }
  14645. else
  14646. {
  14647. isSuccess = ConfigurationStatus_Rejected;
  14648. }
  14649. }
  14650. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14651. {
  14652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14653. {
  14654. strcpy(str, (const char*)value);
  14655. for(int i = 0; str[i]; i++)
  14656. {
  14657. str[i] = tolower(str[i]);
  14658. }
  14659. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14661. isSuccess = ConfigurationStatus_Accepted;
  14662. }
  14663. else
  14664. {
  14665. isSuccess = ConfigurationStatus_Rejected;
  14666. }
  14667. }
  14668. if(strcmp(key, "WebSocketPingInterval") == 0)
  14669. {
  14670. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14671. {
  14672. check_ascii = value[0];
  14673. if( (check_ascii < 48) || (check_ascii > 57) )
  14674. {
  14675. isSuccess = ConfigurationStatus_Rejected;
  14676. }
  14677. else
  14678. {
  14679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14680. isSuccess = ConfigurationStatus_Accepted;
  14681. }
  14682. }
  14683. else
  14684. {
  14685. isSuccess = ConfigurationStatus_Rejected;
  14686. }
  14687. }
  14688. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14689. {
  14690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14691. {
  14692. strcpy(str, (const char*)value);
  14693. for(int i = 0; str[i]; i++)
  14694. {
  14695. str[i] = tolower(str[i]);
  14696. }
  14697. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14699. isSuccess = ConfigurationStatus_Accepted;
  14700. }
  14701. else
  14702. {
  14703. isSuccess = ConfigurationStatus_Rejected;
  14704. }
  14705. }
  14706. if(strcmp(key, "AuthorizationKey") == 0)
  14707. {
  14708. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14709. {
  14710. strcpy(str, (const char*)value);
  14711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14712. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14713. isSuccess = ConfigurationStatus_Accepted;
  14714. }
  14715. else
  14716. {
  14717. isSuccess = ConfigurationStatus_Rejected;
  14718. }
  14719. }
  14720. if(strcmp(key, "SecurityProfile") == 0)
  14721. {
  14722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14723. {
  14724. check_ascii = value[0];
  14725. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14726. {
  14727. isSuccess = ConfigurationStatus_Rejected;
  14728. }
  14729. else if(check_ascii == 0x33)
  14730. {
  14731. isSuccess = NotSupported;
  14732. }
  14733. else
  14734. {
  14735. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14736. {
  14737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14738. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14739. isSuccess = ConfigurationStatus_Accepted;
  14740. }
  14741. else
  14742. isSuccess = ConfigurationStatus_Rejected;
  14743. }
  14744. }
  14745. else
  14746. {
  14747. isSuccess = ConfigurationStatus_Rejected;
  14748. }
  14749. }
  14750. if(strcmp(key, "DefaultPrice") == 0)
  14751. {
  14752. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14753. {
  14754. strcpy(str, (const char*)value);
  14755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14756. isSuccess = ConfigurationStatus_Accepted;
  14757. }
  14758. else
  14759. {
  14760. isSuccess = ConfigurationStatus_Rejected;
  14761. }
  14762. }
  14763. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14764. {
  14765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14766. {
  14767. strcpy(str, (const char*)value);
  14768. for(int i = 0; str[i]; i++)
  14769. {
  14770. str[i] = tolower(str[i]);
  14771. }
  14772. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14774. isSuccess = ConfigurationStatus_Accepted;
  14775. }
  14776. else
  14777. {
  14778. isSuccess = ConfigurationStatus_Rejected;
  14779. }
  14780. }
  14781. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14782. {
  14783. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14784. {
  14785. strcpy(str, (const char*)value);
  14786. for(int i = 0; str[i]; i++)
  14787. {
  14788. str[i] = tolower(str[i]);
  14789. }
  14790. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14792. isSuccess = ConfigurationStatus_Accepted;
  14793. }
  14794. else
  14795. {
  14796. isSuccess = ConfigurationStatus_Rejected;
  14797. }
  14798. }
  14799. if(strcmp(key, "TimeOffset") == 0)
  14800. {
  14801. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14802. {
  14803. strcpy(str, (const char*)value);
  14804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14805. isSuccess = ConfigurationStatus_Accepted;
  14806. }
  14807. else
  14808. {
  14809. isSuccess = ConfigurationStatus_Rejected;
  14810. }
  14811. }
  14812. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14813. {
  14814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14815. {
  14816. strcpy(str, (const char*)value);
  14817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14818. isSuccess = ConfigurationStatus_Accepted;
  14819. }
  14820. else
  14821. {
  14822. isSuccess = ConfigurationStatus_Rejected;
  14823. }
  14824. }
  14825. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14826. {
  14827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14828. {
  14829. strcpy(str, (const char*)value);
  14830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14831. isSuccess = ConfigurationStatus_Accepted;
  14832. }
  14833. else
  14834. {
  14835. isSuccess = ConfigurationStatus_Rejected;
  14836. }
  14837. }
  14838. #if 0
  14839. //For OCPP Test Case
  14840. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14841. {
  14842. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14843. {
  14844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14845. isSuccess = ConfigurationStatus_Accepted;
  14846. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14847. }
  14848. else
  14849. {
  14850. isSuccess = ConfigurationStatus_Rejected;
  14851. }
  14852. }
  14853. #endif
  14854. #if 1
  14855. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14856. {
  14857. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14858. {
  14859. strcpy(str, (const char*)value);
  14860. for(int i = 0; str[i]; i++)
  14861. {
  14862. str[i] = tolower(str[i]);
  14863. }
  14864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14865. isSuccess = ConfigurationStatus_Accepted;
  14866. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14867. }
  14868. else
  14869. {
  14870. isSuccess = ConfigurationStatus_Rejected;
  14871. }
  14872. }
  14873. #endif
  14874. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14875. {
  14876. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14877. {
  14878. check_ascii = value[0];
  14879. if( (check_ascii < 48) || (check_ascii > 57) )
  14880. {
  14881. isSuccess = ConfigurationStatus_Rejected;
  14882. }
  14883. else
  14884. {
  14885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14886. isSuccess = ConfigurationStatus_Accepted;
  14887. }
  14888. }
  14889. else
  14890. {
  14891. isSuccess = ConfigurationStatus_Rejected;
  14892. }
  14893. }
  14894. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14895. {
  14896. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14897. {
  14898. check_ascii = value[0];
  14899. if( (check_ascii < 48) || (check_ascii > 57) )
  14900. {
  14901. isSuccess = ConfigurationStatus_Rejected;
  14902. }
  14903. else
  14904. {
  14905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14906. isSuccess = ConfigurationStatus_Accepted;
  14907. }
  14908. }
  14909. else
  14910. {
  14911. isSuccess = ConfigurationStatus_Rejected;
  14912. }
  14913. }
  14914. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14915. {
  14916. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14917. {
  14918. strcpy(str, (const char*)value);
  14919. for(int i = 0; str[i]; i++)
  14920. {
  14921. str[i] = tolower(str[i]);
  14922. }
  14923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14924. isSuccess = ConfigurationStatus_Accepted;
  14925. }
  14926. else
  14927. {
  14928. isSuccess = ConfigurationStatus_Rejected;
  14929. }
  14930. }
  14931. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14932. {
  14933. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14934. {
  14935. check_ascii = value[0];
  14936. if( (check_ascii < 48) || (check_ascii > 57) )
  14937. {
  14938. isSuccess = ConfigurationStatus_Rejected;
  14939. }
  14940. else
  14941. {
  14942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14943. isSuccess = ConfigurationStatus_Accepted;
  14944. }
  14945. }
  14946. else
  14947. {
  14948. isSuccess = ConfigurationStatus_Rejected;
  14949. }
  14950. }
  14951. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14952. {
  14953. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14954. {
  14955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14956. isSuccess = ConfigurationStatus_Accepted;
  14957. }
  14958. else
  14959. {
  14960. isSuccess = ConfigurationStatus_Rejected;
  14961. }
  14962. }
  14963. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14964. {
  14965. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14966. {
  14967. check_ascii = value[0];
  14968. if( (check_ascii < 48) || (check_ascii > 57) )
  14969. {
  14970. isSuccess = ConfigurationStatus_Rejected;
  14971. }
  14972. else
  14973. {
  14974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14975. isSuccess = ConfigurationStatus_Accepted;
  14976. }
  14977. }
  14978. else
  14979. {
  14980. isSuccess = ConfigurationStatus_Rejected;
  14981. }
  14982. }
  14983. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14984. {
  14985. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14986. {
  14987. strcpy(str, (const char*)value);
  14988. for(int i = 0; str[i]; i++)
  14989. {
  14990. str[i] = tolower(str[i]);
  14991. }
  14992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14993. isSuccess = ConfigurationStatus_Accepted;
  14994. }
  14995. else
  14996. {
  14997. isSuccess = ConfigurationStatus_Rejected;
  14998. }
  14999. }
  15000. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15001. {
  15002. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15003. {
  15004. check_ascii = value[0];
  15005. if( (check_ascii < 48) || (check_ascii > 57) )
  15006. {
  15007. isSuccess = ConfigurationStatus_Rejected;
  15008. }
  15009. else
  15010. {
  15011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15012. isSuccess = ConfigurationStatus_Accepted;
  15013. }
  15014. }
  15015. else
  15016. {
  15017. isSuccess = ConfigurationStatus_Rejected;
  15018. }
  15019. }
  15020. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15021. return isSuccess;
  15022. }
  15023. int TransactionMessageAttemptsGet(void)
  15024. {
  15025. return TransactionMessageAttemptsValue;
  15026. }
  15027. int FirstHeartBeatResponse(void)
  15028. {
  15029. return FirstHeartBeat;
  15030. }
  15031. int TransactionMessageRetryIntervalGet(void)
  15032. {
  15033. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15034. }
  15035. int ReadHttpStatus(int sock)
  15036. {
  15037. //char c;
  15038. char buff[1024]="",*ptr=buff+1;
  15039. int bytes_received, status;
  15040. DEBUG_INFO("Begin Response ..\n");
  15041. while((bytes_received = recv(sock, ptr, 1, 0))){
  15042. if(bytes_received==-1){
  15043. perror("ReadHttpStatus");
  15044. exit(1);
  15045. }
  15046. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15047. ptr++;
  15048. }
  15049. *ptr=0;
  15050. ptr=buff+1;
  15051. sscanf(ptr,"%*s %d ", &status);
  15052. DEBUG_INFO("%s\n",ptr);
  15053. DEBUG_INFO("status=%d\n",status);
  15054. DEBUG_INFO("End Response ..\n");
  15055. return (bytes_received>0)?status:0;
  15056. }
  15057. //the only filed that it parsed is 'Content-Length'
  15058. int ParseHeader(int sock)
  15059. {
  15060. //char c;
  15061. char buff[1024]="",*ptr=buff+4;
  15062. int bytes_received;
  15063. DEBUG_INFO("Begin HEADER ..\n");
  15064. while((bytes_received = recv(sock, ptr, 1, 0))){
  15065. if(bytes_received==-1){
  15066. perror("Parse Header");
  15067. exit(1);
  15068. }
  15069. if(
  15070. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15071. (ptr[-1]=='\r') && (*ptr=='\n' )
  15072. ) break;
  15073. ptr++;
  15074. }
  15075. *ptr=0;
  15076. ptr=buff+4;
  15077. //printf("%s",ptr);
  15078. if(bytes_received){
  15079. ptr=strstr(ptr,"Content-Length:");
  15080. if(ptr){
  15081. sscanf(ptr,"%*s %d",&bytes_received);
  15082. }else
  15083. bytes_received=-1; //unknown size
  15084. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15085. }
  15086. DEBUG_INFO("End HEADER ..\n");
  15087. return bytes_received ;
  15088. }
  15089. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15090. {
  15091. int result = TRUE;
  15092. char rmFileCmd[100]={0};
  15093. char FilePath[100]={0};
  15094. char ftpbuf[200];
  15095. int systemresult;
  15096. //DEBUG_INFO("filename=%s\n",filename);
  15097. //DEBUG_INFO("url=%s\n",url);
  15098. sprintf(FilePath,"/mnt/%s",filename);
  15099. system("ping 8.8.8.8 &");
  15100. if((access(FilePath,F_OK))!=-1)
  15101. {
  15102. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15103. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15104. system(rmFileCmd);
  15105. }
  15106. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15107. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15108. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15109. systemresult = system(ftpbuf);
  15110. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15111. if(systemresult != 0)
  15112. {
  15113. DEBUG_INFO("http DownLoad error!\n");
  15114. result = FALSE;
  15115. }
  15116. system("pkill ping");
  15117. return result;
  15118. }
  15119. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15120. {
  15121. int result = TRUE;
  15122. char rmFileCmd[100]={0};
  15123. char FilePath[100]={0};
  15124. char ftpbuf[200];
  15125. int systemresult;
  15126. //char temp[100];
  15127. sprintf(FilePath,"/mnt/%s",filename);
  15128. system("ping 8.8.8.8 &");
  15129. if((access(FilePath,F_OK))!=-1)
  15130. {
  15131. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15132. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15133. system(rmFileCmd);
  15134. }
  15135. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15136. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15137. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  15138. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15139. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15140. systemresult = system(ftpbuf);
  15141. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15142. if(systemresult != 0)
  15143. {
  15144. DEBUG_WARN("wget error!\n");
  15145. result = FALSE;
  15146. }
  15147. system("pkill ping");
  15148. return result;
  15149. }
  15150. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15151. {
  15152. char rmFileCmd[100]={0};
  15153. char FilePath[100]={0};
  15154. char buf[512];
  15155. int systemresult = 0;
  15156. //DEBUG_INFO("filename=%s\n",filename);
  15157. //DEBUG_INFO("url=%s\n",url);
  15158. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15159. if((access(FilePath,F_OK))!=-1)
  15160. {
  15161. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15162. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15163. system(rmFileCmd);
  15164. }
  15165. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15166. if(fp == NULL)
  15167. {
  15168. DEBUG_INFO("log is NULL\n");
  15169. return FALSE;
  15170. }
  15171. else
  15172. {
  15173. fprintf(fp, "%s\n", url);
  15174. fprintf(fp, "%s\n", filename);
  15175. fclose(fp);
  15176. }
  15177. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15178. if(phpFP == NULL)
  15179. {
  15180. DEBUG_INFO("PHP upload fail.\n");
  15181. return FALSE;
  15182. }
  15183. else
  15184. {
  15185. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15186. {
  15187. if(strstr(buf, "result") != NULL)
  15188. {
  15189. sscanf(buf, "result: %d", &systemresult);
  15190. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15191. }
  15192. }
  15193. pclose(phpFP);
  15194. }
  15195. if(systemresult != 1)
  15196. {
  15197. DEBUG_INFO("HTTP upload error!\n");
  15198. return FALSE;
  15199. }
  15200. return TRUE;
  15201. }
  15202. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15203. {
  15204. struct hostent* server;
  15205. char *IPbuffer;
  15206. char ftpbuf[200];
  15207. int systemresult;
  15208. // To retrieve host information
  15209. server = gethostbyname(location);
  15210. // To convert an Internet network
  15211. // address into ASCII string
  15212. IPbuffer = inet_ntoa(*((struct in_addr*)
  15213. server->h_addr_list[0]));
  15214. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15215. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15216. /* format : ftpput -u username -p passwd IP target source*/
  15217. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15218. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15219. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15220. systemresult = system(ftpbuf);
  15221. DEBUG_INFO("systemresult=%d\n",systemresult);
  15222. if(systemresult != 0)
  15223. {
  15224. DEBUG_INFO("ftpput error!\n");
  15225. return FALSE;
  15226. }
  15227. return TRUE;
  15228. }
  15229. int GetOcppServerURL()
  15230. {
  15231. int result = FALSE;
  15232. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15233. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15234. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15235. struct yuarel url;
  15236. char urlStr[512];
  15237. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15238. {
  15239. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15240. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15241. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15242. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15243. if(yuarel_parse(&url, urlStr) != -1)
  15244. {
  15245. sprintf(OcppProtocol, "%s", url.scheme);
  15246. sprintf(OcppHost, "%s", url.host);
  15247. if(url.path == NULL)
  15248. OcppTempPath[0] = '\0';
  15249. else
  15250. {
  15251. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15252. {
  15253. sprintf(OcppTempPath, "%s/", url.path);
  15254. }
  15255. else
  15256. {
  15257. sprintf(OcppTempPath, "%s", url.path);
  15258. }
  15259. }
  15260. if(url.port == 0)
  15261. {
  15262. if(strcmp(OcppProtocol, "wss") == 0)
  15263. OcppPort = 443;
  15264. else
  15265. OcppPort = 80;
  15266. }
  15267. else
  15268. OcppPort = url.port;
  15269. result = TRUE;
  15270. }
  15271. }
  15272. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15273. {
  15274. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15275. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15276. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15277. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15278. if(yuarel_parse(&url, urlStr) != -1)
  15279. {
  15280. sprintf(OcppProtocol, "%s", url.scheme);
  15281. sprintf(OcppHost, "%s", url.host);
  15282. if(url.path == NULL)
  15283. OcppTempPath[0] = '\0';
  15284. else
  15285. sprintf(OcppTempPath, "%s", url.path);
  15286. if(url.port == 0)
  15287. {
  15288. if(strcmp(OcppProtocol, "wss") == 0)
  15289. OcppPort = 443;
  15290. else
  15291. OcppPort = 80;
  15292. }
  15293. else
  15294. OcppPort = url.port;
  15295. result = TRUE;
  15296. }
  15297. }
  15298. else
  15299. {
  15300. strcpy(OcppHost,"");
  15301. }
  15302. return result;
  15303. }
  15304. int GetOcppPath()
  15305. {
  15306. int result = FALSE;
  15307. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15308. {
  15309. if(OcppTempPath == NULL)
  15310. {
  15311. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15312. }
  15313. else
  15314. {
  15315. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15316. }
  15317. result = TRUE;
  15318. goto End;
  15319. }
  15320. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15321. {
  15322. if(OcppTempPath == NULL)
  15323. {
  15324. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15325. }
  15326. else
  15327. {
  15328. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15329. }
  15330. result = TRUE;
  15331. goto End;
  15332. }
  15333. else
  15334. {
  15335. strcpy(OcppPath,"");
  15336. }
  15337. End:
  15338. return result;
  15339. }
  15340. int GetOcppPort()
  15341. {
  15342. return OcppPort;
  15343. }
  15344. int GetOcppConnStatus(void)
  15345. {
  15346. return ShmOCPP16Data->OcppConnStatus;
  15347. }
  15348. void SetOcppConnStatus(uint8_t status)
  15349. {
  15350. ShmOCPP16Data->OcppConnStatus = status;
  15351. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15352. }
  15353. int GetHeartBeatWithNOResponse(void)
  15354. {
  15355. return HeartBeatWithNOResponse;
  15356. }
  15357. void SetHeartBeatWithNOResponse(void)
  15358. {
  15359. HeartBeatWithNOResponse = 0;
  15360. }
  15361. void GetStartTransactionIdTag(int gun_index)
  15362. {
  15363. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15364. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15365. }
  15366. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15367. {
  15368. char ch;
  15369. FILE *fptr1;
  15370. int temptransactionId;
  15371. char str[100]={0};
  15372. temptransactionId = 0;
  15373. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15374. {
  15375. DEBUG_INFO("IdTag is empty.\n");
  15376. return temptransactionId;
  15377. }
  15378. /*------ Read the file ----------------*/
  15379. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15380. if (!fptr1)
  15381. {
  15382. DEBUG_INFO("QueueTransactionId file open error.\n");
  15383. //printf(" File not found or unable to open the input file!!\n");
  15384. return temptransactionId;
  15385. }
  15386. ch=fgetc(fptr1);
  15387. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15388. rewind(fptr1);
  15389. if(ch!=EOF)
  15390. {
  15391. // printf("%c",ch);
  15392. while (fgets(str, 100, fptr1) != NULL)
  15393. {
  15394. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15395. if(str[0]=='\0')
  15396. {
  15397. break;
  15398. }
  15399. char *revbuf[8] = {0}; // Variable store string split
  15400. int num = 0;// Quantity after string split
  15401. DEBUG_INFO("Transaction queue data= %s\n", str);
  15402. splitstring(str,",",revbuf,&num); // String split
  15403. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15404. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15405. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15406. DEBUG_INFO("------------------------------\n");
  15407. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15408. {
  15409. if(isStopTransaction)
  15410. {
  15411. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15412. {
  15413. temptransactionId = atoi(revbuf[2]);
  15414. //break;
  15415. }
  15416. }
  15417. else
  15418. {
  15419. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15420. {
  15421. temptransactionId = atoi(revbuf[2]);
  15422. //break;
  15423. }
  15424. }
  15425. }
  15426. }
  15427. }
  15428. else
  15429. DEBUG_INFO("EOF\n");
  15430. fclose(fptr1);
  15431. /*------- End of reading ---------------*/
  15432. return temptransactionId;
  15433. }
  15434. void SetTransactionIdZero(int transactionId)
  15435. {
  15436. char ch;
  15437. FILE *fptr1, *fptr2;
  15438. int temptransactionId = 0;
  15439. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15440. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15441. if (!fptr1)
  15442. {
  15443. //printf(" File not found or unable to open the input file!!\n");
  15444. return ;
  15445. }
  15446. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15447. if (!fptr2)
  15448. {
  15449. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15450. fclose(fptr1);
  15451. return ;
  15452. }
  15453. ch=fgetc(fptr1);
  15454. rewind(fptr1);
  15455. if(ch!=EOF)
  15456. {
  15457. // copy all contents to the temporary file except the specific line
  15458. while (fgets(str, 100, fptr1) != NULL)
  15459. {
  15460. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15461. if(str[0]=='\0')
  15462. {
  15463. break;
  15464. }
  15465. char *revbuf[8] = {0};
  15466. int num = 0;
  15467. strcpy(strtemp, str);
  15468. splitstring(str,",",revbuf,&num);
  15469. if(revbuf[2][0] != '\0')
  15470. {
  15471. temptransactionId = atoi(revbuf[2]);
  15472. if(transactionId != temptransactionId)
  15473. {
  15474. fprintf(fptr2, "%s\n", strtemp);
  15475. }
  15476. }
  15477. }
  15478. }
  15479. fclose(fptr1);
  15480. fclose(fptr2);
  15481. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15482. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15483. /*------ Read the file ----------------*/
  15484. }
  15485. int InternetDisconnect(void)
  15486. {
  15487. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15488. }
  15489. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15490. void storeTempStopTransaction(int gun_index)
  15491. {
  15492. char guid[37]={0};
  15493. int tempIndex = 0;
  15494. char TempStopTransaction[256];
  15495. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15496. DEBUG_INFO("storeTempStopTransaction...\n");
  15497. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15498. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15499. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15500. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15501. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15502. {
  15503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15504. {
  15505. tempIndex = ((gun_index==2) ? 1: 0);
  15506. }
  15507. else
  15508. {
  15509. tempIndex = gun_index;
  15510. }
  15511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15512. {
  15513. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15514. {
  15515. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15516. }
  15517. }// END OF CHAdeMO_QUANTITY
  15518. }
  15519. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15520. {
  15521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15522. {
  15523. tempIndex = ((gun_index==2) ? 1: 0);
  15524. }
  15525. else
  15526. {
  15527. tempIndex = gun_index;
  15528. }
  15529. for (int index = 0; index < CCS_QUANTITY; index++)
  15530. {
  15531. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15532. {
  15533. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15534. }
  15535. }// END OF CCS_QUANTITY
  15536. }
  15537. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15538. {
  15539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15540. {
  15541. tempIndex = ((gun_index==2) ? 1: 0);
  15542. }
  15543. else
  15544. {
  15545. tempIndex = gun_index;
  15546. }
  15547. for (int index = 0; index < GB_QUANTITY; index++)
  15548. {
  15549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15550. {
  15551. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15552. }
  15553. }// END OF GB_QUANTITY
  15554. }
  15555. else if(gunType[gun_index] == GUN_TYPE_DO)
  15556. {
  15557. tempIndex = gun_index;
  15558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15559. {
  15560. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15561. {
  15562. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15563. }
  15564. }
  15565. }
  15566. else
  15567. {
  15568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15569. {
  15570. tempIndex = 2;
  15571. }
  15572. else
  15573. {
  15574. tempIndex = gun_index;
  15575. }
  15576. for (int index = 0; index < AC_QUANTITY; index++)
  15577. {
  15578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15579. {
  15580. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15581. }
  15582. }// END OF AC_QUANTITY
  15583. }
  15584. //Stop Transaction Time
  15585. struct timeval tmnow;
  15586. struct tm *tm;
  15587. char buf[28];//, usec_buf[6];
  15588. gettimeofday(&tmnow, NULL);
  15589. time_t t;
  15590. t = time(NULL);
  15591. /*UTC time and date*/
  15592. tm = gmtime(&t);
  15593. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15595. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15597. random_uuid(guid);
  15598. /***********************************transactionData******************************************************/
  15599. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15601. //=================================
  15602. //1. Transaction_Begin
  15603. //=================================
  15604. //============================== Energy.Active.Import.Interval ===========================================
  15605. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15606. {
  15607. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15610. 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*/]);
  15611. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15612. 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))
  15613. {
  15614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15615. }
  15616. else
  15617. {
  15618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15619. }
  15620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15622. }
  15623. //=================================
  15624. //2. Transaction_End
  15625. //=================================
  15626. //2.1====================================== Current.Import L1 ==============================================
  15627. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15628. {
  15629. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15630. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15631. {
  15632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15633. {
  15634. tempIndex = ((gun_index==2) ? 1: 0);
  15635. }
  15636. else
  15637. {
  15638. tempIndex = gun_index;
  15639. }
  15640. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15641. {
  15642. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15643. {
  15644. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15645. }
  15646. }// End of for CHAdeMO_QUANTITY
  15647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15648. }
  15649. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15650. {
  15651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15652. {
  15653. tempIndex = ((gun_index==2) ? 1: 0);
  15654. }
  15655. else
  15656. {
  15657. tempIndex = gun_index;
  15658. }
  15659. for (int index = 0; index < CCS_QUANTITY; index++)
  15660. {
  15661. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15662. {
  15663. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15664. }
  15665. }// End of for CCS_QUANTITY
  15666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15667. }
  15668. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15669. {
  15670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15671. {
  15672. tempIndex = ((gun_index==2) ? 1: 0);
  15673. }
  15674. else
  15675. {
  15676. tempIndex = gun_index;
  15677. }
  15678. for (int index = 0; index < GB_QUANTITY; index++)
  15679. {
  15680. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15681. {
  15682. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15683. }
  15684. }// End of for GB_QUANTITY
  15685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15686. }
  15687. else if(gunType[gun_index] == GUN_TYPE_DO)
  15688. {
  15689. tempIndex = gun_index;
  15690. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15691. {
  15692. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15693. {
  15694. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15695. }
  15696. }
  15697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15698. }
  15699. else
  15700. {
  15701. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15702. {
  15703. tempIndex = 2;
  15704. }
  15705. else
  15706. {
  15707. tempIndex = gun_index;
  15708. }
  15709. for (int index = 0; index < AC_QUANTITY; index++)
  15710. {
  15711. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15712. {
  15713. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15714. }
  15715. }// End of for AC_QUANTITY
  15716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15717. }
  15718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15721. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15724. }
  15725. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15726. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15727. {
  15728. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15729. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15730. {
  15731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15732. {
  15733. tempIndex = ((gun_index==2) ? 1: 0);
  15734. }
  15735. else
  15736. {
  15737. tempIndex = gun_index;
  15738. }
  15739. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15740. {
  15741. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15742. {
  15743. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15744. }
  15745. }// END OF CHAdeMO_QUANTITY
  15746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15747. }
  15748. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15749. {
  15750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15751. {
  15752. tempIndex = ((gun_index==2) ? 1: 0);
  15753. }
  15754. else
  15755. {
  15756. tempIndex = gun_index;
  15757. }
  15758. for (int index = 0; index < CCS_QUANTITY; index++)
  15759. {
  15760. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15761. {
  15762. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15763. }
  15764. }// END OF CCS_QUANTITY
  15765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15766. }
  15767. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15768. {
  15769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15770. {
  15771. tempIndex = ((gun_index==2) ? 1: 0);
  15772. }
  15773. else
  15774. {
  15775. tempIndex = gun_index;
  15776. }
  15777. for (int index = 0; index < GB_QUANTITY; index++)
  15778. {
  15779. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15780. {
  15781. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15782. }
  15783. }// END OF GB_QUANTITY
  15784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15785. }
  15786. else if(gunType[gun_index] == GUN_TYPE_DO)
  15787. {
  15788. tempIndex = gun_index;
  15789. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15790. {
  15791. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15792. {
  15793. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15794. }
  15795. }
  15796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15797. }
  15798. else
  15799. {
  15800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15801. {
  15802. tempIndex = 2;
  15803. }
  15804. else
  15805. {
  15806. tempIndex = gun_index;
  15807. }
  15808. for (int index = 0; index < AC_QUANTITY; index++)
  15809. {
  15810. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15811. {
  15812. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15813. }
  15814. }// END OF AC_QUANTITY
  15815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15816. }
  15817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15820. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15823. }
  15824. //2.3====================================== Power.Active.Import =========================================
  15825. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15826. {
  15827. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15828. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15829. {
  15830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15831. {
  15832. tempIndex = ((gun_index==2) ? 1: 0);
  15833. }
  15834. else
  15835. {
  15836. tempIndex = gun_index;
  15837. }
  15838. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15839. {
  15840. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15841. {
  15842. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15843. }
  15844. } // End for CHAdeMO_QUANTITY
  15845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15846. }
  15847. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15848. {
  15849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15850. {
  15851. tempIndex = ((gun_index==2) ? 1: 0);
  15852. }
  15853. else
  15854. {
  15855. tempIndex = gun_index;
  15856. }
  15857. for (int index = 0; index < CCS_QUANTITY; index++)
  15858. {
  15859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15860. {
  15861. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15862. }
  15863. } // END for CCS_QUANTITY
  15864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15865. }
  15866. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15867. {
  15868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15869. {
  15870. tempIndex = ((gun_index==2) ? 1: 0);
  15871. }
  15872. else
  15873. {
  15874. tempIndex = gun_index;
  15875. }
  15876. for (int index = 0; index < GB_QUANTITY; index++)
  15877. {
  15878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15879. {
  15880. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15881. }
  15882. }// END for GB_QUANTITY
  15883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15884. }
  15885. else if(gunType[gun_index] == GUN_TYPE_DO)
  15886. {
  15887. tempIndex = gun_index;
  15888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15889. {
  15890. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15891. {
  15892. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15893. }
  15894. }
  15895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15896. }
  15897. else
  15898. {
  15899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15900. {
  15901. tempIndex = 2;
  15902. }
  15903. else
  15904. {
  15905. tempIndex = gun_index;
  15906. }
  15907. for (int index = 0; index < AC_QUANTITY; index++)
  15908. {
  15909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15910. {
  15911. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15912. }
  15913. } // END for AC_QUANTITY
  15914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15915. }
  15916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15919. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15922. }
  15923. //2.4====================================== Voltage L1 ====================================================
  15924. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15925. {
  15926. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15927. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15928. {
  15929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15930. {
  15931. tempIndex = ((gun_index==2) ? 1: 0);
  15932. }
  15933. else
  15934. {
  15935. tempIndex = gun_index;
  15936. }
  15937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15938. {
  15939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15940. {
  15941. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15942. }
  15943. } // END OF FOR CHAdeMO_QUANTITY
  15944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15945. }
  15946. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15947. {
  15948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15949. {
  15950. tempIndex = ((gun_index==2) ? 1: 0);
  15951. }
  15952. else
  15953. {
  15954. tempIndex = gun_index;
  15955. }
  15956. for (int index = 0; index < CCS_QUANTITY; index++)
  15957. {
  15958. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15959. {
  15960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15961. }
  15962. } // END OF FOR CCS_QUANTITY
  15963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15964. }
  15965. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15966. {
  15967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15968. {
  15969. tempIndex = ((gun_index==2) ? 1: 0);
  15970. }
  15971. else
  15972. {
  15973. tempIndex = gun_index;
  15974. }
  15975. for (int index = 0; index < GB_QUANTITY; index++)
  15976. {
  15977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15978. {
  15979. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15980. }
  15981. } // END OF FOR GB_QUANTITY
  15982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15983. }
  15984. else if(gunType[gun_index] == GUN_TYPE_DO)
  15985. {
  15986. tempIndex = gun_index;
  15987. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15988. {
  15989. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15990. {
  15991. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15992. }
  15993. }
  15994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15995. }
  15996. else
  15997. {
  15998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15999. {
  16000. tempIndex = 2;
  16001. }
  16002. else
  16003. {
  16004. tempIndex = gun_index;
  16005. }
  16006. for (int index = 0; index < AC_QUANTITY; index++)
  16007. {
  16008. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16009. {
  16010. 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
  16011. }
  16012. } // END OF FOR AC_QUANTITY
  16013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16014. }
  16015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16018. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16021. }
  16022. //2.5============================================== End SoC =========================================================
  16023. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16024. {
  16025. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16026. 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))
  16027. {
  16028. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16029. {
  16030. tempIndex = ((gun_index==2) ? 1: 0);
  16031. }
  16032. else
  16033. {
  16034. tempIndex = gun_index;
  16035. }
  16036. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16037. {
  16038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16039. {
  16040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16041. {
  16042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16043. }
  16044. }
  16045. }
  16046. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16047. {
  16048. for (int index = 0; index < CCS_QUANTITY; index++)
  16049. {
  16050. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16051. {
  16052. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16053. }
  16054. }
  16055. }
  16056. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16057. {
  16058. for (int index = 0; index < GB_QUANTITY; index++)
  16059. {
  16060. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16061. {
  16062. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16063. }
  16064. }
  16065. }
  16066. else if(gunType[gun_index] == GUN_TYPE_DO)
  16067. {
  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[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16073. }
  16074. }
  16075. }
  16076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16082. } // END FOR DC CASE
  16083. }
  16084. //2.6====================================== Current.Import L2 ==============================================
  16085. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16086. {
  16087. // AC 3 phase L2 current
  16088. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16089. {
  16090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16091. {
  16092. tempIndex = 2;
  16093. }
  16094. else
  16095. {
  16096. tempIndex = gun_index;
  16097. }
  16098. for (int index = 0; index < AC_QUANTITY; index++)
  16099. {
  16100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16101. {
  16102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16103. }
  16104. }// End of for AC_QUANTITY
  16105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16106. }
  16107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16112. }
  16113. //2.7====================================== Current.Import L3 ==============================================
  16114. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16115. {
  16116. // AC 3 phase L3 current
  16117. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16118. {
  16119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16120. {
  16121. tempIndex = 2;
  16122. }
  16123. else
  16124. {
  16125. tempIndex = gun_index;
  16126. }
  16127. for (int index = 0; index < AC_QUANTITY; index++)
  16128. {
  16129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16130. {
  16131. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16132. }
  16133. }// End of for AC_QUANTITY
  16134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16135. }
  16136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16141. }
  16142. //2.9====================================== Voltage L2 ====================================================
  16143. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16144. {
  16145. // AC 3 phase L2 volatge
  16146. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16147. {
  16148. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16149. {
  16150. tempIndex = 2;
  16151. }
  16152. else
  16153. {
  16154. tempIndex = gun_index;
  16155. }
  16156. for (int index = 0; index < AC_QUANTITY; index++)
  16157. {
  16158. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16159. {
  16160. 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
  16161. }
  16162. } // END OF FOR AC_QUANTITY
  16163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16164. }
  16165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16170. }
  16171. //2.10====================================== Voltage L3 ====================================================
  16172. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16173. {
  16174. // AC 3 phase L3 volatge
  16175. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16176. {
  16177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16178. {
  16179. tempIndex = 2;
  16180. }
  16181. else
  16182. {
  16183. tempIndex = gun_index;
  16184. }
  16185. for (int index = 0; index < AC_QUANTITY; index++)
  16186. {
  16187. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16188. {
  16189. 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
  16190. }
  16191. } // END OF FOR AC_QUANTITY
  16192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16193. }
  16194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16199. }
  16200. //====================== Start SoC ================================
  16201. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16202. {
  16203. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16204. 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))
  16205. {
  16206. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16207. {
  16208. tempIndex = ((gun_index==2) ? 1: 0);
  16209. }
  16210. else
  16211. {
  16212. tempIndex = gun_index;
  16213. }
  16214. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16215. {
  16216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16217. {
  16218. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16219. {
  16220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16221. }
  16222. }
  16223. }
  16224. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16225. {
  16226. for (int index = 0; index < CCS_QUANTITY; index++)
  16227. {
  16228. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16229. {
  16230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16231. }
  16232. }
  16233. }
  16234. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16235. {
  16236. for (int index = 0; index < GB_QUANTITY; index++)
  16237. {
  16238. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16239. {
  16240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16241. }
  16242. }
  16243. }
  16244. else if(gunType[gun_index] == GUN_TYPE_DO)
  16245. {
  16246. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16247. {
  16248. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16249. {
  16250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16251. }
  16252. }
  16253. }
  16254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16260. } // END FOR DC CASE
  16261. }
  16262. //======================================== Message create ==============================================
  16263. json_object *StopTransaction = json_object_new_object();
  16264. json_object *transactionDatas = json_object_new_array();
  16265. json_object *sampledValues = json_object_new_array();
  16266. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16267. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16268. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16269. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16270. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16271. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16272. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16273. {
  16274. json_object *transactionData = json_object_new_object();
  16275. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16276. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16277. {
  16278. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16279. {
  16280. json_object *sampledValue = json_object_new_object();
  16281. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16282. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16283. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16284. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16285. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16286. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16287. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16288. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16289. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16290. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16291. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16292. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16293. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16294. json_object_array_add(sampledValues, sampledValue);
  16295. }
  16296. }
  16297. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16298. json_object_array_add(transactionDatas, transactionData);
  16299. }
  16300. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16301. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16302. ,MESSAGE_TYPE_CALL
  16303. ,guid
  16304. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16305. json_object_put(StopTransaction);
  16306. // Check File "TempStopTransaction" Exist
  16307. if((access(TempStopTransaction,F_OK))!=-1)
  16308. {
  16309. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16310. fclose(fopen(TempStopTransaction, "w"));
  16311. }
  16312. else
  16313. {
  16314. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16315. FILE *log = fopen(TempStopTransaction, "w+");
  16316. if(log == NULL)
  16317. {
  16318. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16319. return ;
  16320. }
  16321. else
  16322. {
  16323. fclose(log);
  16324. }
  16325. }
  16326. //Add TempStopTransaction | Update TempStopTransaction
  16327. // open file for writing
  16328. FILE *outfile;
  16329. outfile = fopen (TempStopTransaction, "a");
  16330. //DEBUG_INFO("data = %s\n", queuedata);
  16331. fputs(queuedata, outfile);
  16332. fputs("\n", outfile);
  16333. fclose (outfile);
  16334. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16335. }
  16336. void checkTempStopTransaction(int gun_index)
  16337. {
  16338. FILE *fptr1;
  16339. char ch;
  16340. char str[QUEUE_MESSAGE_LENGTH]={0};
  16341. char guid[37]={0};
  16342. char tempdata[65]={0};
  16343. char connectorStr[2]={0};
  16344. char TempStopTransaction[256];
  16345. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16346. fptr1 = fopen(TempStopTransaction, "r");
  16347. //TempStopTransaction格式: 槍號,StopTransaction封包
  16348. if (!fptr1)
  16349. {
  16350. //printf(" File not found or unable to open the input file!!\n");
  16351. return ;
  16352. }
  16353. ch=fgetc(fptr1);
  16354. //printf(" Now the content of the file %s is : \n",fname);
  16355. rewind(fptr1);
  16356. if(ch!=EOF)
  16357. {
  16358. // copy all contents to the temporary file except the specific line
  16359. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16360. {
  16361. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16362. if(str[0]=='\0')
  16363. {
  16364. break;
  16365. }
  16366. //TempStopTransaction格式: 槍號,StopTransaction封包
  16367. strncpy(connectorStr, str, 1);
  16368. if(atoi(connectorStr) != (gun_index+1))
  16369. {
  16370. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16371. fclose(fptr1);
  16372. return ;
  16373. }
  16374. //random_uuid(guid);
  16375. strncpy(guid, str+6, 36); //copy guid
  16376. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16377. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16378. {
  16379. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16380. }
  16381. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16382. OCPP_insert_transaction_msg(NO, str);
  16383. memset(str,0,ARRAY_SIZE(str));
  16384. }
  16385. }
  16386. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16387. fclose(fptr1);
  16388. remove(TempStopTransaction); // remove the original file
  16389. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16390. }
  16391. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16392. {
  16393. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16394. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16395. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16396. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16397. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16398. }
  16399. int GetWebSocketPingInterval(void)
  16400. {
  16401. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16402. }
  16403. int GetServerSign(void)
  16404. {
  16405. return server_sign;
  16406. }
  16407. uint8_t GetOcppSecurityProfile()
  16408. {
  16409. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16410. }
  16411. void GetOcppChargerBoxId(uint8_t *data)
  16412. {
  16413. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16414. }
  16415. void GetOcppSecurityPassword(uint8_t *data)
  16416. {
  16417. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16418. }
  16419. void SetOcppVersion(uint8_t *version)
  16420. {
  16421. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16422. DEBUG_INFO("ocpp version: %s\n", version);
  16423. if(strstr((char*)version, "ocpp1.6") != NULL)
  16424. {
  16425. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16426. }
  16427. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16428. {
  16429. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16430. system("pkill OcppBackend");
  16431. }
  16432. }
  16433. void SetServerSign(int value)
  16434. {
  16435. server_sign = value;
  16436. }
  16437. int GetBootNotificationInterval(void)
  16438. {
  16439. return BootNotificationInterval;
  16440. }
  16441. int GetInternetConn(void)
  16442. {
  16443. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16444. }
  16445. int GetBackendConnectionTimeout(void)
  16446. {
  16447. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16448. }
  16449. int isConnectorInitMode(int gun_index)
  16450. {
  16451. int tempIndex = 0;
  16452. int result = TRUE;
  16453. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16454. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16455. {
  16456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16457. {
  16458. tempIndex = ((gun_index==2) ? 1: 0);
  16459. }
  16460. else
  16461. {
  16462. tempIndex = gun_index;
  16463. }
  16464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16465. {
  16466. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16467. {
  16468. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16469. } //end of the same index
  16470. }//end of for CHAdeMO_QUANTITY
  16471. }
  16472. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16473. {
  16474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16475. {
  16476. tempIndex = ((gun_index==2) ? 1: 0);
  16477. }
  16478. else
  16479. {
  16480. tempIndex = gun_index;
  16481. }
  16482. for (int index = 0; index < CCS_QUANTITY; index++)
  16483. {
  16484. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16485. {
  16486. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16487. } //end of the same index
  16488. } // end of for CCS_QUANTITY
  16489. }
  16490. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16491. {
  16492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16493. {
  16494. tempIndex = ((gun_index==2) ? 1: 0);
  16495. }
  16496. else
  16497. {
  16498. tempIndex = gun_index;
  16499. }
  16500. for (int index = 0; index < GB_QUANTITY; index++)
  16501. {
  16502. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16503. {
  16504. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16505. } //end of the same index
  16506. } // end of for GB_QUANTITY
  16507. }
  16508. else if(gunType[gun_index] == GUN_TYPE_DO)
  16509. {
  16510. tempIndex = gun_index;
  16511. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16512. {
  16513. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16514. {
  16515. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16516. } //end of the same index
  16517. }
  16518. }
  16519. else
  16520. {
  16521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16522. {
  16523. tempIndex = 2;
  16524. }
  16525. else
  16526. {
  16527. tempIndex = gun_index;
  16528. }
  16529. for (int index = 0; index < AC_QUANTITY; index++)
  16530. {
  16531. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16532. {
  16533. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16534. }//end of the same index
  16535. }//end of for AC_QUANTITY
  16536. }
  16537. return result;
  16538. }
  16539. void refreshProcDogTimer()
  16540. {
  16541. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16542. }
  16543. void InitialSystemValue(void)
  16544. {
  16545. int connectorIndex = 0;
  16546. //int valueASCII = 0;
  16547. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16548. gunTotalNumber=0;
  16549. SystemInitial = 0;
  16550. locallistVersion=0;
  16551. BootNotificationInterval = 0;
  16552. authorizeRetryTimes = 0;
  16553. GunStatusInterval = 10;
  16554. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16555. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16556. //Hear Beat
  16557. HeartBeatWithNOResponse = 0;
  16558. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16559. FirstHeartBeat = 0;
  16560. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16561. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16562. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16563. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16564. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16565. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16566. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16567. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16568. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16569. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16570. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16571. memset(gunType, 0, ARRAY_SIZE(gunType));
  16572. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16573. {
  16574. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16575. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16576. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16577. {
  16578. // DO series
  16579. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16580. {
  16581. SystemInitial = SystemInitial + 1;
  16582. gunTotalNumber = gunTotalNumber + 1;
  16583. gunType[connectorIndex] = GUN_TYPE_DO;
  16584. connectorIndex = connectorIndex + 1;
  16585. }
  16586. }
  16587. else
  16588. {
  16589. // DM, DW, DS series
  16590. //check connector / socket type (index: 8, 9, 10)
  16591. for(int index=7; index <10 ; index++)
  16592. {
  16593. if(index != 8)
  16594. {
  16595. // DC Connector
  16596. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16597. {
  16598. SystemInitial = SystemInitial + 1;
  16599. gunTotalNumber = gunTotalNumber + 1;
  16600. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16601. connectorIndex = connectorIndex + 1;
  16602. }
  16603. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16604. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16605. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16606. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16607. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16608. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16609. {
  16610. SystemInitial = SystemInitial + 1;
  16611. gunTotalNumber = gunTotalNumber + 1;
  16612. gunType[connectorIndex] = GUN_TYPE_CCS;
  16613. connectorIndex = connectorIndex + 1;
  16614. }
  16615. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16616. {
  16617. SystemInitial = SystemInitial + 1;
  16618. gunTotalNumber = gunTotalNumber + 1;
  16619. gunType[connectorIndex] = GUN_TYPE_GBT;
  16620. connectorIndex = connectorIndex + 1;
  16621. }
  16622. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16623. {
  16624. SystemInitial = SystemInitial + 1;
  16625. gunTotalNumber = gunTotalNumber + 1;
  16626. gunType[connectorIndex] = GUN_TYPE_DO;
  16627. connectorIndex = connectorIndex + 1;
  16628. }
  16629. }
  16630. else
  16631. {
  16632. // AC Connector
  16633. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16634. {
  16635. SystemInitial = SystemInitial + 1;
  16636. gunTotalNumber = gunTotalNumber + 1;
  16637. gunType[connectorIndex] = GUN_TYPE_AC;
  16638. connectorIndex = connectorIndex + 1;
  16639. }
  16640. }
  16641. }
  16642. }
  16643. //DEBUG_INFO("DC ...\n");
  16644. }
  16645. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16646. {
  16647. //check connector / socket type (index: 8, 9, 10)
  16648. for(int index=7; index <10 ; index++)
  16649. {
  16650. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16651. {
  16652. SystemInitial = SystemInitial + 1;
  16653. gunTotalNumber = gunTotalNumber + 1;
  16654. gunType[connectorIndex] = GUN_TYPE_AC;
  16655. connectorIndex = connectorIndex + 1;
  16656. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16657. }
  16658. }
  16659. }
  16660. //Status && ConnectorPlugIn Setting
  16661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16662. {
  16663. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16664. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16665. }
  16666. for (int index = 0; index < CCS_QUANTITY; index++)
  16667. {
  16668. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16669. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16670. }
  16671. for (int index = 0; index < GB_QUANTITY; index++)
  16672. {
  16673. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16674. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16675. }
  16676. for (int index = 0; index < AC_QUANTITY; index++)
  16677. {
  16678. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16679. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16680. }
  16681. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16682. {
  16683. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16684. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16685. }
  16686. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16687. {
  16688. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16689. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16690. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16691. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16692. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16693. }
  16694. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16695. clientTime.Heartbeat=time((time_t*)NULL);
  16696. sleep(1);
  16697. }
  16698. void LWS_Send(char *str)
  16699. {
  16700. //=====================================================
  16701. // Check InternetConn 0: disconnected, 1: connected
  16702. //====================================================
  16703. if(GetOcppConnStatus() == 0)
  16704. {
  16705. DEBUG_INFO("offline now !!!\n");
  16706. return;
  16707. }
  16708. // Only disable isWebsocketSendable operation initiated by charger
  16709. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16710. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16711. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16712. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16713. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16714. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16715. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16716. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16717. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16718. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16719. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16720. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16721. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16722. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16723. {
  16724. isWebsocketSendable = 0;
  16725. }
  16726. pthread_mutex_lock(&lock_send);
  16727. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16728. sprintf((char *)SendBuffer, "%s", str);
  16729. SendBufLen = strlen(str);
  16730. pthread_mutex_unlock(&lock_send);
  16731. lws_callback_on_writable(wsi_client);
  16732. //lws_service(context, 0);
  16733. //sleep(1);
  16734. }
  16735. void LWS_SendNow(char *str)
  16736. {
  16737. //=====================================================
  16738. // Check InternetConn 0: disconnected, 1: connected
  16739. //====================================================
  16740. if(GetOcppConnStatus() == 0)
  16741. {
  16742. DEBUG_INFO("offline now !!!\n");
  16743. return;
  16744. }
  16745. // Only disable isWebsocketSendable operation initiated by charger
  16746. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16747. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16748. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16749. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16750. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16751. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16752. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16753. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16754. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16755. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16756. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16757. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16758. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16759. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16760. {
  16761. isWebsocketSendable = 0;
  16762. }
  16763. pthread_mutex_lock(&lock_send);
  16764. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16765. sprintf((char *)SendBuffer, "%s", str);
  16766. SendBufLen = strlen(str);
  16767. pthread_mutex_unlock(&lock_send);
  16768. lws_callback_on_writable(wsi_client);
  16769. lws_service(context, 0);
  16770. //sleep(1);
  16771. }