MessageHandler.c 929 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231
  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. struct StructYesCustomData *ShmYesCustomData;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec YesCustomCallReader;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4,
  124. unsigned char :3; //bit5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // TTIA routine
  364. //=========================================
  365. int sendTTIAInfo(uint8_t gun_index)
  366. {
  367. static int sn = 0;
  368. int result = FAIL;
  369. struct hostent *server;
  370. int udp_socket_fd;
  371. struct sockaddr_in dest_addr = {0};
  372. uint8_t tx_buf[80] = {0};
  373. uint8_t logBuf[256]= {0};
  374. uint8_t tx_len, tempIndex, socStart, socEnd;
  375. uint16_t PresentChargedEnergy;
  376. struct tm tmStart, tmEnd;
  377. DEBUG_INFO("sendTTIAInfo...\n");
  378. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  379. {
  380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  381. {
  382. tempIndex = ((gun_index==2) ? 1: 0);
  383. }
  384. else
  385. {
  386. tempIndex = gun_index;
  387. }
  388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  389. {
  390. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  391. {
  392. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  393. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  394. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  395. }
  396. }
  397. }
  398. else if(gunType[gun_index] == GUN_TYPE_CCS)
  399. {
  400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  401. {
  402. tempIndex = ((gun_index==2) ? 1: 0);
  403. }
  404. else
  405. {
  406. tempIndex = gun_index;
  407. }
  408. for (int index = 0; index < CCS_QUANTITY; index++)
  409. {
  410. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  411. {
  412. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  413. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  414. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  415. }
  416. }
  417. }
  418. else if(gunType[gun_index] == GUN_TYPE_GBT)
  419. {
  420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  421. {
  422. tempIndex = ((gun_index==2) ? 1: 0);
  423. }
  424. else
  425. {
  426. tempIndex = gun_index;
  427. }
  428. for (int index = 0; index < GB_QUANTITY; index++)
  429. {
  430. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  431. {
  432. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  433. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  434. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  435. }
  436. }
  437. }
  438. else if(gunType[gun_index] == GUN_TYPE_DO)
  439. {
  440. tempIndex = gun_index;
  441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  442. {
  443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  444. {
  445. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  446. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  447. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  448. }
  449. }
  450. }
  451. else
  452. {
  453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  454. {
  455. tempIndex = 2;
  456. }
  457. else
  458. {
  459. tempIndex = gun_index;
  460. }
  461. for (int index = 0; index < AC_QUANTITY; index++)
  462. {
  463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  464. {
  465. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  466. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  467. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  468. }
  469. }// END
  470. }
  471. // Message assembly
  472. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  473. tx_buf[4] = 0x02; // Protocol Version
  474. tx_buf[5] = 0xb0; // Message ID
  475. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  476. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  477. tx_buf[8] = 0x00; // CarID low byte
  478. tx_buf[9] = 0x00; // CarID high byte
  479. tx_buf[10] = 0x00; // ID Storage
  480. tx_buf[11] = 0x00; // Driver lowest byte
  481. tx_buf[12] = 0x00; // Driver 2nd byte
  482. tx_buf[13] = 0x00; // Driver 3rd byte
  483. tx_buf[14] = 0x00; // Driver highest byte
  484. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  485. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  486. tx_buf[17] = 0x00; // Reserve
  487. tx_buf[18] = 60 & 0xff; // Payload length low byte
  488. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  489. // EVSE provider
  490. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  491. // EVSE provider
  492. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  493. // EVSE id
  494. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  495. // Connector id
  496. tx_buf[37] = gun_index;
  497. // EVSE station
  498. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  499. // Vehicle SN
  500. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  501. // Mileage
  502. tx_buf[61] = 0x00; // lowest byte
  503. tx_buf[62] = 0x00; // 2nd byte
  504. tx_buf[63] = 0x00; // highest byte
  505. // Start date time 6 bytes
  506. 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))
  507. {
  508. struct tm *tmTarget;
  509. struct timeb tbTarget;
  510. tmStart.tm_year -= 1900;
  511. tmStart.tm_mon -= 1;
  512. tmStart.tm_gmtoff = 0;
  513. tbTarget.time = mktime(&tmStart);
  514. tbTarget.timezone = 0;
  515. tbTarget.time += (8*3600);
  516. tmTarget = gmtime(&tbTarget.time);
  517. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  518. tx_buf[65] = (tmTarget->tm_mon+1);
  519. tx_buf[66] = tmTarget->tm_mday;
  520. tx_buf[67] = tmTarget->tm_hour;
  521. tx_buf[68] = tmTarget->tm_min;
  522. tx_buf[69] = tmTarget->tm_sec;
  523. }
  524. // Stop date time 6 bytes
  525. 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))
  526. {
  527. struct tm *tmTarget;
  528. struct timeb tbTarget;
  529. tmEnd.tm_year -= 1900;
  530. tmEnd.tm_mon -= 1;
  531. tmEnd.tm_gmtoff = 0;
  532. tbTarget.time = mktime(&tmEnd);
  533. tbTarget.timezone = 0;
  534. tbTarget.time += (8*3600);
  535. tmTarget = gmtime(&tbTarget.time);
  536. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  537. tx_buf[71] = (tmTarget->tm_mon+1);
  538. tx_buf[72] = tmTarget->tm_mday;
  539. tx_buf[73] = tmTarget->tm_hour;
  540. tx_buf[74] = tmTarget->tm_min;
  541. tx_buf[75] = tmTarget->tm_sec;
  542. }
  543. // Session energy 2 bytes
  544. tx_buf[76] = PresentChargedEnergy & 0xff;
  545. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  546. // Start SOC 1 byte
  547. tx_buf[78] = socStart;
  548. // Stop SOC 1 byte
  549. tx_buf[79] = socEnd;
  550. // Open socket
  551. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  552. if(udp_socket_fd == -1)
  553. {
  554. DEBUG_ERROR("UDP socket create failed!\n");
  555. }
  556. else
  557. {
  558. // Get server DNS entry
  559. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  560. if (server == NULL)
  561. {
  562. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  563. }
  564. else
  565. {
  566. // Build the server's Internet address
  567. bzero((char *) &dest_addr, sizeof(dest_addr));
  568. dest_addr.sin_family = AF_INET;
  569. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  570. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  571. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  572. {
  573. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  574. {
  575. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  576. }
  577. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  578. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  579. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  580. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  581. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  582. DEBUG_TTIA_INFO("---------- Header ----------\n");
  583. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  584. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  585. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  586. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  587. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  588. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  589. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  590. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  591. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  592. DEBUG_TTIA_INFO("Len: 0x3C\n");
  593. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  594. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  595. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  596. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  597. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  598. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  599. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  600. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  601. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  603. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  604. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  605. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  606. DEBUG_TTIA_INFO("=========================================\n");
  607. sn++;
  608. result = PASS;
  609. }
  610. else
  611. {
  612. DEBUG_ERROR("UDP sent out fail.\n");
  613. }
  614. }
  615. }
  616. return result;
  617. }
  618. //=========================================
  619. // Save configuration
  620. //=========================================
  621. int runShellCmd(const char*cmd)
  622. {
  623. int result = FAIL;
  624. char buf[256];
  625. FILE *fp;
  626. fp = popen(cmd, "r");
  627. if(fp != NULL)
  628. {
  629. while(fgets(buf, sizeof(buf), fp) != NULL)
  630. {
  631. DEBUG_INFO("%s\n", buf);
  632. }
  633. result = PASS;
  634. }
  635. pclose(fp);
  636. return result;
  637. }
  638. int StoreUsrConfigData(struct SysConfigData *UsrData)
  639. {
  640. int result = PASS;
  641. int fd,wrd;
  642. unsigned int i,Chk;
  643. unsigned char *ptr, *BufTmp;
  644. int MtdBlockSize = 0x300000;
  645. Chk=0;
  646. ptr=(unsigned char *)UsrData;
  647. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  648. {
  649. memset(BufTmp,0,MtdBlockSize);
  650. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  651. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  652. Chk+=*(BufTmp+i);
  653. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  654. // Output configuration to file.
  655. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  656. if (fd < 0)
  657. {
  658. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  659. free(BufTmp);
  660. return 0;
  661. }
  662. wrd=write(fd, BufTmp, MtdBlockSize);
  663. close(fd);
  664. if(wrd<MtdBlockSize)
  665. {
  666. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  667. free(BufTmp);
  668. return 0;
  669. }
  670. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  671. DEBUG_INFO("Erase /dev/mtd10.\n");
  672. runShellCmd("flash_erase /dev/mtd10 0 0");
  673. DEBUG_INFO("Write /dev/mtd10.\n");
  674. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  675. DEBUG_INFO("Erase /dev/mtd11.\n");
  676. runShellCmd("flash_erase /dev/mtd11 0 0");
  677. DEBUG_INFO("Write /dev/mtd11.\n");
  678. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  679. system("rm -f /mnt/EvseConfig.bin");
  680. DEBUG_INFO("EvseConfig write to flash OK\n");
  681. }
  682. else
  683. {
  684. DEBUG_ERROR("alloc BlockSize NG\r\n");
  685. result = FAIL;
  686. }
  687. if(BufTmp!=NULL)
  688. free(BufTmp);
  689. return result;
  690. }
  691. //=========================================
  692. // Sqlite3 related function
  693. //=========================================
  694. static int selectSqlCount = 0;
  695. static int callback(void *data, int argc, char **argv, char **azColName){
  696. int i;
  697. //printf("%s: ", (const char*)data);
  698. selectSqlCount = argc;
  699. for(i = 0; i<argc; i++){
  700. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  701. }
  702. //printf("\n");
  703. return 0;
  704. }
  705. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  706. //int i;
  707. //printf("%s:\n", (const char*)data);
  708. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  709. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  710. return 0;
  711. }
  712. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  713. //printf("%s:\n", (const char*)data);
  714. //idTag
  715. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  717. //parentIdTag
  718. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  719. //expir_date
  720. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  721. //status
  722. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  723. //version
  724. if(columenCount > 5)
  725. idTagQuery.listVersionInt = atoi(columnValue[5]);
  726. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  727. return 0;
  728. }
  729. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  730. {
  731. // localversion = argv[5] ? atoi(argv[5]) : 0;
  732. // printf("localversion=%d\n", localversion);
  733. return 0;
  734. }
  735. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  736. {
  737. for (int i = 0; i < n_columns; i++)
  738. {
  739. DEBUG_INFO("%s\t", col_values[i]);
  740. }
  741. DEBUG_INFO("\n");
  742. return 0;
  743. }
  744. int OCPP_cleanLocalCache()
  745. {
  746. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  747. char *errMsg = 0;
  748. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  749. if (SQLITE_OK != rc)
  750. {
  751. DEBUG_INFO("SQL error: %s\n",errMsg);
  752. return FALSE;
  753. }
  754. return TRUE;
  755. }
  756. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  757. {
  758. int isSuccess = TRUE;
  759. int ret = 0;
  760. //const char* data = "Callback function called";
  761. char sql[300];
  762. char zErrMsg[200];
  763. memset(sql, 0, 300);
  764. memset(zErrMsg, 0, 200);
  765. 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);
  766. //* Execute SQL statement */
  767. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  768. if( ret != SQLITE_OK )
  769. {
  770. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  771. isSuccess = FALSE;
  772. }
  773. return isSuccess;
  774. }
  775. void OCPP_getIdTagFromLocalCache(char idTag[])
  776. {
  777. int rc = 0;
  778. char sql[100];
  779. char zErrMsg[100];
  780. memset(sql, 0, 100);
  781. memset(zErrMsg, 0, 100);
  782. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  783. memset(&idTagQuery, 0, sizeof(idTagQuery));
  784. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  785. /* Execute SQL statement */
  786. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  787. if( rc != SQLITE_OK )
  788. {
  789. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  790. }
  791. }
  792. void OCPP_getListVerion()
  793. {
  794. int rc = 0;
  795. // const char* data = "Callback function called";
  796. char sql[100];
  797. char zErrMsg[100];
  798. memset(sql, 0, 100);
  799. memset(zErrMsg, 0, 100);
  800. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  801. /* Execute SQL statement */
  802. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  803. if( rc != SQLITE_OK )
  804. {
  805. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  806. }
  807. }
  808. void OCPP_get_TableAuthlocalAllData(void)
  809. {
  810. int rc = 0;
  811. char sql[100];
  812. char zErrMsg[100];
  813. memset(sql, 0, 100);
  814. memset(zErrMsg, 0, 100);
  815. sprintf(sql,"select * from ocpp_auth_local ");
  816. /* Execute SQL statement */
  817. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  818. if( rc != SQLITE_OK )
  819. {
  820. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  821. }
  822. //return ver;
  823. }
  824. int OCPP_cleanLocalList()
  825. {
  826. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  827. char *errMsg = 0;
  828. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  829. if (SQLITE_OK != rc)
  830. {
  831. DEBUG_INFO("%s\n",errMsg);
  832. return FALSE;
  833. }
  834. return TRUE;
  835. }
  836. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  837. {
  838. int isSuccess = FALSE;
  839. int ret = 0;
  840. //const char* data = "Callback function called";
  841. char sql[300];
  842. char zErrMsg[200];
  843. memset(sql, 0, 300);
  844. memset(zErrMsg, 0, 200);
  845. 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);
  846. //* Execute SQL statement */
  847. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  848. if( ret != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. return isSuccess;
  852. }
  853. memset(sql, 0, 300);
  854. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  855. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  856. if( ret != SQLITE_OK )
  857. {
  858. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  859. return isSuccess;
  860. }
  861. isSuccess = TRUE;
  862. return isSuccess;
  863. }
  864. void OCPP_getIdTagFromLocalList(char idTag[])
  865. {
  866. int rc = 0;
  867. // const char* data = "Callback function called";
  868. char sql[100];
  869. char zErrMsg[100];
  870. memset(sql, 0, 100);
  871. memset(zErrMsg, 0, 100);
  872. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  873. memset(&idTagQuery, 0, sizeof(idTagQuery));
  874. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  875. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  876. /* Execute SQL statement */
  877. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  878. if( rc != SQLITE_OK )
  879. {
  880. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  881. }
  882. //return ver;
  883. }
  884. void OCPP_deleteIdTagFromLocalList(char idTag[])
  885. {
  886. //int ver = 0;
  887. //int isSuccess = FALSE;
  888. int rc = 0;
  889. char sql[100];
  890. char zErrMsg[100];
  891. memset(sql, 0, 100);
  892. memset(zErrMsg, 0, 100);
  893. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  894. //* Execute SQL statement */
  895. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  896. if( rc != SQLITE_OK )
  897. {
  898. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  899. }
  900. }
  901. int getCurrentYear()
  902. {
  903. int result = 0;
  904. time_t CurrentTime;
  905. struct tm *tm;
  906. CurrentTime = time(NULL);
  907. tm=localtime(&CurrentTime);
  908. result = (tm->tm_year + 1900);
  909. return result;
  910. }
  911. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  912. {
  913. int result = PASS;
  914. char* errMsg = NULL;
  915. char sqlStr[8192];
  916. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  917. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  918. {
  919. result = FAIL;
  920. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  921. }
  922. 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));
  923. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  924. {
  925. result = FAIL;
  926. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  927. }
  928. return result;
  929. }
  930. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  931. {
  932. int isSuccess = TRUE;
  933. int tempIndex;
  934. json_object *EnergyDataTransfer = json_object_new_object();
  935. json_object *periodEnergys = json_object_new_object();
  936. char sql[1024];
  937. char zErrMsg[200];
  938. memset(sql, 0, ARRAY_SIZE(sql));
  939. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  940. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  941. {
  942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  943. {
  944. tempIndex = ((gun_index==2) ? 1: 0);
  945. }
  946. else
  947. {
  948. tempIndex = gun_index;
  949. }
  950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  951. {
  952. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  953. {
  954. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  955. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  956. {
  957. uint8_t period[3];
  958. sprintf((char*)period, "%d", idxPeriod);
  959. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  960. }
  961. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  962. } //end of the same index
  963. }//end of for CHAdeMO_QUANTITY
  964. }
  965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  966. {
  967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  968. {
  969. tempIndex = ((gun_index==2) ? 1: 0);
  970. }
  971. else
  972. {
  973. tempIndex = gun_index;
  974. }
  975. for (int index = 0; index < CCS_QUANTITY; index++)
  976. {
  977. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  978. {
  979. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  980. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  981. {
  982. uint8_t period[3];
  983. sprintf((char*)period, "%d", idxPeriod);
  984. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  985. }
  986. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  987. } //end of the same index
  988. } // end of for CCS_QUANTITY
  989. }
  990. else if(gunType[gun_index] == GUN_TYPE_GBT)
  991. {
  992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  993. {
  994. tempIndex = ((gun_index==2) ? 1: 0);
  995. }
  996. else
  997. {
  998. tempIndex = gun_index;
  999. }
  1000. for (int index = 0; index < GB_QUANTITY; index++)
  1001. {
  1002. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1003. {
  1004. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1005. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1006. {
  1007. uint8_t period[3];
  1008. sprintf((char*)period, "%d", idxPeriod);
  1009. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1010. }
  1011. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1012. } //end of the same index
  1013. } // end of for GB_QUANTITY
  1014. }
  1015. else if(gunType[gun_index] == GUN_TYPE_DO)
  1016. {
  1017. tempIndex = gun_index;
  1018. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1019. {
  1020. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1021. {
  1022. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1023. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1024. {
  1025. uint8_t period[3];
  1026. sprintf((char*)period, "%d", idxPeriod);
  1027. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1028. }
  1029. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1030. } //end of the same index
  1031. }
  1032. }
  1033. else
  1034. {
  1035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1036. {
  1037. tempIndex = 2;
  1038. }
  1039. else
  1040. {
  1041. tempIndex = gun_index;
  1042. }
  1043. for (int index = 0; index < AC_QUANTITY; index++)
  1044. {
  1045. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1046. {
  1047. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1048. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1049. {
  1050. uint8_t period[3];
  1051. sprintf((char*)period, "%d", idxPeriod);
  1052. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1053. }
  1054. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1055. }//end of the same index
  1056. }//end of for AC_QUANTITY
  1057. }
  1058. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1059. json_object_put(EnergyDataTransfer);
  1060. //* Execute SQL statement */
  1061. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1062. {
  1063. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1064. isSuccess = FALSE;
  1065. }
  1066. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1067. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1068. {
  1069. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1070. isSuccess = FALSE;
  1071. }
  1072. return isSuccess;
  1073. }
  1074. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1075. {
  1076. int isSuccess = TRUE;
  1077. char sql[512];
  1078. char zErrMsg[200];
  1079. int rows, cols;
  1080. char **resultData;
  1081. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1082. /* Execute SQL statement */
  1083. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1084. {
  1085. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1086. isSuccess = FALSE;
  1087. }
  1088. else
  1089. {
  1090. if((rows > 0) && (atoi(resultData[4]) > 0))
  1091. {
  1092. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1093. }
  1094. else
  1095. {
  1096. DEBUG_WARN("There is not match transaction data.\n");
  1097. isSuccess = FALSE;
  1098. }
  1099. }
  1100. return isSuccess;
  1101. }
  1102. //==========================================
  1103. // Check time passed since today
  1104. //==========================================
  1105. long long DiffTimebWithNow(struct timeb ST)
  1106. {
  1107. //return milli-second
  1108. struct timeb ET;
  1109. long long StartTime,StopTime;
  1110. ftime(&ET);
  1111. StartTime=(long long)ST.time;
  1112. StopTime=(long long)ET.time;
  1113. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1114. }
  1115. int getTimePassSinceToday(uint8_t gun_index)
  1116. {
  1117. int result = -1;
  1118. static time_t lastTime[4];
  1119. time_t t;
  1120. struct tm *tmStartToday;
  1121. struct timeb tbStartToday;
  1122. t=time(NULL);
  1123. if(difftime(t, lastTime[gun_index])>0)
  1124. {
  1125. tmStartToday=localtime(&t);
  1126. tmStartToday->tm_hour = 0;
  1127. tmStartToday->tm_min = 0;
  1128. tmStartToday->tm_sec = 0;
  1129. tbStartToday.time = mktime(tmStartToday);
  1130. tbStartToday.millitm = 0;
  1131. result = DiffTimebWithNow(tbStartToday)/1000;
  1132. lastTime[gun_index] = t;
  1133. }
  1134. return result;
  1135. }
  1136. void getNowDatetime(uint8_t *data)
  1137. {
  1138. time_t t = time(NULL);
  1139. struct tm tm = *localtime(&t);
  1140. 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);
  1141. }
  1142. int syncDateTimeRTC(uint8_t *data)
  1143. {
  1144. struct ParsingResult
  1145. {
  1146. int result;
  1147. int scanedElement;
  1148. int year;
  1149. int month;
  1150. int mday;
  1151. int hour;
  1152. int min;
  1153. int sec;
  1154. int tz_hour;
  1155. int tz_min;
  1156. float minSec;
  1157. }result;
  1158. struct tm tmOrg;
  1159. struct tm *tmTarget;
  1160. struct timeb tbTarget;
  1161. char buf[128];
  1162. memset(&result, 0x00, sizeof(struct ParsingResult));
  1163. result.result = PASS;
  1164. if(strstr((char*)data, ".") != NULL)
  1165. {
  1166. // Original data with mini second
  1167. if(strstr((char*)data, "Z") != NULL)
  1168. {
  1169. // Original data with Z
  1170. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1171. &result.year,
  1172. &result.month,
  1173. &result.mday,
  1174. &result.hour,
  1175. &result.min,
  1176. &result.sec,
  1177. &result.minSec);
  1178. }
  1179. else
  1180. {
  1181. // Original data without Z
  1182. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1183. &result.year,
  1184. &result.month,
  1185. &result.mday,
  1186. &result.hour,
  1187. &result.min,
  1188. &result.sec,
  1189. &result.minSec,
  1190. &result.tz_hour,
  1191. &result.tz_min);
  1192. }
  1193. }
  1194. else
  1195. {
  1196. // Original data without mini second
  1197. if(strstr((char*)data, "Z") != NULL)
  1198. {
  1199. // Original data with Z
  1200. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1201. &result.year,
  1202. &result.month,
  1203. &result.mday,
  1204. &result.hour,
  1205. &result.min,
  1206. &result.sec);
  1207. }
  1208. else
  1209. {
  1210. // Original data without Z
  1211. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1212. &result.year,
  1213. &result.month,
  1214. &result.mday,
  1215. &result.hour,
  1216. &result.min,
  1217. &result.sec,
  1218. &result.tz_hour,
  1219. &result.tz_min);
  1220. }
  1221. }
  1222. tmOrg.tm_year = result.year - 1900;
  1223. tmOrg.tm_mon = result.month - 1;
  1224. tmOrg.tm_mday = result.mday;
  1225. tmOrg.tm_hour = result.hour;
  1226. tmOrg.tm_min = result.min;
  1227. tmOrg.tm_sec = result.sec;
  1228. tmOrg.tm_gmtoff = 0;
  1229. tbTarget.time = mktime(&tmOrg);
  1230. tbTarget.timezone = 0;
  1231. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1232. tmTarget = gmtime(&tbTarget.time);
  1233. 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);
  1234. //DEBUG_INFO(" org date time: %s\n", data);
  1235. //DEBUG_INFO("parse date time: %s\n", buf);
  1236. system(buf);
  1237. system("/sbin/hwclock -w --systohc");
  1238. if(result.scanedElement < 6)
  1239. result.result = FAIL;
  1240. return result.result;
  1241. }
  1242. //==========================================
  1243. // GetCompositeSchedule logic related function
  1244. //==========================================
  1245. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1246. {
  1247. //return milli-second
  1248. unsigned int StartTime,StopTime;
  1249. StartTime=(unsigned int)ST.time;
  1250. StopTime=(unsigned int)ET.time;
  1251. return (StopTime-StartTime);
  1252. }
  1253. int DiffTimebWithNowSec(struct timeb ST)
  1254. {
  1255. //return milli-second
  1256. struct timeb ET;
  1257. unsigned int StartTime,StopTime;
  1258. ftime(&ET);
  1259. StartTime=(unsigned int)ST.time;
  1260. StopTime=(unsigned int)ET.time;
  1261. return (StopTime-StartTime);
  1262. }
  1263. int getStartStop(uint8_t *start, uint8_t *stop)
  1264. {
  1265. int result = -1;
  1266. struct tm tmStart;
  1267. struct timeb tbStart;
  1268. struct tm tmStop;
  1269. struct timeb tbStop;
  1270. 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) &&
  1271. (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))
  1272. {
  1273. //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);
  1274. //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);
  1275. tmStart.tm_year -= 1900;
  1276. tmStart.tm_mon -= 1;
  1277. tbStart.time = mktime(&tmStart);
  1278. tbStart.millitm = 0;
  1279. tmStop.tm_year -= 1900;
  1280. tmStop.tm_mon -= 1;
  1281. tbStop.time = mktime(&tmStop);
  1282. tbStop.millitm = 0;
  1283. result = DiffTimebSec(tbStart, tbStop);
  1284. //DEBUG_INFO("getStartStop(): %d\n", result);
  1285. }
  1286. else
  1287. {
  1288. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1289. }
  1290. return result;
  1291. }
  1292. int isOvertNow(uint8_t *start)
  1293. {
  1294. int result = NO;
  1295. struct ParsingResult
  1296. {
  1297. int result;
  1298. int scanedElement;
  1299. int year;
  1300. int month;
  1301. int mday;
  1302. int hour;
  1303. int min;
  1304. int sec;
  1305. int tz_hour;
  1306. int tz_min;
  1307. float minSec;
  1308. }parsingResult;
  1309. struct tm tmStart;
  1310. struct timeb tbStart;
  1311. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1312. if(strstr((char*)start, ".") != NULL)
  1313. {
  1314. // Original data with mini second
  1315. if(strstr((char*)start, "Z") != NULL)
  1316. {
  1317. // Original data with Z
  1318. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1319. &parsingResult.year,
  1320. &parsingResult.month,
  1321. &parsingResult.mday,
  1322. &parsingResult.hour,
  1323. &parsingResult.min,
  1324. &parsingResult.sec,
  1325. &parsingResult.minSec);
  1326. }
  1327. else
  1328. {
  1329. // Original data without Z
  1330. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1331. &parsingResult.year,
  1332. &parsingResult.month,
  1333. &parsingResult.mday,
  1334. &parsingResult.hour,
  1335. &parsingResult.min,
  1336. &parsingResult.sec,
  1337. &parsingResult.minSec,
  1338. &parsingResult.tz_hour,
  1339. &parsingResult.tz_min);
  1340. }
  1341. }
  1342. else
  1343. {
  1344. // Original data without mini second
  1345. if(strstr((char*)start, "Z") != NULL)
  1346. {
  1347. // Original data with Z
  1348. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1349. &parsingResult.year,
  1350. &parsingResult.month,
  1351. &parsingResult.mday,
  1352. &parsingResult.hour,
  1353. &parsingResult.min,
  1354. &parsingResult.sec);
  1355. }
  1356. else
  1357. {
  1358. // Original data without Z
  1359. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1360. &parsingResult.year,
  1361. &parsingResult.month,
  1362. &parsingResult.mday,
  1363. &parsingResult.hour,
  1364. &parsingResult.min,
  1365. &parsingResult.sec,
  1366. &parsingResult.tz_hour,
  1367. &parsingResult.tz_min);
  1368. }
  1369. }
  1370. if(parsingResult.scanedElement >= 6)
  1371. {
  1372. tmStart.tm_year = parsingResult.year - 1900;
  1373. tmStart.tm_mon = parsingResult.month - 1;
  1374. tmStart.tm_mday = parsingResult.mday;
  1375. tmStart.tm_hour = parsingResult.hour;
  1376. tmStart.tm_min = parsingResult.min;
  1377. tmStart.tm_sec = parsingResult.sec;
  1378. tmStart.tm_gmtoff = 0;
  1379. tbStart.time = mktime(&tmStart);
  1380. tbStart.timezone = 0;
  1381. tbStart.millitm = 0;
  1382. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1383. if(DiffTimebWithNowSec(tbStart) <= 0)
  1384. result = NO;
  1385. else
  1386. result = YES;
  1387. }
  1388. else
  1389. {
  1390. DEBUG_WARN("Start date parsing error.\n");
  1391. }
  1392. return result;
  1393. }
  1394. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1395. {
  1396. int result = -1;
  1397. struct tm tmStart;
  1398. struct timeb tbStart;
  1399. struct tm tmStop;
  1400. struct timeb tbStop;
  1401. 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) &&
  1402. (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))
  1403. {
  1404. tmStart.tm_year -= 1900;
  1405. tmStart.tm_mon -= 1;
  1406. tbStart.time = mktime(&tmStart);
  1407. tbStart.millitm = 0;
  1408. tmStop.tm_year -= 1900;
  1409. tmStop.tm_mon -= 1;
  1410. tbStop.time = mktime(&tmStop);
  1411. tbStop.millitm = 0;
  1412. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1413. }
  1414. return result;
  1415. }
  1416. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1417. {
  1418. FILE *fp;
  1419. char profileFileName[128];
  1420. char *line = NULL;
  1421. size_t len = 0;
  1422. time_t CurrentTime;
  1423. struct tm *tmComposite;
  1424. struct StructChargingProfile maxProfile;
  1425. uint8_t limitMax=0;
  1426. int compositePeriodIdx = 0;
  1427. CurrentTime = time(NULL);
  1428. tmComposite=localtime(&CurrentTime);
  1429. 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);
  1430. if(isUnitA)
  1431. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1432. else
  1433. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1434. compositeProfile->ChargingSchedule.Duration = durationReq;
  1435. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1436. {
  1437. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1438. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1439. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1440. }
  1441. compositeProfile->ChargingProfileId = 0;
  1442. compositeProfile->StackLevel = 99 ;
  1443. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1444. maxProfile.ChargingProfileId = -1;
  1445. maxProfile.ChargingSchedule.Duration = -1;
  1446. system("rm -f /tmp/*.json");
  1447. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1448. // Search max profile
  1449. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1450. if((access(profileFileName, F_OK))!=-1)
  1451. {
  1452. fp = fopen(profileFileName, "r");
  1453. while(getline(&line, &len, fp) != -1)
  1454. {
  1455. json_object *obj = NULL;
  1456. obj = json_tokener_parse(line);
  1457. if(is_error(obj))
  1458. {
  1459. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1460. }
  1461. else
  1462. {
  1463. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1464. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1465. )
  1466. {
  1467. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1468. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1469. )
  1470. {
  1471. struct tm tmFrom, tmTo;
  1472. struct timeb tbFrom, tbTo;
  1473. 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) &&
  1474. (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))
  1475. {
  1476. tmFrom.tm_year -= 1900;
  1477. tmFrom.tm_mon -= 1;
  1478. tbFrom.time = mktime(&tmFrom);
  1479. tmTo.tm_year -= 1900;
  1480. tmTo.tm_mon -= 1;
  1481. tbTo.time = mktime(&tmTo);
  1482. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1483. {
  1484. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1485. {
  1486. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1487. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1488. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1489. }
  1490. maxProfile.ChargingProfileId = -1;
  1491. maxProfile.StackLevel = -1;
  1492. if(maxProfile.ChargingProfileId == -1)
  1493. DEBUG_INFO("MaxProfile found.\n");
  1494. else
  1495. DEBUG_INFO("MaxProfile updated.\n");
  1496. // Required item
  1497. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1498. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1499. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1500. if(isUnitA)
  1501. {
  1502. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1503. 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++)
  1504. {
  1505. 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"));
  1506. 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?
  1507. 3:
  1508. 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")));
  1509. 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")));
  1510. }
  1511. }
  1512. else
  1513. {
  1514. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1515. 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++)
  1516. {
  1517. 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"));
  1518. 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?
  1519. 3:
  1520. 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")));
  1521. 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));
  1522. }
  1523. }
  1524. // Optional item
  1525. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1526. {
  1527. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1528. }
  1529. else
  1530. {
  1531. sprintf((char*)maxProfile.ValidFrom, " ");
  1532. }
  1533. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1534. {
  1535. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1536. }
  1537. else
  1538. {
  1539. sprintf((char*)maxProfile.ValidTo, " ");
  1540. }
  1541. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1542. {
  1543. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1544. }
  1545. else
  1546. {
  1547. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1548. }
  1549. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1550. {
  1551. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1552. }
  1553. else
  1554. {
  1555. maxProfile.TransactionId = -1;
  1556. }
  1557. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1558. {
  1559. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1560. }
  1561. else
  1562. {
  1563. maxProfile.ChargingSchedule.Duration = 86400;
  1564. }
  1565. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1566. {
  1567. 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")));
  1568. }
  1569. else
  1570. {
  1571. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1572. }
  1573. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1574. {
  1575. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1576. }
  1577. else
  1578. {
  1579. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. else
  1585. {
  1586. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1587. {
  1588. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1590. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1591. }
  1592. maxProfile.ChargingProfileId = -1;
  1593. maxProfile.StackLevel = -1;
  1594. if(maxProfile.ChargingProfileId == -1)
  1595. DEBUG_INFO("MaxProfile found.\n");
  1596. else
  1597. DEBUG_INFO("MaxProfile updated.\n");
  1598. // Required item
  1599. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1600. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1601. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1602. if(isUnitA)
  1603. {
  1604. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1605. 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++)
  1606. {
  1607. 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"));
  1608. 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?
  1609. 3:
  1610. 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")));
  1611. 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")));
  1612. }
  1613. }
  1614. else
  1615. {
  1616. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1617. 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++)
  1618. {
  1619. 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"));
  1620. 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?
  1621. 3:
  1622. 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")));
  1623. 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));
  1624. }
  1625. }
  1626. // Optional item
  1627. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1628. {
  1629. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1630. }
  1631. else
  1632. {
  1633. sprintf((char*)maxProfile.ValidFrom, " ");
  1634. }
  1635. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1636. {
  1637. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1638. }
  1639. else
  1640. {
  1641. sprintf((char*)maxProfile.ValidTo, " ");
  1642. }
  1643. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1644. {
  1645. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1646. }
  1647. else
  1648. {
  1649. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1650. }
  1651. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1652. {
  1653. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1654. }
  1655. else
  1656. {
  1657. maxProfile.TransactionId = -1;
  1658. }
  1659. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1660. {
  1661. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1662. }
  1663. else
  1664. {
  1665. maxProfile.ChargingSchedule.Duration = 86400;
  1666. }
  1667. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1668. {
  1669. 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")));
  1670. }
  1671. else
  1672. {
  1673. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1674. }
  1675. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1676. {
  1677. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1678. }
  1679. else
  1680. {
  1681. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1682. }
  1683. }
  1684. }
  1685. }
  1686. json_object_put(obj);
  1687. }
  1688. fclose(fp);
  1689. /*
  1690. if(maxProfile.ChargingProfileId !=-1)
  1691. {
  1692. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1693. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1694. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1695. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1696. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1697. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1698. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1699. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1700. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1701. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1702. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1703. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1704. {
  1705. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1706. {
  1707. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1708. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1709. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1710. }
  1711. }
  1712. }
  1713. else
  1714. DEBUG_INFO("MaxProfile not found.\n");
  1715. DEBUG_INFO("------------------------------------\n");*/
  1716. }
  1717. if(maxProfile.ChargingProfileId != -1)
  1718. {
  1719. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1720. {
  1721. if(maxProfile.ChargingSchedule.Duration != -1)
  1722. {
  1723. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1724. 0:
  1725. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1726. }
  1727. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1728. {
  1729. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1730. {
  1731. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1732. 0:
  1733. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1734. if(idxPeriod > 0)
  1735. {
  1736. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1737. {
  1738. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1739. }
  1740. }
  1741. }
  1742. }
  1743. }
  1744. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1745. {
  1746. if(maxProfile.ChargingSchedule.Duration != -1)
  1747. {
  1748. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1749. }
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1753. {
  1754. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1755. if(idxPeriod > 0)
  1756. {
  1757. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1758. {
  1759. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1760. }
  1761. }
  1762. }
  1763. }
  1764. }
  1765. else
  1766. {
  1767. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1768. {
  1769. if(maxProfile.ChargingSchedule.Duration != -1)
  1770. {
  1771. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1772. 0:
  1773. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1774. }
  1775. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1776. {
  1777. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1778. {
  1779. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1780. 0:
  1781. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1782. if(idxPeriod > 0)
  1783. {
  1784. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1785. {
  1786. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1787. }
  1788. }
  1789. }
  1790. }
  1791. }
  1792. else
  1793. {
  1794. if(maxProfile.ChargingSchedule.Duration != -1)
  1795. {
  1796. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1797. 0:
  1798. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1799. }
  1800. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1801. {
  1802. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1803. {
  1804. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1805. 0:
  1806. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1807. if(idxPeriod > 0)
  1808. {
  1809. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1810. {
  1811. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. /*
  1819. DEBUG_INFO("MaxProfile after align.\n");
  1820. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1821. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1822. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1823. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1824. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1825. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1826. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1827. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1828. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1829. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1830. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1832. {
  1833. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1834. {
  1835. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1836. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1837. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1838. }
  1839. }
  1840. DEBUG_INFO("------------------------------------\n");*/
  1841. }
  1842. // Find each profile period quantity
  1843. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1844. {
  1845. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1846. limitMax = idx+1;
  1847. }
  1848. if(maxProfile.ChargingProfileId != -1)
  1849. {
  1850. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1851. {
  1852. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1853. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1854. (maxProfile.ChargingSchedule.Duration > 0))
  1855. {
  1856. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1857. {
  1858. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1859. compositePeriodIdx++;
  1860. }
  1861. else
  1862. {
  1863. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1864. }
  1865. }
  1866. }
  1867. }
  1868. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1869. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1870. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1871. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1872. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1873. {
  1874. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1875. {
  1876. compositeProfile->ChargingProfileId = 1;
  1877. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1878. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1879. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1880. }
  1881. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1882. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1883. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1884. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1885. }
  1886. if(line)
  1887. free(line);
  1888. }
  1889. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1890. {
  1891. FILE *fp;
  1892. char profileFileName[128];
  1893. char *line = NULL;
  1894. size_t len = 0;
  1895. time_t CurrentTime;
  1896. struct tm *tmComposite;
  1897. struct StructChargingProfile maxProfile;
  1898. struct StructChargingProfile defaultTxProfile;
  1899. struct StructChargingProfile txProfile;
  1900. struct StructChargingSchedulePeriod tmpPeriod;
  1901. uint8_t limitMax=0;
  1902. uint8_t limitDef=0;
  1903. uint8_t limitTx=0;
  1904. int compositePeriodIdx = 0;
  1905. CurrentTime = time(NULL);
  1906. tmComposite=localtime(&CurrentTime);
  1907. 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);
  1908. if(isUnitA)
  1909. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1910. else
  1911. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1912. compositeProfile->ChargingSchedule.Duration = durationReq;
  1913. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1914. {
  1915. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1916. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1917. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1918. }
  1919. compositeProfile->ChargingProfileId = 0;
  1920. compositeProfile->StackLevel = 99 ;
  1921. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1922. maxProfile.ChargingProfileId = -1;
  1923. defaultTxProfile.ChargingProfileId = -1;
  1924. txProfile.ChargingProfileId = -1;
  1925. maxProfile.ChargingSchedule.Duration = -1;
  1926. defaultTxProfile.ChargingSchedule.Duration = -1;
  1927. txProfile.ChargingSchedule.Duration = -1;
  1928. system("rm -f /tmp/*.json");
  1929. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1930. /*
  1931. * Search valid charging profile
  1932. */
  1933. //DEBUG_INFO("====================================\n");
  1934. // Search tx profile
  1935. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1936. if((access(profileFileName, F_OK))!=-1)
  1937. {
  1938. fp = fopen(profileFileName, "r");
  1939. while(getline(&line, &len, fp) != -1)
  1940. {
  1941. json_object *obj = NULL;
  1942. obj = json_tokener_parse(line);
  1943. if(is_error(obj))
  1944. {
  1945. DEBUG_ERROR("Parse txProfile from file error.\n");
  1946. }
  1947. else
  1948. {
  1949. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1950. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1951. )
  1952. {
  1953. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1954. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1955. )
  1956. {
  1957. struct tm tmFrom, tmTo;
  1958. struct timeb tbFrom, tbTo;
  1959. 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) &&
  1960. (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))
  1961. {
  1962. tmFrom.tm_year -= 1900;
  1963. tmFrom.tm_mon -= 1;
  1964. tbFrom.time = mktime(&tmFrom);
  1965. tmTo.tm_year -= 1900;
  1966. tmTo.tm_mon -= 1;
  1967. tbTo.time = mktime(&tmTo);
  1968. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1969. {
  1970. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1971. {
  1972. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1973. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1974. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1975. }
  1976. txProfile.ChargingProfileId = -1;
  1977. txProfile.StackLevel = -1;
  1978. if(txProfile.ChargingProfileId == -1)
  1979. DEBUG_INFO("TxProfile found.\n");
  1980. else
  1981. DEBUG_INFO("TxProfile updated.\n");
  1982. // Required item
  1983. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1984. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1985. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1986. if(isUnitA)
  1987. {
  1988. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1989. 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++)
  1990. {
  1991. 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"));
  1992. 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?
  1993. 3:
  1994. 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")));
  1995. 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")));
  1996. }
  1997. }
  1998. else
  1999. {
  2000. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2001. 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++)
  2002. {
  2003. 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"));
  2004. 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?
  2005. 3:
  2006. 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")));
  2007. 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));
  2008. }
  2009. }
  2010. // Optional item
  2011. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2012. {
  2013. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2014. }
  2015. else
  2016. {
  2017. sprintf((char*)txProfile.ValidFrom, " ");
  2018. }
  2019. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2020. {
  2021. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2022. }
  2023. else
  2024. {
  2025. sprintf((char*)txProfile.ValidTo, " ");
  2026. }
  2027. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2028. {
  2029. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2030. }
  2031. else
  2032. {
  2033. sprintf((char*)txProfile.RecurrencyKind, " ");
  2034. }
  2035. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2036. {
  2037. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2038. }
  2039. else
  2040. {
  2041. txProfile.TransactionId = -1;
  2042. }
  2043. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2044. {
  2045. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2046. }
  2047. else
  2048. {
  2049. txProfile.ChargingSchedule.Duration = 86400;
  2050. }
  2051. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2052. {
  2053. 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")));
  2054. }
  2055. else
  2056. {
  2057. 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));
  2058. }
  2059. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2060. {
  2061. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2062. }
  2063. else
  2064. {
  2065. txProfile.ChargingSchedule.MinChargingRate = -1;
  2066. }
  2067. }
  2068. }
  2069. }
  2070. else
  2071. {
  2072. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2073. {
  2074. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2075. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2076. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2077. }
  2078. txProfile.ChargingProfileId = -1;
  2079. txProfile.StackLevel = -1;
  2080. if(txProfile.ChargingProfileId == -1)
  2081. DEBUG_INFO("TxProfile found.\n");
  2082. else
  2083. DEBUG_INFO("TxProfile updated.\n");
  2084. // Required item
  2085. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2086. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2087. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2088. if(isUnitA)
  2089. {
  2090. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2091. 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++)
  2092. {
  2093. 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"));
  2094. 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?
  2095. 3:
  2096. 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")));
  2097. 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")));
  2098. }
  2099. }
  2100. else
  2101. {
  2102. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2103. 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++)
  2104. {
  2105. 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"));
  2106. 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?
  2107. 3:
  2108. 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")));
  2109. 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));
  2110. }
  2111. }
  2112. // Optional item
  2113. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2114. {
  2115. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2116. }
  2117. else
  2118. {
  2119. sprintf((char*)txProfile.ValidFrom, " ");
  2120. }
  2121. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2122. {
  2123. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2124. }
  2125. else
  2126. {
  2127. sprintf((char*)txProfile.ValidTo, " ");
  2128. }
  2129. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2130. {
  2131. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2132. }
  2133. else
  2134. {
  2135. sprintf((char*)txProfile.RecurrencyKind, " ");
  2136. }
  2137. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2138. {
  2139. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2140. }
  2141. else
  2142. {
  2143. txProfile.TransactionId = -1;
  2144. }
  2145. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2146. {
  2147. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2148. }
  2149. else
  2150. {
  2151. txProfile.ChargingSchedule.Duration = 86400;
  2152. }
  2153. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2154. {
  2155. 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")));
  2156. }
  2157. else
  2158. {
  2159. 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));
  2160. }
  2161. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2162. {
  2163. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2164. }
  2165. else
  2166. {
  2167. txProfile.ChargingSchedule.MinChargingRate = -1;
  2168. }
  2169. }
  2170. }
  2171. }
  2172. json_object_put(obj);
  2173. }
  2174. fclose(fp);
  2175. /*
  2176. if(txProfile.ChargingProfileId != -1)
  2177. {
  2178. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2179. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2180. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2181. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2182. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2183. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2184. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2185. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2186. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2187. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2188. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2189. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2190. {
  2191. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2192. {
  2193. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2194. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2195. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2196. }
  2197. }
  2198. }
  2199. else
  2200. DEBUG_INFO("TxProfile not found.\n");*/
  2201. }
  2202. // Search default tx profile
  2203. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2204. if((access(profileFileName, F_OK))==-1)
  2205. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2206. if((access(profileFileName, F_OK))!=-1)
  2207. {
  2208. fp = fopen(profileFileName, "r");
  2209. while(getline(&line, &len, fp) != -1)
  2210. {
  2211. json_object *obj = NULL;
  2212. obj = json_tokener_parse(line);
  2213. if(is_error(obj))
  2214. {
  2215. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2216. }
  2217. else
  2218. {
  2219. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2220. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2221. )
  2222. {
  2223. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2224. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2225. )
  2226. {
  2227. struct tm tmFrom, tmTo;
  2228. struct timeb tbFrom, tbTo;
  2229. 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) &&
  2230. (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))
  2231. {
  2232. tmFrom.tm_year -= 1900;
  2233. tmFrom.tm_mon -= 1;
  2234. tbFrom.time = mktime(&tmFrom);
  2235. tmTo.tm_year -= 1900;
  2236. tmTo.tm_mon -= 1;
  2237. tbTo.time = mktime(&tmTo);
  2238. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2239. {
  2240. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2241. {
  2242. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2243. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2244. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2245. }
  2246. defaultTxProfile.ChargingProfileId = -1;
  2247. defaultTxProfile.StackLevel = -1;
  2248. if(defaultTxProfile.ChargingProfileId == -1)
  2249. DEBUG_INFO("TxDefaultProfile found.\n");
  2250. else
  2251. DEBUG_INFO("TxDefaultProfile updated.\n");
  2252. // Required item
  2253. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2254. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2255. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2256. if(isUnitA)
  2257. {
  2258. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2259. 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++)
  2260. {
  2261. 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"));
  2262. 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?
  2263. 3:
  2264. 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")));
  2265. 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")));
  2266. }
  2267. }
  2268. else
  2269. {
  2270. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2271. 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++)
  2272. {
  2273. 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"));
  2274. 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?
  2275. 3:
  2276. 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")));
  2277. 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));
  2278. }
  2279. }
  2280. // Optional item
  2281. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2282. {
  2283. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2284. }
  2285. else
  2286. {
  2287. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2288. }
  2289. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2290. {
  2291. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2292. }
  2293. else
  2294. {
  2295. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2296. }
  2297. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2298. {
  2299. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2300. }
  2301. else
  2302. {
  2303. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2304. }
  2305. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2306. {
  2307. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2308. }
  2309. else
  2310. {
  2311. defaultTxProfile.TransactionId = -1;
  2312. }
  2313. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2314. {
  2315. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2316. }
  2317. else
  2318. {
  2319. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2320. }
  2321. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2322. {
  2323. 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")));
  2324. }
  2325. else
  2326. {
  2327. 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));
  2328. }
  2329. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2330. {
  2331. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2332. }
  2333. else
  2334. {
  2335. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2336. }
  2337. }
  2338. }
  2339. }
  2340. else
  2341. {
  2342. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2343. {
  2344. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2345. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2346. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2347. }
  2348. defaultTxProfile.ChargingProfileId = -1;
  2349. defaultTxProfile.StackLevel = -1;
  2350. if(defaultTxProfile.ChargingProfileId == -1)
  2351. DEBUG_INFO("TxDefaultProfile found.\n");
  2352. else
  2353. DEBUG_INFO("TxDefaultProfile updated.\n");
  2354. // Required item
  2355. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2356. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2357. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2358. if(isUnitA)
  2359. {
  2360. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2361. 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++)
  2362. {
  2363. 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"));
  2364. 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?
  2365. 3:
  2366. 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")));
  2367. 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")));
  2368. }
  2369. }
  2370. else
  2371. {
  2372. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2373. 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++)
  2374. {
  2375. 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"));
  2376. 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?
  2377. 3:
  2378. 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")));
  2379. 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));
  2380. }
  2381. }
  2382. // Optional item
  2383. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2384. {
  2385. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2386. }
  2387. else
  2388. {
  2389. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2390. }
  2391. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2392. {
  2393. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2394. }
  2395. else
  2396. {
  2397. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2398. }
  2399. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2400. {
  2401. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2402. }
  2403. else
  2404. {
  2405. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2406. }
  2407. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2408. {
  2409. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2410. }
  2411. else
  2412. {
  2413. defaultTxProfile.TransactionId = -1;
  2414. }
  2415. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2416. {
  2417. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2418. }
  2419. else
  2420. {
  2421. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2422. }
  2423. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2424. {
  2425. 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")));
  2426. }
  2427. else
  2428. {
  2429. 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));
  2430. }
  2431. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2432. {
  2433. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2434. }
  2435. else
  2436. {
  2437. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2438. }
  2439. }
  2440. }
  2441. }
  2442. json_object_put(obj);
  2443. }
  2444. fclose(fp);
  2445. /*
  2446. if(defaultTxProfile.ChargingProfileId != -1)
  2447. {
  2448. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2449. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2450. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2451. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2452. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2453. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2454. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2455. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2456. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2457. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2458. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2460. {
  2461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2462. {
  2463. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2464. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2465. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2466. }
  2467. }
  2468. }
  2469. else
  2470. DEBUG_INFO("TxDefaultProfile not found.\n");
  2471. DEBUG_INFO("------------------------------------\n");*/
  2472. }
  2473. // Search max profile
  2474. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2475. if((access(profileFileName, F_OK))!=-1)
  2476. {
  2477. fp = fopen(profileFileName, "r");
  2478. while(getline(&line, &len, fp) != -1)
  2479. {
  2480. json_object *obj = NULL;
  2481. obj = json_tokener_parse(line);
  2482. if(is_error(obj))
  2483. {
  2484. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2485. }
  2486. else
  2487. {
  2488. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2489. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2490. )
  2491. {
  2492. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2493. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2494. )
  2495. {
  2496. struct tm tmFrom, tmTo;
  2497. struct timeb tbFrom, tbTo;
  2498. 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) &&
  2499. (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))
  2500. {
  2501. tmFrom.tm_year -= 1900;
  2502. tmFrom.tm_mon -= 1;
  2503. tbFrom.time = mktime(&tmFrom);
  2504. tmTo.tm_year -= 1900;
  2505. tmTo.tm_mon -= 1;
  2506. tbTo.time = mktime(&tmTo);
  2507. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2508. {
  2509. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2510. {
  2511. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2512. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2513. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2514. }
  2515. maxProfile.ChargingProfileId = -1;
  2516. maxProfile.StackLevel = -1;
  2517. if(maxProfile.ChargingProfileId == -1)
  2518. DEBUG_INFO("MaxProfile found.\n");
  2519. else
  2520. DEBUG_INFO("MaxProfile updated.\n");
  2521. // Required item
  2522. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2523. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2524. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2525. if(isUnitA)
  2526. {
  2527. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2528. 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++)
  2529. {
  2530. 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"));
  2531. 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?
  2532. 3:
  2533. 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")));
  2534. 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")));
  2535. }
  2536. }
  2537. else
  2538. {
  2539. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2540. 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++)
  2541. {
  2542. 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"));
  2543. 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?
  2544. 3:
  2545. 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")));
  2546. 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));
  2547. }
  2548. }
  2549. // Optional item
  2550. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2551. {
  2552. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2553. }
  2554. else
  2555. {
  2556. sprintf((char*)maxProfile.ValidFrom, " ");
  2557. }
  2558. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2559. {
  2560. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2561. }
  2562. else
  2563. {
  2564. sprintf((char*)maxProfile.ValidTo, " ");
  2565. }
  2566. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2567. {
  2568. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2569. }
  2570. else
  2571. {
  2572. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2573. }
  2574. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2575. {
  2576. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2577. }
  2578. else
  2579. {
  2580. maxProfile.TransactionId = -1;
  2581. }
  2582. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2583. {
  2584. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2585. }
  2586. else
  2587. {
  2588. maxProfile.ChargingSchedule.Duration = 86400;
  2589. }
  2590. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2591. {
  2592. 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")));
  2593. }
  2594. else
  2595. {
  2596. 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));
  2597. }
  2598. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2599. {
  2600. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2601. }
  2602. else
  2603. {
  2604. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2605. }
  2606. }
  2607. }
  2608. }
  2609. else
  2610. {
  2611. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2612. {
  2613. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2614. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2615. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2616. }
  2617. maxProfile.ChargingProfileId = -1;
  2618. maxProfile.StackLevel = -1;
  2619. if(maxProfile.ChargingProfileId == -1)
  2620. DEBUG_INFO("MaxProfile found.\n");
  2621. else
  2622. DEBUG_INFO("MaxProfile updated.\n");
  2623. // Required item
  2624. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2625. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2626. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2627. if(isUnitA)
  2628. {
  2629. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2630. 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++)
  2631. {
  2632. 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"));
  2633. 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?
  2634. 3:
  2635. 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")));
  2636. 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")));
  2637. }
  2638. }
  2639. else
  2640. {
  2641. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2642. 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++)
  2643. {
  2644. 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"));
  2645. 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?
  2646. 3:
  2647. 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")));
  2648. 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));
  2649. }
  2650. }
  2651. // Optional item
  2652. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2653. {
  2654. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2655. }
  2656. else
  2657. {
  2658. sprintf((char*)maxProfile.ValidFrom, " ");
  2659. }
  2660. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2661. {
  2662. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2663. }
  2664. else
  2665. {
  2666. sprintf((char*)maxProfile.ValidTo, " ");
  2667. }
  2668. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2669. {
  2670. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2671. }
  2672. else
  2673. {
  2674. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2675. }
  2676. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2677. {
  2678. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2679. }
  2680. else
  2681. {
  2682. maxProfile.TransactionId = -1;
  2683. }
  2684. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2685. {
  2686. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2687. }
  2688. else
  2689. {
  2690. maxProfile.ChargingSchedule.Duration = 86400;
  2691. }
  2692. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2693. {
  2694. 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")));
  2695. }
  2696. else
  2697. {
  2698. 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));
  2699. }
  2700. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2701. {
  2702. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2703. }
  2704. else
  2705. {
  2706. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2707. }
  2708. }
  2709. }
  2710. }
  2711. json_object_put(obj);
  2712. }
  2713. fclose(fp);
  2714. /*
  2715. if(maxProfile.ChargingProfileId !=-1)
  2716. {
  2717. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2718. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2719. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2720. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2721. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2722. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2723. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2724. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2725. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2726. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2727. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2729. {
  2730. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2731. {
  2732. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2733. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2734. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2735. }
  2736. }
  2737. }
  2738. else
  2739. DEBUG_INFO("MaxProfile not found.\n");
  2740. DEBUG_INFO("------------------------------------\n");*/
  2741. }
  2742. /*
  2743. * Align found profile start schedule & periods
  2744. */
  2745. //DEBUG_INFO("====================================\n");
  2746. /*
  2747. // For local test usage, force modify found profile start schedule info
  2748. 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);
  2749. 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);
  2750. 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);
  2751. */
  2752. if(txProfile.ChargingProfileId != -1)
  2753. {
  2754. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2755. {
  2756. if(txProfile.ChargingSchedule.Duration != -1)
  2757. {
  2758. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2759. 0:
  2760. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2761. }
  2762. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2763. {
  2764. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2765. {
  2766. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2767. 0:
  2768. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2769. if(idxPeriod > 0)
  2770. {
  2771. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2772. {
  2773. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2774. }
  2775. }
  2776. }
  2777. }
  2778. }
  2779. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2780. {
  2781. if(txProfile.ChargingSchedule.Duration != -1)
  2782. {
  2783. 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?
  2784. 0:
  2785. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2786. }
  2787. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2788. {
  2789. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2790. {
  2791. 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?
  2792. 0:
  2793. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2794. if(idxPeriod > 0)
  2795. {
  2796. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2797. {
  2798. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2799. }
  2800. }
  2801. }
  2802. }
  2803. }
  2804. else
  2805. {
  2806. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2807. {
  2808. if(txProfile.ChargingSchedule.Duration != -1)
  2809. {
  2810. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2811. 0:
  2812. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2813. }
  2814. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2815. {
  2816. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2817. {
  2818. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2819. 0:
  2820. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2821. if(idxPeriod > 0)
  2822. {
  2823. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2824. {
  2825. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2826. }
  2827. }
  2828. }
  2829. }
  2830. }
  2831. else
  2832. {
  2833. if(txProfile.ChargingSchedule.Duration != -1)
  2834. {
  2835. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2836. 0:
  2837. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2838. }
  2839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2840. {
  2841. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2842. {
  2843. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2844. 0:
  2845. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2846. if(idxPeriod > 0)
  2847. {
  2848. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2849. {
  2850. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857. /*
  2858. DEBUG_INFO("txProfile after align.\n");
  2859. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2860. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2861. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2862. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2863. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2864. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2865. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2866. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2867. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2868. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2869. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2870. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2871. {
  2872. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2873. {
  2874. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2875. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2876. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2877. }
  2878. }*/
  2879. }
  2880. if(defaultTxProfile.ChargingProfileId != -1)
  2881. {
  2882. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2883. {
  2884. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2885. {
  2886. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2887. 0:
  2888. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2889. }
  2890. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2891. {
  2892. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2893. {
  2894. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2895. 0:
  2896. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2897. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2898. {
  2899. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2900. }
  2901. if(idxPeriod > 0)
  2902. {
  2903. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2904. {
  2905. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2912. {
  2913. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2914. {
  2915. 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?
  2916. 0:
  2917. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2918. }
  2919. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2920. {
  2921. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2922. {
  2923. 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?
  2924. 0:
  2925. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2926. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2927. {
  2928. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2929. }
  2930. if(idxPeriod > 0)
  2931. {
  2932. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2933. {
  2934. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2935. }
  2936. }
  2937. }
  2938. }
  2939. }
  2940. else
  2941. {
  2942. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2943. {
  2944. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2945. {
  2946. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2947. 0:
  2948. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2949. }
  2950. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2951. {
  2952. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2953. {
  2954. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2955. 0:
  2956. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2957. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2958. {
  2959. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2960. }
  2961. if(idxPeriod > 0)
  2962. {
  2963. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2964. {
  2965. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2966. }
  2967. }
  2968. }
  2969. }
  2970. }
  2971. else
  2972. {
  2973. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2974. {
  2975. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2976. 0:
  2977. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2978. }
  2979. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2980. {
  2981. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2982. {
  2983. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2984. 0:
  2985. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2986. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2987. {
  2988. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2989. }
  2990. if(idxPeriod > 0)
  2991. {
  2992. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2993. {
  2994. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2995. }
  2996. }
  2997. }
  2998. }
  2999. }
  3000. }
  3001. /*
  3002. DEBUG_INFO("defaultTxProfile after align.\n");
  3003. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3004. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3005. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3006. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3007. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3008. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3009. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3010. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3011. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3012. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3013. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3014. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3015. {
  3016. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3017. {
  3018. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3019. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3020. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3021. }
  3022. }
  3023. DEBUG_INFO("------------------------------------\n");*/
  3024. }
  3025. if(maxProfile.ChargingProfileId != -1)
  3026. {
  3027. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3028. {
  3029. if(maxProfile.ChargingSchedule.Duration != -1)
  3030. {
  3031. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3032. 0:
  3033. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3034. }
  3035. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3036. {
  3037. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3038. {
  3039. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3040. 0:
  3041. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3042. if(idxPeriod > 0)
  3043. {
  3044. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3045. {
  3046. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3047. }
  3048. }
  3049. }
  3050. }
  3051. }
  3052. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3053. {
  3054. if(maxProfile.ChargingSchedule.Duration != -1)
  3055. {
  3056. 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?
  3057. 0:
  3058. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3059. }
  3060. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3061. {
  3062. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3063. {
  3064. 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?
  3065. 0:
  3066. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3067. if(idxPeriod > 0)
  3068. {
  3069. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3070. {
  3071. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3072. }
  3073. }
  3074. }
  3075. }
  3076. }
  3077. else
  3078. {
  3079. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3080. {
  3081. if(maxProfile.ChargingSchedule.Duration != -1)
  3082. {
  3083. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3084. 0:
  3085. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3086. }
  3087. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3088. {
  3089. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3090. {
  3091. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3092. 0:
  3093. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3094. if(idxPeriod > 0)
  3095. {
  3096. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3097. {
  3098. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3099. }
  3100. }
  3101. }
  3102. }
  3103. }
  3104. else
  3105. {
  3106. if(maxProfile.ChargingSchedule.Duration != -1)
  3107. {
  3108. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3109. 0:
  3110. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3111. }
  3112. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3113. {
  3114. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3115. {
  3116. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3117. 0:
  3118. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3119. if(idxPeriod > 0)
  3120. {
  3121. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3122. {
  3123. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3124. }
  3125. }
  3126. }
  3127. }
  3128. }
  3129. }
  3130. /*
  3131. DEBUG_INFO("MaxProfile after align.\n");
  3132. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3133. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3134. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3135. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3136. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3137. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3138. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3139. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3140. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3141. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3142. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3143. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3144. {
  3145. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3146. {
  3147. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3148. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3149. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3150. }
  3151. }
  3152. DEBUG_INFO("------------------------------------\n");*/
  3153. }
  3154. /*
  3155. * Merge to conposite schedule
  3156. */
  3157. //DEBUG_INFO("====================================\n");
  3158. // Find each profile period quantity
  3159. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3160. {
  3161. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3162. limitMax = idx+1;
  3163. }
  3164. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3165. {
  3166. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3167. limitDef = idx+1;
  3168. }
  3169. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3170. {
  3171. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3172. limitTx = idx+1;
  3173. }
  3174. // TxProfile found, composite schedule based on it
  3175. if(txProfile.ChargingProfileId != -1)
  3176. {
  3177. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3178. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3179. {
  3180. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3181. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3182. (txProfile.ChargingSchedule.Duration > 0))
  3183. {
  3184. if(maxProfile.ChargingProfileId != -1)
  3185. {
  3186. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3187. {
  3188. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3189. {
  3190. if((maxProfile.ChargingSchedule.Duration > 0))
  3191. {
  3192. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3193. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3194. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3195. }
  3196. else
  3197. {
  3198. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3199. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3200. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3201. }
  3202. }
  3203. if(idxMaxPeriod == (limitMax-1))
  3204. {
  3205. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3206. {
  3207. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3208. {
  3209. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3210. compositePeriodIdx++;
  3211. }
  3212. else
  3213. {
  3214. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3215. }
  3216. }
  3217. }
  3218. }
  3219. }
  3220. else
  3221. {
  3222. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3223. {
  3224. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3225. compositePeriodIdx++;
  3226. }
  3227. else
  3228. {
  3229. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3230. }
  3231. }
  3232. }
  3233. if(idxTxPeriod == (limitTx-1))
  3234. {
  3235. if(defaultTxProfile.ChargingProfileId != -1)
  3236. {
  3237. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3238. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3239. {
  3240. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3241. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3242. (defaultTxProfile.ChargingSchedule.Duration>0))
  3243. {
  3244. if(maxProfile.ChargingProfileId != -1)
  3245. {
  3246. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3247. {
  3248. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3249. {
  3250. if((maxProfile.ChargingSchedule.Duration > 0))
  3251. {
  3252. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3253. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3254. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3255. }
  3256. else
  3257. {
  3258. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3259. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3260. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3261. }
  3262. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3263. {
  3264. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3265. {
  3266. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3267. compositePeriodIdx++;
  3268. }
  3269. else
  3270. {
  3271. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3272. }
  3273. }
  3274. // Delete duplicate period
  3275. if(compositePeriodIdx > 1)
  3276. {
  3277. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3278. {
  3279. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3280. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3281. compositePeriodIdx -= 1;
  3282. }
  3283. }
  3284. }
  3285. else
  3286. {
  3287. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3288. {
  3289. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3290. compositePeriodIdx++;
  3291. }
  3292. else
  3293. {
  3294. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3295. }
  3296. break;
  3297. }
  3298. }
  3299. }
  3300. else
  3301. {
  3302. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3303. {
  3304. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3305. compositePeriodIdx++;
  3306. }
  3307. else
  3308. {
  3309. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3310. }
  3311. }
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. }
  3318. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3319. else if(defaultTxProfile.ChargingProfileId != -1)
  3320. {
  3321. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3322. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3323. {
  3324. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3325. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3326. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3327. {
  3328. if(maxProfile.ChargingProfileId != -1)
  3329. {
  3330. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3331. {
  3332. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3333. {
  3334. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3335. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3336. if((maxProfile.ChargingSchedule.Duration > 0))
  3337. {
  3338. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3339. }
  3340. else
  3341. {
  3342. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3343. }
  3344. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3345. {
  3346. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3347. {
  3348. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3349. compositePeriodIdx++;
  3350. }
  3351. else
  3352. {
  3353. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3354. }
  3355. }
  3356. // Delete duplicate period
  3357. if(compositePeriodIdx > 1)
  3358. {
  3359. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3360. {
  3361. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3362. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3363. compositePeriodIdx -= 1;
  3364. }
  3365. }
  3366. }
  3367. else
  3368. {
  3369. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3370. {
  3371. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3372. compositePeriodIdx++;
  3373. }
  3374. else
  3375. {
  3376. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3377. }
  3378. break;
  3379. }
  3380. }
  3381. }
  3382. else
  3383. {
  3384. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3385. {
  3386. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3387. compositePeriodIdx++;
  3388. }
  3389. else
  3390. {
  3391. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3392. }
  3393. }
  3394. }
  3395. }
  3396. }
  3397. // Fill other period by MaxProfile
  3398. if(maxProfile.ChargingProfileId != -1)
  3399. {
  3400. if(compositePeriodIdx==0)
  3401. {
  3402. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3403. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3404. {
  3405. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3406. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3407. (maxProfile.ChargingSchedule.Duration > 0))
  3408. {
  3409. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3410. {
  3411. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3412. compositePeriodIdx++;
  3413. }
  3414. else
  3415. {
  3416. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3417. }
  3418. }
  3419. }
  3420. }
  3421. else
  3422. {
  3423. int lastCompositePeriodIdx = compositePeriodIdx;
  3424. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3425. {
  3426. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3427. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3428. (maxProfile.ChargingSchedule.Duration > 0))
  3429. {
  3430. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3431. {
  3432. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3433. {
  3434. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3435. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3436. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3437. }
  3438. else
  3439. {
  3440. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3441. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3442. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3443. }
  3444. }
  3445. if(tmpPeriod.Limit != -1)
  3446. {
  3447. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3448. {
  3449. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3450. {
  3451. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3452. compositePeriodIdx++;
  3453. }
  3454. else
  3455. {
  3456. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3457. }
  3458. }
  3459. // Delete duplicate period
  3460. if(compositePeriodIdx > 1)
  3461. {
  3462. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3463. {
  3464. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3465. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3466. compositePeriodIdx -= 1;
  3467. }
  3468. }
  3469. }
  3470. }
  3471. }
  3472. }
  3473. }
  3474. compositeProfile->ChargingSchedule.Duration = durationReq;
  3475. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3476. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3477. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3478. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3479. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3480. {
  3481. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3482. {
  3483. compositeProfile->ChargingProfileId = 1;
  3484. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3485. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3486. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3487. }
  3488. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3489. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3490. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3491. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3492. }
  3493. if(line)
  3494. free(line);
  3495. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3496. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3497. }
  3498. //==========================================
  3499. // Init all share memory
  3500. //==========================================
  3501. int InitShareMemory()
  3502. {
  3503. int result = PASS;
  3504. int MeterSMId;
  3505. //creat ShmSysConfigAndInfo
  3506. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3507. {
  3508. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3509. result = FAIL;
  3510. }
  3511. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3512. {
  3513. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3514. result = FAIL;
  3515. }
  3516. else
  3517. {}
  3518. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3519. {
  3520. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3521. result = FAIL;
  3522. }
  3523. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3524. {
  3525. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3526. result = FAIL;
  3527. }
  3528. else
  3529. {}
  3530. //creat ShmPsuData
  3531. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3532. {
  3533. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3534. result = FAIL;
  3535. }
  3536. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3537. {
  3538. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3539. result = FAIL;
  3540. }
  3541. else
  3542. {}
  3543. //creat ShmOCPP16Data
  3544. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3545. {
  3546. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3547. result = FAIL;
  3548. }
  3549. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3550. {
  3551. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3552. result = FAIL;
  3553. }
  3554. else
  3555. {}
  3556. //creat ShmYesCustomData
  3557. if ((MeterSMId = shmget(ShmYesCustomKey, sizeof(struct StructYesCustomData), 0777)) < 0)
  3558. {
  3559. DEBUG_ERROR("shmget StructYesCustomKey NG\n");
  3560. result = FAIL;
  3561. }
  3562. else if ((ShmYesCustomData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3563. {
  3564. DEBUG_ERROR("shmat StructYesCustomData NG\n");
  3565. result = FAIL;
  3566. }
  3567. else
  3568. {}
  3569. /****************************** For Initial Settings************************************************/
  3570. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3571. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3572. // allocate Configuration memory address
  3573. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3574. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3575. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3576. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3577. //offline MeterValue Interval
  3578. TempMeterValueInterval = 0;
  3579. return result;
  3580. }
  3581. int ProcessShareMemory()
  3582. {
  3583. int result = PASS;
  3584. if(InitShareMemory() == FAIL)
  3585. {
  3586. DEBUG_ERROR("InitShareMemory NG\n");
  3587. if(ShmStatusCodeData!=NULL)
  3588. {
  3589. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3590. }
  3591. result = FAIL;
  3592. }
  3593. // Model name parsing
  3594. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3595. {
  3596. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3597. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3598. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3599. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3600. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3601. ) // 'D' means DC
  3602. {
  3603. // DO series
  3604. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3605. {
  3606. SystemInitial += 1;
  3607. gunTotalNumber += 1;
  3608. gunType[gun_index] = GUN_TYPE_DO;
  3609. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3610. {
  3611. case Gun_Type_Chademo:
  3612. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3613. break;
  3614. case Gun_Type_CCS_2:
  3615. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3616. break;
  3617. case Gun_Type_GB:
  3618. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3619. break;
  3620. case Gun_Type_AC:
  3621. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3622. break;
  3623. default:
  3624. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3625. break;
  3626. }
  3627. }
  3628. }
  3629. else
  3630. {
  3631. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3632. {
  3633. SystemInitial += 1;
  3634. gunTotalNumber += 1;
  3635. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3636. {
  3637. case Gun_Type_Chademo:
  3638. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3639. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3640. break;
  3641. case Gun_Type_CCS_2:
  3642. gunType[gun_index] = GUN_TYPE_CCS;
  3643. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3644. break;
  3645. case Gun_Type_GB:
  3646. gunType[gun_index] = GUN_TYPE_GBT;
  3647. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3648. break;
  3649. case Gun_Type_AC:
  3650. gunType[gun_index] = GUN_TYPE_AC;
  3651. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3652. break;
  3653. default:
  3654. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3655. break;
  3656. }
  3657. }
  3658. }
  3659. }
  3660. else
  3661. {
  3662. DEBUG_ERROR("Model name parsing fail.\n");
  3663. result = FAIL;
  3664. }
  3665. if(result != PASS)sleep(5);
  3666. return result;
  3667. }
  3668. void checkRemoteStart(uint8_t connectorIdInt)
  3669. {
  3670. uint8_t tempIndex;
  3671. int result = PASS;
  3672. char cmdBuf[512];
  3673. //check Transaction active
  3674. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3675. {
  3676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3677. {
  3678. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3679. }
  3680. else
  3681. {
  3682. tempIndex = connectorIdInt -1;
  3683. }
  3684. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3685. {
  3686. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3687. {
  3688. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3689. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3690. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3691. {
  3692. //Reserved
  3693. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3694. }
  3695. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3696. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3697. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3698. {
  3699. //Reserved
  3700. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3701. result = FAIL;
  3702. goto end;
  3703. }
  3704. else
  3705. {
  3706. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3707. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3708. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3709. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3710. {
  3711. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3712. result = FAIL;
  3713. goto end;
  3714. }
  3715. }//END FOR ELSE
  3716. }
  3717. }// END FOR CHAdeMO_QUANTITY
  3718. }
  3719. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3720. {
  3721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3722. {
  3723. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3724. }
  3725. else
  3726. {
  3727. tempIndex = connectorIdInt -1;
  3728. }
  3729. for (int index = 0; index < CCS_QUANTITY; index++)
  3730. {
  3731. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3732. {
  3733. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3734. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3735. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3736. {
  3737. //Reserved
  3738. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3739. }
  3740. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3741. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3742. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3743. {
  3744. //Reserved
  3745. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3746. result = FAIL;
  3747. goto end;
  3748. }
  3749. else
  3750. {
  3751. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3752. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3753. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3754. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3755. {
  3756. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3757. result = FAIL;
  3758. goto end;
  3759. }
  3760. }// END FOR ELSE
  3761. }
  3762. }// END FOR CCS_QUANTITY
  3763. }
  3764. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3765. {
  3766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3767. {
  3768. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3769. }
  3770. else
  3771. {
  3772. tempIndex = connectorIdInt -1;
  3773. }
  3774. for (int index = 0; index < GB_QUANTITY; index++)
  3775. {
  3776. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3777. {
  3778. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3779. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3780. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3781. {
  3782. //Reserved
  3783. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3784. }
  3785. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3786. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3787. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3788. {
  3789. //Reserved
  3790. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3791. result = FAIL;
  3792. goto end;
  3793. }
  3794. else
  3795. {
  3796. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3797. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3798. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3799. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3800. {
  3801. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3802. result = FAIL;
  3803. goto end;
  3804. }
  3805. }// END FOR ELSE
  3806. }
  3807. } // END FOR GB_QUANTITY
  3808. }
  3809. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3810. {
  3811. tempIndex = connectorIdInt -1;
  3812. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3813. {
  3814. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3815. {
  3816. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3817. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3818. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3819. {
  3820. //Reserved
  3821. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3822. }
  3823. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3824. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3825. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3826. {
  3827. //Reserved
  3828. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3829. result = FAIL;
  3830. goto end;
  3831. }
  3832. else
  3833. {
  3834. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3835. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3836. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3837. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3838. {
  3839. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3840. result = FAIL;
  3841. goto end;
  3842. }
  3843. }// END FOR ELSE
  3844. }
  3845. } // END FOR GB_QUANTITY
  3846. }
  3847. else
  3848. {
  3849. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3850. {
  3851. tempIndex = 2;
  3852. }
  3853. else
  3854. {
  3855. tempIndex = connectorIdInt -1;
  3856. }
  3857. for (int index = 0; index < AC_QUANTITY; index++)
  3858. {
  3859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3860. {
  3861. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3862. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3863. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3864. {
  3865. //Reserved
  3866. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3867. }
  3868. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3869. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3870. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3871. {
  3872. //Reserved
  3873. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3874. result = FAIL;
  3875. goto end;
  3876. }
  3877. else
  3878. {
  3879. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3880. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3881. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3882. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3883. {
  3884. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3885. result = FAIL;
  3886. goto end;
  3887. }
  3888. }//END FOR ELSE
  3889. }
  3890. }// END FOR AC_QUANTITY
  3891. }
  3892. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3893. {
  3894. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3895. {
  3896. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3897. {
  3898. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3899. system(cmdBuf);
  3900. }
  3901. }
  3902. else
  3903. {
  3904. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3905. result = FAIL;
  3906. }
  3907. }
  3908. end:
  3909. if(result == PASS)
  3910. {
  3911. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3912. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3913. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3914. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3915. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3916. }
  3917. }
  3918. void CheckSystemValue(void)
  3919. {
  3920. char filenmae[100]={0};
  3921. char str[100]={0};
  3922. int tempIndex = 0;
  3923. //===============================
  3924. // send Heartbeat
  3925. //===============================
  3926. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3927. {
  3928. //parameter for test
  3929. sendHeartbeatRequest(0);
  3930. //==============================================
  3931. // Reset Waiting Time
  3932. //==============================================
  3933. HeartBeatWithNOResponse += 1;
  3934. }
  3935. //===============================
  3936. // send YES CallReader
  3937. //===============================
  3938. if(isWebsocketSendable && (server_sign == TRUE) && (ShmYesCustomData->CallReaderReq == 1) && (getDiffSecNow(clientTime.YesCustomCallReader) >= 5))
  3939. {
  3940. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3941. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"call_reader");
  3942. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data," ");
  3943. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  3944. //ShmYesCustomData->CallReaderReq = 0;
  3945. refreshStartTimer(&clientTime.YesCustomCallReader);
  3946. }
  3947. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3948. {
  3949. // ClockAlign MeterValue
  3950. 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))
  3951. {
  3952. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3953. {
  3954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3955. {
  3956. tempIndex = ((gun_index==2) ? 1: 0);
  3957. }
  3958. else
  3959. {
  3960. tempIndex = gun_index;
  3961. }
  3962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3963. {
  3964. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3965. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3966. {
  3967. reqClockAlignMeter[gun_index] = 1;
  3968. }
  3969. }// End for CHAdeMO
  3970. }
  3971. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3972. {
  3973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3974. {
  3975. tempIndex = ((gun_index==2) ? 1: 0);
  3976. }
  3977. else
  3978. {
  3979. tempIndex = gun_index;
  3980. }
  3981. for (int index = 0; index < CCS_QUANTITY; index++)
  3982. {
  3983. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3984. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3985. {
  3986. reqClockAlignMeter[gun_index] = 1;
  3987. }
  3988. } // End for CCS
  3989. }
  3990. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3991. {
  3992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3993. {
  3994. tempIndex = ((gun_index==2) ? 1: 0);
  3995. }
  3996. else
  3997. {
  3998. tempIndex = gun_index;
  3999. }
  4000. for (int index = 0; index < GB_QUANTITY; index++)
  4001. {
  4002. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4003. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4004. {
  4005. reqClockAlignMeter[gun_index] = 1;
  4006. }
  4007. }// End for GB
  4008. }
  4009. else if(gunType[gun_index] == GUN_TYPE_DO)
  4010. {
  4011. tempIndex = gun_index;
  4012. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4013. {
  4014. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4015. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4016. {
  4017. reqClockAlignMeter[gun_index] = 1;
  4018. }
  4019. }
  4020. }
  4021. else
  4022. {
  4023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4024. {
  4025. tempIndex = 2;
  4026. }
  4027. else
  4028. {
  4029. tempIndex = gun_index;
  4030. }
  4031. for (int index = 0; index < AC_QUANTITY; index++)
  4032. {
  4033. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4034. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4035. {
  4036. reqClockAlignMeter[gun_index] = 1;
  4037. }
  4038. }//End for AC
  4039. }
  4040. }
  4041. }
  4042. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4043. {
  4044. //==========================================
  4045. // Check remote start without connector id
  4046. //==========================================
  4047. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4048. {
  4049. int connectorIdInt = -1;
  4050. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4051. {
  4052. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4053. {
  4054. connectorIdInt = (gun_index+1);
  4055. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4056. checkRemoteStart(connectorIdInt);
  4057. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4058. break;
  4059. }
  4060. }
  4061. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4062. {
  4063. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4064. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4065. }
  4066. }
  4067. //==========================================
  4068. // csu trigger DataTransferReq
  4069. //==========================================
  4070. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4071. {
  4072. sendDataTransferRequest(gun_index);
  4073. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4074. }
  4075. //==========================================
  4076. // CSU Trigger Authorize Request
  4077. //==========================================
  4078. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4079. {
  4080. sendAuthorizeRequest(0);
  4081. authorizeRetryTimes = authorizeRetryTimes + 1;
  4082. if(authorizeRetryTimes < 3)
  4083. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4084. }
  4085. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4086. {
  4087. authorizeRetryTimes = 0;
  4088. SetOcppConnStatus(FALSE);
  4089. server_sign = FALSE;
  4090. }
  4091. 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))
  4092. {
  4093. sendAuthorizeRequest(0);
  4094. }
  4095. //==========================================
  4096. // Charger start transaction
  4097. //==========================================
  4098. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4099. {
  4100. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4101. sendStartTransactionRequest(gun_index);
  4102. refreshStartTimer(&clientTime.StartTransaction);
  4103. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4104. storeTempStopTransaction(gun_index);
  4105. }
  4106. //==========================================
  4107. // Charger stop transaction
  4108. //==========================================
  4109. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4110. {
  4111. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4112. sendStopTransactionRequest(gun_index);
  4113. OCPP_updatePeriodEnergy(gun_index);
  4114. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4115. refreshStartTimer(&clientTime.StopTransaction);
  4116. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4117. }
  4118. //==========================================
  4119. // Charger status report
  4120. //==========================================
  4121. //--- Check Mode Change ---//
  4122. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4123. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4134. {
  4135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4136. {
  4137. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4138. {
  4139. // Sent unplug message for California pricing logic
  4140. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4141. {
  4142. uint8_t ts[20];
  4143. getNowDatetime(ts);
  4144. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4145. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4146. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4147. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4148. }
  4149. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4150. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4151. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4152. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4153. {
  4154. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4155. if((access(filenmae,F_OK))!=-1)
  4156. {
  4157. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4158. sprintf(str,"rm -f %s",filenmae);
  4159. system(str);
  4160. }
  4161. }
  4162. }
  4163. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4164. #if 1 // for TempStopTransaction
  4165. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4166. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4167. {
  4168. checkTempStopTransaction(gun_index);
  4169. }
  4170. #endif
  4171. }
  4172. }
  4173. }
  4174. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4175. {
  4176. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4177. {
  4178. tempIndex = ((gun_index==2) ? 1: 0);
  4179. }
  4180. else
  4181. {
  4182. tempIndex = gun_index;
  4183. }
  4184. for (int index = 0; index < CCS_QUANTITY; index++)
  4185. {
  4186. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4187. {
  4188. 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]*/ )
  4189. {
  4190. // Sent unplug message for California pricing logic
  4191. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4192. {
  4193. uint8_t ts[20];
  4194. getNowDatetime(ts);
  4195. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4196. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4197. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4198. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4199. }
  4200. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4201. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4202. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4203. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4204. {
  4205. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4206. if((access(filenmae,F_OK))!=-1)
  4207. {
  4208. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4209. sprintf(str,"rm -f %s",filenmae);
  4210. system(str);
  4211. }
  4212. }
  4213. }
  4214. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4215. #if 1 // for TempStopTransaction
  4216. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4217. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4218. {
  4219. checkTempStopTransaction(gun_index);
  4220. }
  4221. #endif
  4222. }
  4223. }
  4224. }
  4225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4226. {
  4227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4228. {
  4229. tempIndex = ((gun_index==2) ? 1: 0);
  4230. }
  4231. else
  4232. {
  4233. tempIndex = gun_index;
  4234. }
  4235. for (int index = 0; index < GB_QUANTITY; index++)
  4236. {
  4237. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4238. {
  4239. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4240. {
  4241. // Sent unplug message for California pricing logic
  4242. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4243. {
  4244. uint8_t ts[20];
  4245. getNowDatetime(ts);
  4246. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4247. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4248. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4249. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4250. }
  4251. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4252. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4253. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4254. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4255. {
  4256. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4257. if((access(filenmae,F_OK))!=-1)
  4258. {
  4259. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4260. sprintf(str,"rm -f %s",filenmae);
  4261. system(str);
  4262. }
  4263. }
  4264. }
  4265. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4266. #if 1 // for TempStopTransaction
  4267. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4268. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4269. {
  4270. checkTempStopTransaction(gun_index);
  4271. }
  4272. #endif
  4273. }
  4274. }
  4275. }
  4276. else if(gunType[gun_index] == GUN_TYPE_DO)
  4277. {
  4278. tempIndex = gun_index;
  4279. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4280. {
  4281. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4282. {
  4283. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4284. {
  4285. // Sent unplug message for California pricing logic
  4286. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4287. {
  4288. uint8_t ts[20];
  4289. getNowDatetime(ts);
  4290. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4291. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4292. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4293. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4294. }
  4295. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4296. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4297. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4298. 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_IDLE))) // complete
  4299. {
  4300. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4301. if((access(filenmae,F_OK))!=-1)
  4302. {
  4303. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4304. sprintf(str,"rm -f %s",filenmae);
  4305. system(str);
  4306. }
  4307. }
  4308. }
  4309. 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);
  4310. #if 1 // for TempStopTransaction
  4311. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4312. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4313. {
  4314. checkTempStopTransaction(gun_index);
  4315. }
  4316. #endif
  4317. }
  4318. }
  4319. }
  4320. else
  4321. {
  4322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4323. {
  4324. tempIndex = 2;
  4325. }
  4326. else
  4327. {
  4328. tempIndex = gun_index;
  4329. }
  4330. for (int index = 0; index < AC_QUANTITY; index++)
  4331. {
  4332. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4333. {
  4334. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4335. {
  4336. // Sent unplug message for California pricing logic
  4337. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4338. {
  4339. uint8_t ts[20];
  4340. getNowDatetime(ts);
  4341. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4342. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4343. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4344. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4345. }
  4346. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4347. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4348. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4349. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4350. {
  4351. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4352. if((access(filenmae,F_OK))!=-1)
  4353. {
  4354. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4355. sprintf(str,"rm -f %s",filenmae);
  4356. system(str);
  4357. }
  4358. }
  4359. }
  4360. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4361. #if 1 // for TempStopTransaction
  4362. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4363. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4364. {
  4365. checkTempStopTransaction(gun_index);
  4366. }
  4367. #endif
  4368. }
  4369. }// END
  4370. }
  4371. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4372. (
  4373. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  4374. )
  4375. )
  4376. {
  4377. if(SystemInitial > 0)
  4378. SystemInitial -= 1;
  4379. sendStatusNotificationRequest(gun_index);
  4380. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4381. }
  4382. //==============================================
  4383. // CSU Trigger Smart Charging Profile
  4384. //==============================================
  4385. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4386. {
  4387. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4388. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4389. }
  4390. //==============================================
  4391. // Meter report
  4392. //==============================================
  4393. // Trigger MeterValue
  4394. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4395. {
  4396. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4397. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4398. }
  4399. // Clock-aligned Meter value
  4400. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4401. {
  4402. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4403. reqClockAlignMeter[gun_index] = 0;
  4404. }
  4405. // Sample period MeterValue
  4406. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4407. {
  4408. //check Transaction active
  4409. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4410. {
  4411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4412. {
  4413. tempIndex = ((gun_index==2) ? 1: 0);
  4414. }
  4415. else
  4416. {
  4417. tempIndex = gun_index;
  4418. }
  4419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4420. {
  4421. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4422. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4423. {
  4424. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4425. {
  4426. reqSampleMeter[gun_index] = 1;
  4427. }
  4428. }
  4429. }// End for CHAdeMO
  4430. }
  4431. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4432. {
  4433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4434. {
  4435. tempIndex = ((gun_index==2) ? 1: 0);
  4436. }
  4437. else
  4438. {
  4439. tempIndex = gun_index;
  4440. }
  4441. for (int index = 0; index < CCS_QUANTITY; index++)
  4442. {
  4443. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4444. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4445. {
  4446. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4447. {
  4448. reqSampleMeter[gun_index] = 1;
  4449. }
  4450. }
  4451. } // End for CCS
  4452. }
  4453. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4454. {
  4455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4456. {
  4457. tempIndex = ((gun_index==2) ? 1: 0);
  4458. }
  4459. else
  4460. {
  4461. tempIndex = gun_index;
  4462. }
  4463. for (int index = 0; index < GB_QUANTITY; index++)
  4464. {
  4465. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4466. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4467. {
  4468. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4469. {
  4470. reqSampleMeter[gun_index] = 1;
  4471. }
  4472. }
  4473. }// End for GB
  4474. }
  4475. else if(gunType[gun_index] == GUN_TYPE_DO)
  4476. {
  4477. tempIndex = gun_index;
  4478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4479. {
  4480. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4481. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4482. {
  4483. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4484. {
  4485. reqSampleMeter[gun_index] = 1;
  4486. }
  4487. }
  4488. }
  4489. }
  4490. else
  4491. {
  4492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4493. {
  4494. tempIndex = 2;
  4495. }
  4496. else
  4497. {
  4498. tempIndex = gun_index;
  4499. }
  4500. for (int index = 0; index < AC_QUANTITY; index++)
  4501. {
  4502. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4503. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4504. {
  4505. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4506. {
  4507. reqSampleMeter[gun_index] = 1;
  4508. }
  4509. }
  4510. }//End for AC
  4511. }
  4512. if(reqSampleMeter[gun_index] == 1)
  4513. {
  4514. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4515. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4516. storeTempStopTransaction(gun_index);
  4517. reqSampleMeter[gun_index] = 0;
  4518. }
  4519. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4520. }
  4521. //==============================================
  4522. // Check Connector reserved
  4523. //==============================================
  4524. //===============================
  4525. // Check if Reserve is expired
  4526. //===============================
  4527. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4528. {
  4529. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4530. {
  4531. DEBUG_INFO("reserve expired.\n");
  4532. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4533. }
  4534. }//END OF Check if Reserve is expired
  4535. //==========================================
  4536. // csu trigger FirmwareStatusNotificationReq
  4537. //==========================================
  4538. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4539. {
  4540. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4541. }
  4542. //==========================================
  4543. // csu trigger DiagnosticsStatusNotificationReq
  4544. //==========================================
  4545. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4546. {
  4547. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4548. }
  4549. //==========================================
  4550. // csu trigger CancelReservationConf
  4551. //==========================================
  4552. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4553. {
  4554. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4555. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4556. }
  4557. //==========================================
  4558. // csu trigger ChangeAvailabilityConf
  4559. //==========================================
  4560. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4561. {
  4562. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4563. }
  4564. //==========================================
  4565. // csu trigger UnlockConnectorConf
  4566. //==========================================
  4567. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4568. {
  4569. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4570. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4571. }
  4572. //==========================================
  4573. // csu trigger ReserveNowConf
  4574. //==========================================
  4575. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4576. {
  4577. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4578. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4579. }
  4580. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4581. {
  4582. sendSignCertificateRequest();
  4583. }
  4584. }
  4585. }
  4586. //==========================================
  4587. // send request routine
  4588. //==========================================
  4589. int sendAuthorizeRequest(int gun_index)
  4590. {
  4591. mtrace();
  4592. int result = FAIL;
  4593. char message[100]={0};
  4594. char guid[37];
  4595. char tempdata[65]={0};
  4596. DEBUG_INFO("sendAuthorizeRequest...\n");
  4597. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4598. //Local Authorize
  4599. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4600. {
  4601. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4602. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4603. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4604. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4605. result = PASS;
  4606. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4607. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4608. authorizeRetryTimes = 0;
  4609. return result;
  4610. }
  4611. 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))||
  4612. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4613. {
  4614. // Query from cache
  4615. DEBUG_INFO("Authorize from cache.\n");
  4616. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4617. // Query from list
  4618. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4619. {
  4620. DEBUG_INFO("Authorize from list.\n");
  4621. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4622. }
  4623. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4624. {
  4625. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4626. {
  4627. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4628. }
  4629. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4630. {
  4631. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4632. }
  4633. if(!GetOcppConnStatus())
  4634. {
  4635. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4636. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4637. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4638. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4639. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4640. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4641. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4642. authorizeRetryTimes = 0;
  4643. return result;
  4644. }
  4645. }
  4646. else
  4647. {
  4648. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4649. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4650. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4651. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4652. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4653. else
  4654. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4655. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4656. result = PASS;
  4657. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4658. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4659. authorizeRetryTimes = 0;
  4660. return result;
  4661. }
  4662. }
  4663. //initialize struct Authorize
  4664. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4665. //get data from shared memory
  4666. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4667. random_uuid(guid);
  4668. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4669. LWS_Send(message);
  4670. sprintf(tempdata, "Authorize,%d", gun_index);
  4671. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4672. {
  4673. result = PASS;
  4674. DEBUG_INFO("Authorize mapItem pass\n");
  4675. }
  4676. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4677. return result;
  4678. }
  4679. int sendBootNotificationRequest(void)
  4680. {
  4681. mtrace();
  4682. int result = FAIL;
  4683. char message[500]={0}, payload[700]={0};
  4684. char guid[37]={0};
  4685. char tempdata[65]={0};
  4686. // Fill BootNotification fields
  4687. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4688. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4689. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4690. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4691. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4692. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4693. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4694. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4695. ShmOCPP16Data->ChargeBoxId
  4696. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4697. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4698. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4699. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4700. ,ShmOCPP16Data->BootNotification.CpIccid
  4701. ,ShmOCPP16Data->BootNotification.CpImsi);
  4702. random_uuid(guid);
  4703. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4704. LWS_Send(message);
  4705. sprintf(tempdata, "BootNotification,0");
  4706. 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*/)
  4707. {
  4708. result = PASS;
  4709. }
  4710. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4711. strcpy(queuedata,message);
  4712. return result;
  4713. }
  4714. int sendDataTransferRequest(int gun_index)
  4715. {
  4716. mtrace();
  4717. char message[1000]={0};
  4718. char guid[37]={0};
  4719. char tempdata[65]={0};
  4720. int result = FAIL;
  4721. random_uuid(guid);
  4722. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4723. MESSAGE_TYPE_CALL,
  4724. guid,
  4725. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4726. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4727. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4728. LWS_Send(message);
  4729. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4730. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4731. {
  4732. result = PASS;
  4733. DEBUG_INFO("DataTransfer mapItem pass\n");
  4734. }
  4735. return result;
  4736. }
  4737. int sendDiagnosticsStatusNotificationRequest(char *status)
  4738. {
  4739. mtrace();
  4740. int result = FAIL;
  4741. char message[110]={0};
  4742. char guid[37]={0};
  4743. char tempdata[65]={0};
  4744. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4745. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4746. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4747. random_uuid(guid);
  4748. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4749. LWS_SendNow(message);
  4750. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4751. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4752. {
  4753. result = PASS;
  4754. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4755. }
  4756. //#ifdef SystemLogMessage
  4757. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4758. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4759. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4760. //#endif
  4761. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4762. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4763. //record status
  4764. if(strcmp(status,"Idle")==0)
  4765. {
  4766. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4767. }
  4768. else if(strcmp(status,"Uploaded")==0)
  4769. {
  4770. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4771. }
  4772. else if(strcmp(status,"UploadFailed")==0)
  4773. {
  4774. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4775. }
  4776. else if(strcmp(status,"Uploading")==0)
  4777. {
  4778. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4779. }
  4780. return result;
  4781. }
  4782. int sendFirmwareStatusNotificationRequest(char *status)
  4783. {
  4784. mtrace();
  4785. int result = FAIL;
  4786. char message[110]={0};
  4787. char guid[37]={0};
  4788. char tempdata[65]={0};
  4789. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4790. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4791. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4792. random_uuid(guid);
  4793. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4794. LWS_SendNow(message);
  4795. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4796. 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*/)
  4797. {
  4798. result = PASS;
  4799. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4800. }
  4801. //#ifdef SystemLogMessage
  4802. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4803. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4804. //#endif
  4805. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4806. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4807. //record status
  4808. if(strcmp(status,"Downloaded")==0)
  4809. {
  4810. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4811. }
  4812. else if(strcmp(status,"DownloadFailed")==0)
  4813. {
  4814. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4815. }
  4816. else if(strcmp(status,"Downloading")==0)
  4817. {
  4818. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4819. }
  4820. else if(strcmp(status,"Idle")==0)
  4821. {
  4822. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4823. }
  4824. else if(strcmp(status,"InstallationFailed")==0)
  4825. {
  4826. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4827. }
  4828. else if(strcmp(status,"Installing")==0)
  4829. {
  4830. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4831. }
  4832. else if(strcmp(status,"Installed")==0)
  4833. {
  4834. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4835. }
  4836. return result;
  4837. }
  4838. int sendHeartbeatRequest(int gun_index)
  4839. {
  4840. mtrace();
  4841. int result = FAIL;
  4842. char message[80]={0};
  4843. char guid[37]={0};
  4844. char tempdata[65]={0};
  4845. random_uuid(guid);
  4846. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4847. , MESSAGE_TYPE_CALL
  4848. , guid );
  4849. LWS_Send(message);
  4850. sprintf(tempdata, "Heartbeat,%d", 0);
  4851. 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*/)
  4852. {
  4853. result = PASS;
  4854. }
  4855. return result;
  4856. }
  4857. int sendStartTransactionRequest(int gun_index)
  4858. {
  4859. mtrace();
  4860. int result = FAIL;
  4861. char message[250]={0};
  4862. char guid[37]={0};
  4863. struct timeval tmnow;
  4864. struct tm *tm;
  4865. char buf[28];//, usec_buf[6];
  4866. char tempdata[65]={0};
  4867. int tempIndex = 0;
  4868. DEBUG_INFO("sendStartTransactionRequest...\n");
  4869. gettimeofday(&tmnow, NULL);
  4870. time_t t;
  4871. t = time(NULL);
  4872. /*UTC time and date*/
  4873. tm = gmtime(&t);
  4874. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4875. #if 0 // remove temporally
  4876. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4877. strcat(buf,".");
  4878. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4879. strcat(buf,usec_buf);
  4880. #endif
  4881. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4882. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4883. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4884. // clear StartTransaction Response
  4885. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4886. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4887. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4888. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4889. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4890. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4891. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4892. {
  4893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4894. {
  4895. tempIndex = ((gun_index==2) ? 1: 0);
  4896. }
  4897. else
  4898. {
  4899. tempIndex = gun_index;
  4900. }
  4901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4902. {
  4903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4904. {
  4905. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4906. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4907. }
  4908. }
  4909. }
  4910. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  4921. {
  4922. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4923. {
  4924. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4925. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4926. }
  4927. }
  4928. }
  4929. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  4940. {
  4941. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4942. {
  4943. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4944. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4945. }
  4946. }
  4947. }
  4948. else if(gunType[gun_index] == GUN_TYPE_DO)
  4949. {
  4950. tempIndex = gun_index;
  4951. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4952. {
  4953. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4954. {
  4955. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4956. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4957. }
  4958. }
  4959. }
  4960. else
  4961. {
  4962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4963. {
  4964. tempIndex = 2;
  4965. }
  4966. else
  4967. {
  4968. tempIndex = gun_index;
  4969. }
  4970. for (int index = 0; index < AC_QUANTITY; index++)
  4971. {
  4972. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4973. {
  4974. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4975. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4976. }
  4977. }
  4978. }
  4979. random_uuid(guid);
  4980. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4981. {
  4982. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4983. , gun_index +1
  4984. , MESSAGE_TYPE_CALL
  4985. , guid
  4986. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4987. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4988. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4989. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4990. }
  4991. else
  4992. {
  4993. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4994. , gun_index +1
  4995. , MESSAGE_TYPE_CALL
  4996. , guid
  4997. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4998. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4999. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5000. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5001. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5002. }
  5003. #if 1
  5004. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5005. 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*/)
  5006. {
  5007. result = PASS;
  5008. }
  5009. #endif
  5010. strcpy(queuedata, message);
  5011. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5012. OCPP_insert_transaction_msg(YES, queuedata);
  5013. return result;
  5014. }
  5015. int sendStatusNotificationRequest(int gun_index)
  5016. {
  5017. mtrace();
  5018. int result = FAIL;
  5019. char message[600]={0};
  5020. char guid[37];
  5021. int currentStatus = 0;
  5022. struct timeval tmnow;
  5023. struct tm *tm;
  5024. char buf[28];//, usec_buf[6];
  5025. char tempdata[65]={0};
  5026. int tempIndex = 0;
  5027. uint8_t isStateChanged = TRUE;
  5028. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5029. gettimeofday(&tmnow, NULL);
  5030. time_t t;
  5031. t = time(NULL);
  5032. /*UTC time and date*/
  5033. tm = gmtime(&t);
  5034. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5035. #if 0 // remove temporally
  5036. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5037. strcat(buf,".");
  5038. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5039. strcat(buf,usec_buf);
  5040. #endif
  5041. //printf("%s",buf);
  5042. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5043. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5044. // it's option
  5045. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5046. /*
  5047. enum _SYSTEM_STATUS
  5048. {
  5049. S_BOOTING = 0,
  5050. S_IDLE, = 1
  5051. S_AUTHORIZING, =2
  5052. S_REASSIGN_CHECK, =3
  5053. S_REASSIGN, =4
  5054. S_PRECHARGE, =5
  5055. S_PREPARING_FOR_EV, =6
  5056. S_PREPARING_FOR_EVSE, =7
  5057. S_CHARGING, =8
  5058. S_TERMINATING, =9
  5059. S_COMPLETE, =10
  5060. S_ALARM, =11
  5061. S_FAULT =12
  5062. }
  5063. */
  5064. //check Transaction active
  5065. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5066. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5067. {
  5068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5069. {
  5070. tempIndex = ((gun_index==2) ? 1: 0);
  5071. }
  5072. else
  5073. {
  5074. tempIndex = gun_index;
  5075. }
  5076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5077. {
  5078. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5079. {
  5080. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5081. {
  5082. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5083. {
  5084. currentStatus = Preparing; //OCPP Status: Preparing
  5085. }
  5086. else
  5087. {
  5088. currentStatus = Available; //OCPP Status: Available
  5089. }
  5090. }
  5091. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5092. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5093. ) //S_PRECHARGE
  5094. {
  5095. currentStatus = Preparing; //OCPP Status: Preparing
  5096. }
  5097. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5098. {
  5099. currentStatus = Charging; //OCPP Status: Charging
  5100. }
  5101. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5102. {
  5103. currentStatus = Finishing; //OCPP Status: Finishing
  5104. }
  5105. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5106. {
  5107. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5108. }
  5109. 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
  5110. {
  5111. currentStatus = Unavailable; //OCPP Status: Unavailable
  5112. }
  5113. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5114. {
  5115. currentStatus = Faulted; //OCPP Status: Faulted
  5116. }
  5117. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5118. {
  5119. currentStatus = Reserved; //OCPP Status: Reserved
  5120. }
  5121. } //end of the same index
  5122. }//end of for CHAdeMO_QUANTITY
  5123. }
  5124. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5125. {
  5126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5127. {
  5128. tempIndex = ((gun_index==2) ? 1: 0);
  5129. }
  5130. else
  5131. {
  5132. tempIndex = gun_index;
  5133. }
  5134. for (int index = 0; index < CCS_QUANTITY; index++)
  5135. {
  5136. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5137. {
  5138. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5139. {
  5140. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5141. {
  5142. currentStatus = Preparing; //OCPP Status: Preparing
  5143. }
  5144. else
  5145. {
  5146. currentStatus = Available; //OCPP Status: Available
  5147. }
  5148. }
  5149. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5150. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5151. ) //S_PRECHARGE
  5152. {
  5153. currentStatus = Preparing; //OCPP Status: Preparing
  5154. }
  5155. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5156. {
  5157. currentStatus = Charging; //OCPP Status: Charging
  5158. }
  5159. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5160. {
  5161. currentStatus = Finishing; //OCPP Status: Finishing
  5162. }
  5163. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5164. {
  5165. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5166. }
  5167. 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
  5168. {
  5169. currentStatus = Unavailable; //OCPP Status : Unavailable
  5170. }
  5171. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5172. {
  5173. currentStatus = Faulted; //OCPP Status: Faulted
  5174. }
  5175. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5176. {
  5177. currentStatus = Reserved; //OCPP Status: Reserved
  5178. }
  5179. } //end of the same index
  5180. } // end of for CCS_QUANTITY
  5181. }
  5182. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5183. {
  5184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5185. {
  5186. tempIndex = ((gun_index==2) ? 1: 0);
  5187. }
  5188. else
  5189. {
  5190. tempIndex = gun_index;
  5191. }
  5192. for (int index = 0; index < GB_QUANTITY; index++)
  5193. {
  5194. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5195. {
  5196. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5197. {
  5198. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5199. {
  5200. currentStatus = Preparing; //OCPP Status: Preparing
  5201. }
  5202. else
  5203. {
  5204. currentStatus = Available; //OCPP Status: Available
  5205. }
  5206. }
  5207. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5208. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5209. ) //S_PRECHARGE
  5210. {
  5211. currentStatus = Preparing; //OCPP Status: Preparing
  5212. }
  5213. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5214. {
  5215. currentStatus = Charging; //OCPP Status: Charging
  5216. }
  5217. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5218. {
  5219. currentStatus = Finishing; //OCPP Status: Finishing
  5220. }
  5221. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5222. {
  5223. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5224. }
  5225. 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
  5226. {
  5227. currentStatus = Unavailable; //OCPP Status: Unavailable
  5228. }
  5229. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5230. {
  5231. currentStatus = Faulted; //OCPP Status: Faulted
  5232. }
  5233. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5234. {
  5235. currentStatus = Reserved; //OCPP Status: Reserved
  5236. }
  5237. } //end of the same index
  5238. } // end of for GB_QUANTITY
  5239. }
  5240. else if(gunType[gun_index] == GUN_TYPE_DO)
  5241. {
  5242. tempIndex = gun_index;
  5243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5244. {
  5245. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5246. {
  5247. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5248. {
  5249. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5250. {
  5251. currentStatus = Preparing; //OCPP Status: Preparing
  5252. }
  5253. else
  5254. {
  5255. currentStatus = Available; //OCPP Status: Available
  5256. }
  5257. }
  5258. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5259. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5260. ) //S_PRECHARGE
  5261. {
  5262. currentStatus = Preparing; //OCPP Status: Preparing
  5263. }
  5264. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5265. {
  5266. currentStatus = Charging; //OCPP Status: Charging
  5267. }
  5268. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5269. {
  5270. currentStatus = Finishing; //OCPP Status: Finishing
  5271. }
  5272. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5273. {
  5274. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5275. }
  5276. 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
  5277. {
  5278. currentStatus = Unavailable; //OCPP Status: Unavailable
  5279. }
  5280. 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
  5281. {
  5282. currentStatus = Faulted; //OCPP Status: Faulted
  5283. }
  5284. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5285. {
  5286. currentStatus = Reserved; //OCPP Status: Reserved
  5287. }
  5288. } //end of the same index
  5289. }
  5290. }
  5291. else
  5292. {
  5293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5294. {
  5295. tempIndex = 2;
  5296. }
  5297. else
  5298. {
  5299. tempIndex = gun_index;
  5300. }
  5301. for (int index = 0; index < AC_QUANTITY; index++)
  5302. {
  5303. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5304. {
  5305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5306. {
  5307. 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))
  5308. {
  5309. currentStatus = Preparing; //OCPP Status: Preparing
  5310. }
  5311. else
  5312. {
  5313. currentStatus = Available; //OCPP Status: Available
  5314. }
  5315. }
  5316. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5317. {
  5318. currentStatus = Preparing; //OCPP Status: Preparing
  5319. }
  5320. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5321. {
  5322. currentStatus = Charging; //OCPP Status: Charging
  5323. }
  5324. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5325. {
  5326. currentStatus = Finishing; //OCPP Status: Finishing
  5327. }
  5328. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5329. {
  5330. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5331. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5332. else
  5333. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5334. }
  5335. 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
  5336. {
  5337. currentStatus = Unavailable; //OCPP Status: Unavailable
  5338. }
  5339. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5340. {
  5341. currentStatus = Faulted; //OCPP Status: Faulted
  5342. }
  5343. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5344. {
  5345. currentStatus = Reserved; //OCPP Status: Reserved
  5346. }
  5347. }//end of the same index
  5348. }//end of for AC_QUANTITY
  5349. }
  5350. //it's option
  5351. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5352. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  5353. {
  5354. isStateChanged = FALSE;
  5355. }
  5356. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5357. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5358. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5359. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5360. random_uuid(guid);
  5361. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5362. , MESSAGE_TYPE_CALL
  5363. , guid
  5364. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5365. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5366. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5367. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5368. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5369. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5370. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5371. if((server_sign == TRUE) && isStateChanged)
  5372. {
  5373. LWS_Send(message);
  5374. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5375. 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*/)
  5376. {
  5377. //DEBUG_ERROR("statusNotification mapitem pass");
  5378. result = PASS;
  5379. }
  5380. }
  5381. else
  5382. {
  5383. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5384. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5385. result = PASS;
  5386. }
  5387. return result;
  5388. }
  5389. int sendStopTransactionRequest(int gun_index)
  5390. {
  5391. mtrace();
  5392. int result = FAIL;
  5393. //char message[1500]={0};
  5394. char guid[37]={0};
  5395. char tempdata[65]={0};
  5396. int tempIndex = 0;
  5397. char TempStopTransaction[256];
  5398. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5399. //int idx_sample=0;
  5400. DEBUG_INFO("sendStopTransactionRequest \n");
  5401. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5402. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5403. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5404. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5405. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5408. {
  5409. tempIndex = ((gun_index==2) ? 1: 0);
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5418. {
  5419. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5420. }
  5421. }// END OF CHAdeMO_QUANTITY
  5422. }
  5423. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5424. {
  5425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5426. {
  5427. tempIndex = ((gun_index==2) ? 1: 0);
  5428. }
  5429. else
  5430. {
  5431. tempIndex = gun_index;
  5432. }
  5433. for (int index = 0; index < CCS_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5436. {
  5437. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5438. }
  5439. }// END OF CCS_QUANTITY
  5440. }
  5441. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5442. {
  5443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5444. {
  5445. tempIndex = ((gun_index==2) ? 1: 0);
  5446. }
  5447. else
  5448. {
  5449. tempIndex = gun_index;
  5450. }
  5451. for (int index = 0; index < GB_QUANTITY; index++)
  5452. {
  5453. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5454. {
  5455. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5456. }
  5457. }// END OF GB_QUANTITY
  5458. }
  5459. else if(gunType[gun_index] == GUN_TYPE_DO)
  5460. {
  5461. tempIndex = gun_index;
  5462. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5463. {
  5464. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5465. {
  5466. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5467. }
  5468. }// END OF GB_QUANTITY
  5469. }
  5470. else
  5471. {
  5472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5473. {
  5474. tempIndex = 2;
  5475. }
  5476. else
  5477. {
  5478. tempIndex = gun_index;
  5479. }
  5480. for (int index = 0; index < AC_QUANTITY; index++)
  5481. {
  5482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5483. {
  5484. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5485. }
  5486. }// END OF AC_QUANTITY
  5487. }
  5488. //====================================== Stop Transaction Time =====================================================
  5489. struct timeval tmnow;
  5490. struct tm *tm;
  5491. char buf[28];//, usec_buf[6];
  5492. gettimeofday(&tmnow, NULL);
  5493. time_t t;
  5494. t = time(NULL);
  5495. /*UTC time and date*/
  5496. tm = gmtime(&t);
  5497. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5499. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5500. random_uuid(guid);
  5501. /***********************************transactionData******************************************************/
  5502. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5504. //=================================
  5505. // Transaction_Begin
  5506. //=================================
  5507. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5508. {
  5509. //============================================ Energy.Active.Import.Interval ================================
  5510. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5513. 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*/]);
  5514. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5515. 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))
  5516. {
  5517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5518. }
  5519. else
  5520. {
  5521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5522. }
  5523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5525. }
  5526. //=================================
  5527. // Transaction_End
  5528. //=================================
  5529. // ================================= Current.Import L1 ===============================================
  5530. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5531. {
  5532. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5533. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5534. {
  5535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5536. {
  5537. tempIndex = ((gun_index==2) ? 1: 0);
  5538. }
  5539. else
  5540. {
  5541. tempIndex = gun_index;
  5542. }
  5543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5544. {
  5545. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5546. {
  5547. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5548. }
  5549. }// End of for CHAdeMO_QUANTITY
  5550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5551. }
  5552. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5553. {
  5554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5555. {
  5556. tempIndex = ((gun_index==2) ? 1: 0);
  5557. }
  5558. else
  5559. {
  5560. tempIndex = gun_index;
  5561. }
  5562. for (int index = 0; index < CCS_QUANTITY; index++)
  5563. {
  5564. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5565. {
  5566. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5567. }
  5568. }// End of for CCS_QUANTITY
  5569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5570. }
  5571. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5572. {
  5573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5574. {
  5575. tempIndex = ((gun_index==2) ? 1: 0);
  5576. }
  5577. else
  5578. {
  5579. tempIndex = gun_index;
  5580. }
  5581. for (int index = 0; index < GB_QUANTITY; index++)
  5582. {
  5583. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5584. {
  5585. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5586. }
  5587. }// End of for GB_QUANTITY
  5588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5589. }
  5590. else if(gunType[gun_index] == GUN_TYPE_DO)
  5591. {
  5592. tempIndex = gun_index;
  5593. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5594. {
  5595. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5596. {
  5597. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5598. }
  5599. }
  5600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5601. }
  5602. else
  5603. {
  5604. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5605. {
  5606. tempIndex = 2;
  5607. }
  5608. else
  5609. {
  5610. tempIndex = gun_index;
  5611. }
  5612. for (int index = 0; index < AC_QUANTITY; index++)
  5613. {
  5614. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5615. {
  5616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5617. }
  5618. }// End of for AC_QUANTITY
  5619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5620. }
  5621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5626. }
  5627. // ================================= Energy.Active.Import.Interval ==============================================
  5628. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5629. {
  5630. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5631. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5632. {
  5633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5634. {
  5635. tempIndex = ((gun_index==2) ? 1: 0);
  5636. }
  5637. else
  5638. {
  5639. tempIndex = gun_index;
  5640. }
  5641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5642. {
  5643. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5644. {
  5645. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5646. }
  5647. }// END OF CHAdeMO_QUANTITY
  5648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5649. }
  5650. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5651. {
  5652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5653. {
  5654. tempIndex = ((gun_index==2) ? 1: 0);
  5655. }
  5656. else
  5657. {
  5658. tempIndex = gun_index;
  5659. }
  5660. for (int index = 0; index < CCS_QUANTITY; index++)
  5661. {
  5662. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5663. {
  5664. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5665. }
  5666. }// END OF CCS_QUANTITY
  5667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5668. }
  5669. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5670. {
  5671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5672. {
  5673. tempIndex = ((gun_index==2) ? 1: 0);
  5674. }
  5675. else
  5676. {
  5677. tempIndex = gun_index;
  5678. }
  5679. for (int index = 0; index < GB_QUANTITY; index++)
  5680. {
  5681. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5682. {
  5683. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5684. }
  5685. }// END OF GB_QUANTITY
  5686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5687. }
  5688. else if(gunType[gun_index] == GUN_TYPE_DO)
  5689. {
  5690. tempIndex = gun_index;
  5691. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5692. {
  5693. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5694. {
  5695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5696. }
  5697. }
  5698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5699. }
  5700. else
  5701. {
  5702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5703. {
  5704. tempIndex = 2;
  5705. }
  5706. else
  5707. {
  5708. tempIndex = gun_index;
  5709. }
  5710. for (int index = 0; index < AC_QUANTITY; index++)
  5711. {
  5712. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5713. {
  5714. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5715. }
  5716. }// END OF AC_QUANTITY
  5717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5718. }
  5719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5724. }
  5725. //=================================== Power.Active.Import ==================================================
  5726. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5727. {
  5728. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5729. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5730. {
  5731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5732. {
  5733. tempIndex = ((gun_index==2) ? 1: 0);
  5734. }
  5735. else
  5736. {
  5737. tempIndex = gun_index;
  5738. }
  5739. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5740. {
  5741. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5742. {
  5743. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5744. }
  5745. } // End for CHAdeMO_QUANTITY
  5746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5747. }
  5748. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5749. {
  5750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5751. {
  5752. tempIndex = ((gun_index==2) ? 1: 0);
  5753. }
  5754. else
  5755. {
  5756. tempIndex = gun_index;
  5757. }
  5758. for (int index = 0; index < CCS_QUANTITY; index++)
  5759. {
  5760. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5761. {
  5762. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5763. }
  5764. } // END for CCS_QUANTITY
  5765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5766. }
  5767. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5768. {
  5769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5770. {
  5771. tempIndex = ((gun_index==2) ? 1: 0);
  5772. }
  5773. else
  5774. {
  5775. tempIndex = gun_index;
  5776. }
  5777. for (int index = 0; index < GB_QUANTITY; index++)
  5778. {
  5779. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5780. {
  5781. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5782. }
  5783. }// END for GB_QUANTITY
  5784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5785. }
  5786. else if(gunType[gun_index] == GUN_TYPE_DO)
  5787. {
  5788. tempIndex = gun_index;
  5789. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5790. {
  5791. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5792. {
  5793. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5794. }
  5795. }
  5796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5797. }
  5798. else
  5799. {
  5800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5801. {
  5802. tempIndex = 2;
  5803. }
  5804. else
  5805. {
  5806. tempIndex = gun_index;
  5807. }
  5808. for (int index = 0; index < AC_QUANTITY; index++)
  5809. {
  5810. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5811. {
  5812. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5813. }
  5814. } // END for AC_QUANTITY
  5815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5816. }
  5817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5822. }
  5823. //============================ Voltage L1 ====================================
  5824. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5825. {
  5826. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5827. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5828. {
  5829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5830. {
  5831. tempIndex = ((gun_index==2) ? 1: 0);
  5832. }
  5833. else
  5834. {
  5835. tempIndex = gun_index;
  5836. }
  5837. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5838. {
  5839. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5840. {
  5841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5842. }
  5843. } // END OF FOR CHAdeMO_QUANTITY
  5844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5845. }
  5846. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5847. {
  5848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5849. {
  5850. tempIndex = ((gun_index==2) ? 1: 0);
  5851. }
  5852. else
  5853. {
  5854. tempIndex = gun_index;
  5855. }
  5856. for (int index = 0; index < CCS_QUANTITY; index++)
  5857. {
  5858. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5859. {
  5860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5861. }
  5862. } // END OF FOR CCS_QUANTITY
  5863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5864. }
  5865. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5866. {
  5867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5868. {
  5869. tempIndex = ((gun_index==2) ? 1: 0);
  5870. }
  5871. else
  5872. {
  5873. tempIndex = gun_index;
  5874. }
  5875. for (int index = 0; index < GB_QUANTITY; index++)
  5876. {
  5877. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5878. {
  5879. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5880. }
  5881. } // END OF FOR GB_QUANTITY
  5882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5883. }
  5884. else if(gunType[gun_index] == GUN_TYPE_DO)
  5885. {
  5886. tempIndex = gun_index;
  5887. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5888. {
  5889. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5890. {
  5891. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5892. }
  5893. }
  5894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5895. }
  5896. else
  5897. {
  5898. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5899. {
  5900. tempIndex = 2;
  5901. }
  5902. else
  5903. {
  5904. tempIndex = gun_index;
  5905. }
  5906. for (int index = 0; index < AC_QUANTITY; index++)
  5907. {
  5908. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5909. {
  5910. 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
  5911. }
  5912. } // END OF FOR AC_QUANTITY
  5913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5914. }
  5915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5920. }
  5921. //====================== End SoC ================================
  5922. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5923. {
  5924. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5925. 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))
  5926. {
  5927. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5928. {
  5929. tempIndex = ((gun_index==2) ? 1: 0);
  5930. }
  5931. else
  5932. {
  5933. tempIndex = gun_index;
  5934. }
  5935. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5936. {
  5937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5938. {
  5939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5940. {
  5941. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5942. }
  5943. }
  5944. }
  5945. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5946. {
  5947. for (int index = 0; index < CCS_QUANTITY; index++)
  5948. {
  5949. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5950. {
  5951. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5952. }
  5953. }
  5954. }
  5955. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5956. {
  5957. for (int index = 0; index < GB_QUANTITY; index++)
  5958. {
  5959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5960. {
  5961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5962. }
  5963. }
  5964. }
  5965. else if(gunType[gun_index] == GUN_TYPE_DO)
  5966. {
  5967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5968. {
  5969. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5970. {
  5971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5972. }
  5973. }
  5974. }
  5975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5981. } // END FOR DC CASE
  5982. }
  5983. // ================================= Current.Import L2 ===============================================
  5984. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5985. {
  5986. // AC 3 phse L2 current
  5987. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5988. {
  5989. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5990. {
  5991. tempIndex = 2;
  5992. }
  5993. else
  5994. {
  5995. tempIndex = gun_index;
  5996. }
  5997. for (int index = 0; index < AC_QUANTITY; index++)
  5998. {
  5999. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6000. {
  6001. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6002. }
  6003. }// End of for AC_QUANTITY
  6004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6005. }
  6006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6011. }
  6012. // ================================= Current.Import L3 ===============================================
  6013. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6014. {
  6015. // AC 3 phse L3 current
  6016. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6017. {
  6018. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6019. {
  6020. tempIndex = 2;
  6021. }
  6022. else
  6023. {
  6024. tempIndex = gun_index;
  6025. }
  6026. for (int index = 0; index < AC_QUANTITY; index++)
  6027. {
  6028. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6029. {
  6030. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6031. }
  6032. }// End of for AC_QUANTITY
  6033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6034. }
  6035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6040. }
  6041. //============================ Voltage L2 ====================================
  6042. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6043. {
  6044. // AC 3 phse L2 voltage
  6045. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6046. {
  6047. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6048. {
  6049. tempIndex = 2;
  6050. }
  6051. else
  6052. {
  6053. tempIndex = gun_index;
  6054. }
  6055. for (int index = 0; index < AC_QUANTITY; index++)
  6056. {
  6057. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6058. {
  6059. 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
  6060. }
  6061. } // END OF FOR AC_QUANTITY
  6062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6063. }
  6064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6069. }
  6070. //============================ Voltage L3 ====================================
  6071. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6072. {
  6073. // AC 3 phse L3 voltage
  6074. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6075. {
  6076. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6077. {
  6078. tempIndex = 2;
  6079. }
  6080. else
  6081. {
  6082. tempIndex = gun_index;
  6083. }
  6084. for (int index = 0; index < AC_QUANTITY; index++)
  6085. {
  6086. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6087. {
  6088. 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
  6089. }
  6090. } // END OF FOR AC_QUANTITY
  6091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6092. }
  6093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6098. }
  6099. //====================== Start SoC ================================
  6100. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6101. {
  6102. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6103. 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))
  6104. {
  6105. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6106. {
  6107. tempIndex = ((gun_index==2) ? 1: 0);
  6108. }
  6109. else
  6110. {
  6111. tempIndex = gun_index;
  6112. }
  6113. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6114. {
  6115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6116. {
  6117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6118. {
  6119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6120. }
  6121. }
  6122. }
  6123. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6124. {
  6125. for (int index = 0; index < CCS_QUANTITY; index++)
  6126. {
  6127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6128. {
  6129. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6130. }
  6131. }
  6132. }
  6133. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6134. {
  6135. for (int index = 0; index < GB_QUANTITY; index++)
  6136. {
  6137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6138. {
  6139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6140. }
  6141. }
  6142. }
  6143. else if(gunType[gun_index] == GUN_TYPE_DO)
  6144. {
  6145. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6146. {
  6147. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6148. {
  6149. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6150. }
  6151. }
  6152. }
  6153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6159. } // END FOR DC CASE
  6160. }
  6161. //================================================ Message create ====================================================
  6162. json_object *StopTransaction = json_object_new_object();
  6163. json_object *transactionDatas = json_object_new_array();
  6164. json_object *sampledValues = json_object_new_array();
  6165. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6166. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6167. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6168. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6169. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6170. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6171. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6172. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6173. {
  6174. json_object *transactionData = json_object_new_object();
  6175. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6176. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6177. {
  6178. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6179. {
  6180. json_object *sampledValue = json_object_new_object();
  6181. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6182. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6183. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6184. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6185. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6186. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6187. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6188. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6189. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6190. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6191. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6192. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6193. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6194. json_object_array_add(sampledValues, sampledValue);
  6195. }
  6196. }
  6197. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6198. json_object_array_add(transactionDatas, transactionData);
  6199. }
  6200. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6201. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6202. ,MESSAGE_TYPE_CALL
  6203. ,guid
  6204. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6205. json_object_put(StopTransaction);
  6206. #if 1 // for TempStopTransaction
  6207. //Delete TempStopTransaction
  6208. if((access(TempStopTransaction,F_OK))!=-1)
  6209. {
  6210. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6211. }
  6212. #endif
  6213. #if 1
  6214. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6215. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6216. {
  6217. result = PASS;
  6218. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6219. }
  6220. #endif
  6221. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6222. OCPP_insert_transaction_msg(NO, queuedata);
  6223. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6224. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6225. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6226. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6227. {
  6228. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6229. }
  6230. //for test
  6231. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6232. return result;
  6233. }
  6234. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6235. {
  6236. mtrace();
  6237. int result = FAIL;
  6238. char guid[37]={0};
  6239. char tempdata[65]={0};
  6240. int tempIndex = 0;
  6241. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6242. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6243. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6244. //set value
  6245. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6246. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6247. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6248. -1);
  6249. random_uuid(guid);
  6250. //UTC Date time
  6251. struct timeval tmnow;
  6252. struct tm *tm;
  6253. char buf[28];//, usec_buf[6];
  6254. gettimeofday(&tmnow, NULL);
  6255. time_t t;
  6256. t = time(NULL);
  6257. /*UTC time and date*/
  6258. tm = gmtime(&t);
  6259. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6261. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6262. //********************************(1)Current.Import L1************************************************/
  6263. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6264. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6265. (dataType == ReadingContext_Trigger))
  6266. {
  6267. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6268. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6269. {
  6270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6271. {
  6272. tempIndex = ((gun_index==2) ? 1: 0);
  6273. }
  6274. else
  6275. {
  6276. tempIndex = gun_index;
  6277. }
  6278. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6279. {
  6280. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6281. {
  6282. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6283. }
  6284. }
  6285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6286. }
  6287. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6288. {
  6289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6290. {
  6291. tempIndex = ((gun_index==2) ? 1: 0);
  6292. }
  6293. else
  6294. {
  6295. tempIndex = gun_index;
  6296. }
  6297. for (int index = 0; index < CCS_QUANTITY; index++)
  6298. {
  6299. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6300. {
  6301. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6302. }
  6303. }
  6304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6305. }
  6306. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6307. {
  6308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6309. {
  6310. tempIndex = ((gun_index==2) ? 1: 0);
  6311. }
  6312. else
  6313. {
  6314. tempIndex = gun_index;
  6315. }
  6316. for (int index = 0; index < GB_QUANTITY; index++)
  6317. {
  6318. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6319. {
  6320. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6321. }
  6322. }
  6323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6324. }
  6325. else if(gunType[gun_index] == GUN_TYPE_DO)
  6326. {
  6327. tempIndex = gun_index;
  6328. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6329. {
  6330. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6331. {
  6332. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6333. }
  6334. }
  6335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6336. }
  6337. else
  6338. {
  6339. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6340. {
  6341. tempIndex = 2;
  6342. }
  6343. else
  6344. {
  6345. tempIndex = gun_index;
  6346. }
  6347. for (int index = 0; index < AC_QUANTITY; index++)
  6348. {
  6349. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6350. {
  6351. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6352. }
  6353. }
  6354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6355. }
  6356. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6357. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6358. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6359. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6360. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6361. }
  6362. //********************************(2)Energy.Active.Import.Register ************************************************/
  6363. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6364. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6365. (dataType == ReadingContext_Trigger))
  6366. {
  6367. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6368. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6369. {
  6370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6371. {
  6372. tempIndex = ((gun_index==2) ? 1: 0);
  6373. }
  6374. else
  6375. {
  6376. tempIndex = gun_index;
  6377. }
  6378. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6379. {
  6380. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6381. {
  6382. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6383. }
  6384. }
  6385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6386. }
  6387. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6388. {
  6389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6390. {
  6391. tempIndex = ((gun_index==2) ? 1: 0);
  6392. }
  6393. else
  6394. {
  6395. tempIndex = gun_index;
  6396. }
  6397. for (int index = 0; index < CCS_QUANTITY; index++)
  6398. {
  6399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6400. {
  6401. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6402. }
  6403. }
  6404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6405. }
  6406. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6407. {
  6408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6409. {
  6410. tempIndex = ((gun_index==2) ? 1: 0);
  6411. }
  6412. else
  6413. {
  6414. tempIndex = gun_index;
  6415. }
  6416. for (int index = 0; index < GB_QUANTITY; index++)
  6417. {
  6418. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6419. {
  6420. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6421. }
  6422. }
  6423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6424. }
  6425. else if(gunType[gun_index] == GUN_TYPE_DO)
  6426. {
  6427. tempIndex = gun_index;
  6428. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6429. {
  6430. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6431. {
  6432. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6433. }
  6434. }
  6435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6436. }
  6437. else
  6438. {
  6439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6440. {
  6441. tempIndex = 2;
  6442. }
  6443. else
  6444. {
  6445. tempIndex = gun_index;
  6446. }
  6447. for (int index = 0; index < AC_QUANTITY; index++)
  6448. {
  6449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6450. {
  6451. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6452. }
  6453. }
  6454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6455. }
  6456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6457. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6459. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6461. }
  6462. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6463. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6464. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6465. (dataType == ReadingContext_Trigger))
  6466. {
  6467. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6468. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6469. {
  6470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6471. {
  6472. tempIndex = ((gun_index==2) ? 1: 0);
  6473. }
  6474. else
  6475. {
  6476. tempIndex = gun_index;
  6477. }
  6478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6479. {
  6480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6481. {
  6482. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6483. }
  6484. } // END OF FOR CHAdeMO_QUANTITY
  6485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6486. }
  6487. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6488. {
  6489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6490. {
  6491. tempIndex = ((gun_index==2) ? 1: 0);
  6492. }
  6493. else
  6494. {
  6495. tempIndex = gun_index;
  6496. }
  6497. for (int index = 0; index < CCS_QUANTITY; index++)
  6498. {
  6499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6500. {
  6501. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6502. }
  6503. } // END OF CCS_QUANTITY
  6504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6505. }
  6506. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6507. {
  6508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6509. {
  6510. tempIndex = ((gun_index==2) ? 1: 0);
  6511. }
  6512. else
  6513. {
  6514. tempIndex = gun_index;
  6515. }
  6516. for (int index = 0; index < GB_QUANTITY; index++)
  6517. {
  6518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6519. {
  6520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6521. }
  6522. } // END OF GB_QUANTITY
  6523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6524. }
  6525. else if(gunType[gun_index] == GUN_TYPE_DO)
  6526. {
  6527. tempIndex = gun_index;
  6528. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6529. {
  6530. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6531. {
  6532. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6533. }
  6534. }
  6535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6536. }
  6537. else
  6538. {
  6539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6540. {
  6541. tempIndex = 2;
  6542. }
  6543. else
  6544. {
  6545. tempIndex = gun_index;
  6546. }
  6547. for (int index = 0; index < AC_QUANTITY; index++)
  6548. {
  6549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6550. {
  6551. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6552. }
  6553. }
  6554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6555. }
  6556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6558. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6559. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6561. }
  6562. //********************************(4)Power.Active.Import************************************************/
  6563. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6564. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6565. (dataType == ReadingContext_Trigger))
  6566. {
  6567. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6568. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6569. {
  6570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6571. {
  6572. tempIndex = ((gun_index==2) ? 1: 0);
  6573. }
  6574. else
  6575. {
  6576. tempIndex = gun_index;
  6577. }
  6578. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6579. {
  6580. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6581. {
  6582. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6583. }
  6584. } // END OF FOR
  6585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6586. }
  6587. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6588. {
  6589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6590. {
  6591. tempIndex = ((gun_index==2) ? 1: 0);
  6592. }
  6593. else
  6594. {
  6595. tempIndex = gun_index;
  6596. }
  6597. for (int index = 0; index < CCS_QUANTITY; index++)
  6598. {
  6599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6600. {
  6601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6602. }
  6603. }
  6604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6605. }
  6606. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6607. {
  6608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6609. {
  6610. tempIndex = ((gun_index==2) ? 1: 0);
  6611. }
  6612. else
  6613. {
  6614. tempIndex = gun_index;
  6615. }
  6616. for (int index = 0; index < GB_QUANTITY; index++)
  6617. {
  6618. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6619. {
  6620. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6621. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6622. }
  6623. }
  6624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6625. }
  6626. else if(gunType[gun_index] == GUN_TYPE_DO)
  6627. {
  6628. tempIndex = gun_index;
  6629. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6630. {
  6631. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6632. {
  6633. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6634. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6635. }
  6636. }
  6637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6638. }
  6639. else
  6640. {
  6641. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6642. {
  6643. tempIndex = 2;
  6644. }
  6645. else
  6646. {
  6647. tempIndex = gun_index;
  6648. }
  6649. for (int index = 0; index < AC_QUANTITY; index++)
  6650. {
  6651. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6652. {
  6653. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6654. }
  6655. }
  6656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6657. }
  6658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6663. }
  6664. //***********************************************(5)VOLTAGE L1******************************************************/
  6665. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6666. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6667. (dataType == ReadingContext_Trigger))
  6668. {
  6669. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6670. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6671. {
  6672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6673. {
  6674. tempIndex = ((gun_index==2) ? 1: 0);
  6675. }
  6676. else
  6677. {
  6678. tempIndex = gun_index;
  6679. }
  6680. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6681. {
  6682. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6683. {
  6684. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6685. }
  6686. }
  6687. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6688. }
  6689. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6690. {
  6691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6692. {
  6693. tempIndex = ((gun_index==2) ? 1: 0);
  6694. }
  6695. else
  6696. {
  6697. tempIndex = gun_index;
  6698. }
  6699. for (int index = 0; index < CCS_QUANTITY; index++)
  6700. {
  6701. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6702. {
  6703. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6704. }
  6705. }
  6706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6707. }
  6708. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6709. {
  6710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6711. {
  6712. tempIndex = ((gun_index==2) ? 1: 0);
  6713. }
  6714. else
  6715. {
  6716. tempIndex = gun_index;
  6717. }
  6718. for (int index = 0; index < GB_QUANTITY; index++)
  6719. {
  6720. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6721. {
  6722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6723. }
  6724. }
  6725. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6726. }
  6727. else if(gunType[gun_index] == GUN_TYPE_DO)
  6728. {
  6729. tempIndex = gun_index;
  6730. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6731. {
  6732. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6733. {
  6734. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6735. }
  6736. }
  6737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6738. }
  6739. else
  6740. {
  6741. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6742. {
  6743. tempIndex = 2;
  6744. }
  6745. else
  6746. {
  6747. tempIndex = gun_index;
  6748. }
  6749. for (int index = 0; index < AC_QUANTITY; index++)
  6750. {
  6751. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6752. {
  6753. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6754. }
  6755. }
  6756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6757. }
  6758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6761. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6762. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6763. }
  6764. //***********************************************(6)SOC******************************************************/
  6765. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6766. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6767. (dataType == ReadingContext_Trigger))
  6768. {
  6769. 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))
  6770. {
  6771. //idx_sample=5;
  6772. //sampledValue = NULL;
  6773. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6774. {
  6775. tempIndex = ((gun_index==2) ? 1: 0);
  6776. }
  6777. else
  6778. {
  6779. tempIndex = gun_index;
  6780. }
  6781. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6782. {
  6783. //tempIndex = ((gun_index==2) ? 1: 0);
  6784. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6785. {
  6786. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6787. {
  6788. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6789. }
  6790. }
  6791. }
  6792. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6793. {
  6794. //tempIndex = ((gun_index==2) ? 1: 0);
  6795. for (int index = 0; index < CCS_QUANTITY; index++)
  6796. {
  6797. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6798. {
  6799. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6800. }
  6801. }
  6802. }
  6803. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6804. {
  6805. //tempIndex = ((gun_index==2) ? 1: 0);
  6806. for (int index = 0; index < GB_QUANTITY; index++)
  6807. {
  6808. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6809. {
  6810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6811. }
  6812. }
  6813. }
  6814. else if(gunType[gun_index] == GUN_TYPE_DO)
  6815. {
  6816. //tempIndex = ((gun_index==2) ? 1: 0);
  6817. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6818. {
  6819. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6820. {
  6821. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6822. }
  6823. }
  6824. }
  6825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6826. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6827. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6831. }
  6832. }
  6833. //********************************(7)Current.Import L2************************************************/
  6834. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6835. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6836. (dataType == ReadingContext_Trigger))
  6837. {
  6838. // Only for AC 3 phase
  6839. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6840. {
  6841. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6842. {
  6843. tempIndex = 2;
  6844. }
  6845. else
  6846. {
  6847. tempIndex = gun_index;
  6848. }
  6849. for (int index = 0; index < AC_QUANTITY; index++)
  6850. {
  6851. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6852. {
  6853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6854. }
  6855. }
  6856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6857. }
  6858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6859. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6860. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6861. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6863. }
  6864. //********************************(8)Current.Import L3************************************************/
  6865. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6866. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6867. (dataType == ReadingContext_Trigger))
  6868. {
  6869. // Only for AC 3 phase
  6870. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6871. {
  6872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6873. {
  6874. tempIndex = 2;
  6875. }
  6876. else
  6877. {
  6878. tempIndex = gun_index;
  6879. }
  6880. for (int index = 0; index < AC_QUANTITY; index++)
  6881. {
  6882. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6883. {
  6884. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6885. }
  6886. }
  6887. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6888. }
  6889. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6890. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6891. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6892. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6893. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6894. }
  6895. //***********************************************(9)VOLTAGE L2******************************************************/
  6896. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6897. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6898. (dataType == ReadingContext_Trigger))
  6899. {
  6900. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6901. {
  6902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6903. {
  6904. tempIndex = 2;
  6905. }
  6906. else
  6907. {
  6908. tempIndex = gun_index;
  6909. }
  6910. for (int index = 0; index < AC_QUANTITY; index++)
  6911. {
  6912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6913. {
  6914. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6915. }
  6916. }
  6917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6918. }
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6924. }
  6925. //***********************************************(10)VOLTAGE L3******************************************************/
  6926. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6927. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6928. (dataType == ReadingContext_Trigger))
  6929. {
  6930. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6931. {
  6932. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6933. {
  6934. tempIndex = 2;
  6935. }
  6936. else
  6937. {
  6938. tempIndex = gun_index;
  6939. }
  6940. for (int index = 0; index < AC_QUANTITY; index++)
  6941. {
  6942. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6943. {
  6944. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6945. }
  6946. }
  6947. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6948. }
  6949. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6950. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6951. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6954. }
  6955. //***********************************************(11)Current.Offered******************************************************/
  6956. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6957. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6958. (dataType == ReadingContext_Trigger))
  6959. {
  6960. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6961. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6962. {
  6963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6964. {
  6965. tempIndex = ((gun_index==2) ? 1: 0);
  6966. }
  6967. else
  6968. {
  6969. tempIndex = gun_index;
  6970. }
  6971. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6972. {
  6973. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6974. {
  6975. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6976. }
  6977. } // END OF FOR CHAdeMO_QUANTITY
  6978. }
  6979. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6980. {
  6981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6982. {
  6983. tempIndex = ((gun_index==2) ? 1: 0);
  6984. }
  6985. else
  6986. {
  6987. tempIndex = gun_index;
  6988. }
  6989. for (int index = 0; index < CCS_QUANTITY; index++)
  6990. {
  6991. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6992. {
  6993. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6994. }
  6995. } // END OF CCS_QUANTITY
  6996. }
  6997. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6998. {
  6999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7000. {
  7001. tempIndex = ((gun_index==2) ? 1: 0);
  7002. }
  7003. else
  7004. {
  7005. tempIndex = gun_index;
  7006. }
  7007. for (int index = 0; index < GB_QUANTITY; index++)
  7008. {
  7009. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7010. {
  7011. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7012. }
  7013. } // END OF GB_QUANTITY
  7014. }
  7015. else if(gunType[gun_index] == GUN_TYPE_DO)
  7016. {
  7017. tempIndex = gun_index;
  7018. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7019. {
  7020. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7021. {
  7022. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7023. }
  7024. }
  7025. }
  7026. else
  7027. {
  7028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7029. {
  7030. tempIndex = 2;
  7031. }
  7032. else
  7033. {
  7034. tempIndex = gun_index;
  7035. }
  7036. for (int index = 0; index < AC_QUANTITY; index++)
  7037. {
  7038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7039. {
  7040. uint16_t currentOffer;
  7041. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7042. {
  7043. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7044. }
  7045. else
  7046. {
  7047. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7048. }
  7049. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7050. }
  7051. }
  7052. }
  7053. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7056. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7057. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7058. }
  7059. //***********************************************(12)Power.Offered******************************************************/
  7060. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7061. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7062. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7063. {
  7064. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7065. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7066. {
  7067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7068. {
  7069. tempIndex = ((gun_index==2) ? 1: 0);
  7070. }
  7071. else
  7072. {
  7073. tempIndex = gun_index;
  7074. }
  7075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7078. {
  7079. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7080. }
  7081. } // END OF FOR CHAdeMO_QUANTITY
  7082. }
  7083. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7084. {
  7085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7086. {
  7087. tempIndex = ((gun_index==2) ? 1: 0);
  7088. }
  7089. else
  7090. {
  7091. tempIndex = gun_index;
  7092. }
  7093. for (int index = 0; index < CCS_QUANTITY; index++)
  7094. {
  7095. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7096. {
  7097. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7098. }
  7099. } // END OF CCS_QUANTITY
  7100. }
  7101. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7102. {
  7103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7104. {
  7105. tempIndex = ((gun_index==2) ? 1: 0);
  7106. }
  7107. else
  7108. {
  7109. tempIndex = gun_index;
  7110. }
  7111. for (int index = 0; index < GB_QUANTITY; index++)
  7112. {
  7113. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7114. {
  7115. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7116. }
  7117. } // END OF GB_QUANTITY
  7118. }
  7119. else if(gunType[gun_index] == GUN_TYPE_DO)
  7120. {
  7121. tempIndex = gun_index;
  7122. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7123. {
  7124. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7125. {
  7126. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7127. }
  7128. }
  7129. }
  7130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7135. }
  7136. // Message create ====================================================================================================
  7137. if(TRUE)
  7138. {
  7139. json_object *MeterValueReq = json_object_new_object();
  7140. json_object *MeterValues = json_object_new_array();
  7141. json_object *sampledValues = json_object_new_array();
  7142. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7143. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7144. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7145. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7146. {
  7147. json_object *MeterValue = json_object_new_object();
  7148. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7149. {
  7150. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7151. {
  7152. json_object *sampledValue = json_object_new_object();
  7153. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7154. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7155. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7156. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7157. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7158. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7159. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7160. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7161. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7162. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7163. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7164. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7165. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7166. json_object_array_add(sampledValues, sampledValue);
  7167. }
  7168. }
  7169. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7170. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7171. json_object_array_add(MeterValues, MeterValue);
  7172. }
  7173. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7174. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7175. ,gun_index + 1
  7176. ,MESSAGE_TYPE_CALL
  7177. ,guid
  7178. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7179. json_object_put(MeterValueReq);
  7180. }
  7181. // Put request guid to hash map
  7182. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7183. 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*/)
  7184. {
  7185. result = PASS;
  7186. //DEBUG_INFO("MeterValues mapitem pass\n");
  7187. }
  7188. if((dataType != ReadingContext_Trigger) &&
  7189. (dataType != ReadingContext_Sample_Clock) &&
  7190. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7191. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7192. else
  7193. {
  7194. if(FirstHeartBeat)
  7195. LWS_Send(queuedata +2);
  7196. }
  7197. return result;
  7198. }
  7199. int sendLogStatusNotificationRequest(char *status)
  7200. {
  7201. mtrace();
  7202. int result = PASS;
  7203. char message[4096]={0};
  7204. char guid[37]={0};
  7205. char tempdata[128]={0};
  7206. json_object *LogStatusNotification = json_object_new_object();
  7207. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7208. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7209. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7210. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7211. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7212. random_uuid(guid);
  7213. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7214. json_object_put(LogStatusNotification);
  7215. LWS_Send(message);
  7216. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7217. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7218. {
  7219. result = PASS;
  7220. }
  7221. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7222. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7223. return result;
  7224. }
  7225. int sendSecurityEventNotificationRequest()
  7226. {
  7227. mtrace();
  7228. int result = PASS;
  7229. char message[4096]={0};
  7230. char guid[37]={0};
  7231. char tempdata[128]={0};
  7232. json_object *SecurityEventNotification = json_object_new_object();
  7233. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7234. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7235. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7236. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7237. random_uuid(guid);
  7238. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7239. json_object_put(SecurityEventNotification);
  7240. LWS_Send(message);
  7241. sprintf(tempdata, "SecurityEventNotification,0");
  7242. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7243. {
  7244. result = PASS;
  7245. }
  7246. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7247. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7248. return result;
  7249. }
  7250. int sendSignCertificateRequest()
  7251. {
  7252. mtrace();
  7253. int result = PASS;
  7254. char message[4096]={0};
  7255. char guid[37]={0};
  7256. char tempdata[128]={0};
  7257. json_object *SignCertificate = json_object_new_object();
  7258. DEBUG_INFO("sendSignCertificateRequest...\n");
  7259. // Read csr file content
  7260. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7261. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7262. char *line = NULL;
  7263. size_t len = 0;
  7264. while(getline(&line, &len, fp) != -1)
  7265. {
  7266. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7267. {
  7268. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7269. }
  7270. }
  7271. fclose(fp);
  7272. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7273. random_uuid(guid);
  7274. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7275. json_object_put(SignCertificate);
  7276. LWS_Send(message);
  7277. sprintf(tempdata, "SignCertificate,0");
  7278. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7279. {
  7280. result = PASS;
  7281. }
  7282. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7283. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7284. return result;
  7285. }
  7286. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7287. {
  7288. mtrace();
  7289. int result = PASS;
  7290. char message[110]={0};
  7291. char guid[37]={0};
  7292. char tempdata[65]={0};
  7293. json_object *FirmwareStatusNotification = json_object_new_object();
  7294. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7295. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7296. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7297. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7298. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7299. random_uuid(guid);
  7300. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7301. json_object_put(FirmwareStatusNotification);
  7302. LWS_Send(message);
  7303. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7304. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7305. {
  7306. result = PASS;
  7307. }
  7308. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7309. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7310. return result;
  7311. }
  7312. //==========================================
  7313. // send confirm routine
  7314. //==========================================
  7315. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7316. {
  7317. mtrace();
  7318. int result = FAIL;
  7319. char message[100]={0};
  7320. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7321. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7322. LWS_Send(message);
  7323. result = TRUE;
  7324. return result;
  7325. }
  7326. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7327. {
  7328. mtrace();
  7329. int result = FAIL;
  7330. char message[100]={0};
  7331. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7332. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7333. LWS_Send(message);
  7334. result = TRUE;
  7335. return result;
  7336. }
  7337. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7338. {
  7339. mtrace();
  7340. int result = FAIL;
  7341. char message[100]={0};
  7342. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7343. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7344. LWS_Send(message);
  7345. result = TRUE;
  7346. return result;
  7347. }
  7348. int sendClearCacheConfirmation(char *uuid,char *payload)
  7349. {
  7350. mtrace();
  7351. int result = FAIL;
  7352. char message[500]={0};
  7353. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7354. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7355. LWS_Send(message);
  7356. return result;
  7357. }
  7358. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7359. {
  7360. mtrace();
  7361. int result = FAIL;
  7362. char message[500]={0};
  7363. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7364. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7365. LWS_Send(message);
  7366. return result;
  7367. }
  7368. int sendDataTransferConfirmation(char *uuid,char *payload)
  7369. {
  7370. mtrace();
  7371. char statusStr[20]={0};
  7372. char dataStr[10]={0};
  7373. char sstr[20]={0};
  7374. int c = 0;
  7375. char *loc;
  7376. int result = FAIL;
  7377. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7378. /**********************status**************************/
  7379. loc = strstr(payload, "status");
  7380. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7381. c = 0;
  7382. while (loc[3+strlen("status")+c] != '\"')
  7383. {
  7384. sstr[c] = loc[3+strlen("status")+c];
  7385. c++;
  7386. }
  7387. sstr[c] = '\0';
  7388. strcpy(statusStr, sstr);
  7389. /**********************data**************************/
  7390. loc = strstr(payload, "data");
  7391. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7392. c = 0;
  7393. while (loc[3+strlen("data")+c] != '\"')
  7394. {
  7395. sstr[c] = loc[3+strlen("data")+c];
  7396. c++;
  7397. }
  7398. sstr[c] = '\0';
  7399. strcpy(dataStr, sstr);
  7400. return result;
  7401. }
  7402. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7403. {
  7404. mtrace();
  7405. int result = FAIL;
  7406. char message[1000]={0};
  7407. int CompositeScheduleIndex = 0;
  7408. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7409. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7410. if(nPeriod == 0)
  7411. {
  7412. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7413. {
  7414. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7415. ,MESSAGE_TYPE_CALLRESULT
  7416. ,uuid
  7417. ,payload
  7418. ,connectorIdInt);
  7419. }
  7420. else
  7421. {
  7422. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7423. ,MESSAGE_TYPE_CALLRESULT
  7424. ,uuid
  7425. ,payload
  7426. ,connectorIdInt
  7427. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7428. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7429. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7430. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7431. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7432. }
  7433. }
  7434. else
  7435. {
  7436. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7437. ,MESSAGE_TYPE_CALLRESULT
  7438. ,uuid
  7439. ,payload
  7440. ,connectorIdInt
  7441. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7442. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7443. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7444. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7445. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7446. {
  7447. if (idx_sample == 0)
  7448. {
  7449. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7450. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7451. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7452. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7453. }
  7454. else
  7455. {
  7456. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7457. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7458. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7459. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7460. }
  7461. }
  7462. sprintf(message + strlen(message), "]}}]");
  7463. }
  7464. LWS_Send(message);
  7465. result = TRUE;
  7466. return result;
  7467. }
  7468. int sendGetConfigurationConfirmation(char *uuid)
  7469. {
  7470. mtrace();
  7471. int result = FAIL;
  7472. int MaxKeySupported = 0;
  7473. int sentConfigurationNumber= 0;
  7474. int sentunConfigurationNumber= 0;
  7475. char message[1024*10]={0};
  7476. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7477. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7478. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7479. ,MESSAGE_TYPE_CALLRESULT
  7480. ,uuid );
  7481. //configuration key
  7482. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7483. {
  7484. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7485. {
  7486. if (sentConfigurationNumber == 0)
  7487. {
  7488. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7489. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7490. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7491. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7492. }
  7493. else
  7494. {
  7495. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7496. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7497. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7498. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7499. }
  7500. sentConfigurationNumber = sentConfigurationNumber + 1;
  7501. }
  7502. }
  7503. sprintf(message + strlen(message), "]");
  7504. if(UnknownKeynum != 0)
  7505. {
  7506. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7507. //unkown key
  7508. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7509. {
  7510. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7511. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7512. if(sentunConfigurationNumber == 0)
  7513. {
  7514. sprintf(message + strlen(message), "\"%s\""
  7515. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7516. }
  7517. else
  7518. {
  7519. sprintf(message + strlen(message), ",\"%s\""
  7520. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7521. }
  7522. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7523. }
  7524. sprintf(message + strlen(message), "]");
  7525. }
  7526. sprintf(message + strlen(message), "}]");
  7527. LWS_Send(message);
  7528. return result;
  7529. }
  7530. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7531. {
  7532. mtrace();
  7533. int result = FAIL;
  7534. char message[400]={0};
  7535. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7536. if(strcmp(payload,"")==0)
  7537. {
  7538. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7539. }
  7540. else
  7541. {
  7542. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7543. }
  7544. LWS_Send(message);
  7545. result = TRUE;
  7546. return result;
  7547. }
  7548. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7549. {
  7550. mtrace();
  7551. int result = FAIL;
  7552. char message[80]={0};
  7553. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7554. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7555. LWS_Send(message);
  7556. result = TRUE;
  7557. return result;
  7558. }
  7559. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7560. {
  7561. mtrace();
  7562. int result = FAIL;
  7563. char message[80]={0};
  7564. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7565. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7566. LWS_Send(message);
  7567. result = TRUE;
  7568. return result;
  7569. }
  7570. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7571. {
  7572. mtrace();
  7573. int result = FAIL;
  7574. char message[80]={0};
  7575. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7576. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7577. LWS_Send(message);
  7578. result = TRUE;
  7579. return result;
  7580. }
  7581. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7582. {
  7583. mtrace();
  7584. int result = FAIL;
  7585. char message[80]={0};
  7586. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7587. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7588. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7589. LWS_Send(message);
  7590. result = TRUE;
  7591. return result;
  7592. }
  7593. int sendResetConfirmation(char *uuid,char *payload)
  7594. {
  7595. mtrace();
  7596. int result = FAIL;
  7597. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7598. char message[80]={0};
  7599. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7600. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7601. LWS_Send(message);
  7602. result = TRUE;
  7603. return result;
  7604. }
  7605. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7606. {
  7607. mtrace();
  7608. int result = FAIL;
  7609. char message[500]={0};
  7610. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7611. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7612. LWS_Send(message);
  7613. result = TRUE;
  7614. return result;
  7615. }
  7616. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7617. {
  7618. mtrace();
  7619. int result = FAIL;
  7620. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7621. char message[80]={0};
  7622. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7623. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7624. LWS_Send(message);
  7625. result = TRUE;
  7626. return result;
  7627. }
  7628. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7629. {
  7630. mtrace();
  7631. int result = FAIL;
  7632. char message[80]={0};
  7633. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7634. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7635. LWS_Send(message);
  7636. result = TRUE;
  7637. return result;
  7638. }
  7639. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7640. {
  7641. mtrace();
  7642. int result = FAIL;
  7643. char message[80]={0};
  7644. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7645. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7646. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7647. LWS_Send(message);
  7648. result = TRUE;
  7649. return result;
  7650. }
  7651. int sendUpdateFirmwareConfirmation(char *uuid)
  7652. {
  7653. mtrace();
  7654. int result = FAIL;
  7655. char message[60]={0};
  7656. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7657. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7658. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7659. LWS_Send(message);
  7660. result = TRUE;
  7661. return result;
  7662. }
  7663. int sendCertificateSignedConfirmation(char *uuid)
  7664. {
  7665. mtrace();
  7666. int result = PASS;
  7667. char message[4096]={0};
  7668. json_object *CertificateSigned = json_object_new_object();
  7669. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7670. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7671. sprintf(message,"[%d,\"%s\",%s]"
  7672. ,MESSAGE_TYPE_CALLRESULT
  7673. ,uuid
  7674. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7675. json_object_put(CertificateSigned);
  7676. LWS_Send(message);
  7677. return result;
  7678. }
  7679. int sendDeleteCertificateConfirmation(char *uuid)
  7680. {
  7681. mtrace();
  7682. int result = PASS;
  7683. char message[4096]={0};
  7684. json_object *DeleteCertificate = json_object_new_object();
  7685. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7686. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7687. sprintf(message,"[%d,\"%s\",%s]"
  7688. ,MESSAGE_TYPE_CALLRESULT
  7689. ,uuid
  7690. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7691. json_object_put(DeleteCertificate);
  7692. LWS_Send(message);
  7693. return result;
  7694. }
  7695. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7696. {
  7697. mtrace();
  7698. int result = PASS;
  7699. char message[4096]={0};
  7700. json_object *ExtendedTriggerMessage = json_object_new_object();
  7701. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7702. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7703. sprintf(message,"[%d,\"%s\",%s]"
  7704. ,MESSAGE_TYPE_CALLRESULT
  7705. ,uuid
  7706. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7707. json_object_put(ExtendedTriggerMessage);
  7708. LWS_Send(message);
  7709. return result;
  7710. }
  7711. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7712. {
  7713. mtrace();
  7714. int result = PASS;
  7715. char message[4096]={0};
  7716. json_object *GetInstalledCertificateIds = json_object_new_object();
  7717. json_object *certificateHashDataDatas = json_object_new_array();
  7718. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7719. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7720. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7721. {
  7722. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7723. {
  7724. json_object *certificateHashData = json_object_new_object();
  7725. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7726. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7727. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7728. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7729. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7730. }
  7731. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7732. }
  7733. else
  7734. {
  7735. json_object_put(certificateHashDataDatas);
  7736. }
  7737. sprintf(message,"[%d,\"%s\",%s]"
  7738. ,MESSAGE_TYPE_CALLRESULT
  7739. ,uuid
  7740. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7741. json_object_put(GetInstalledCertificateIds);
  7742. LWS_Send(message);
  7743. return result;
  7744. }
  7745. int sendGetLogConfirmation(char *uuid)
  7746. {
  7747. mtrace();
  7748. int result = PASS;
  7749. char message[4096]={0};
  7750. json_object *GetLog = json_object_new_object();
  7751. DEBUG_INFO("sendGetLogConfirmation...\n");
  7752. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7753. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7754. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7755. sprintf(message,"[%d,\"%s\",%s]"
  7756. ,MESSAGE_TYPE_CALLRESULT
  7757. ,uuid
  7758. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7759. json_object_put(GetLog);
  7760. LWS_Send(message);
  7761. return result;
  7762. }
  7763. int sendInstallCertificateConfirmation(char *uuid)
  7764. {
  7765. mtrace();
  7766. int result = PASS;
  7767. char message[4096]={0};
  7768. json_object *InstallCertificate = json_object_new_object();
  7769. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7770. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7771. sprintf(message,"[%d,\"%s\",%s]"
  7772. ,MESSAGE_TYPE_CALLRESULT
  7773. ,uuid
  7774. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7775. json_object_put(InstallCertificate);
  7776. LWS_Send(message);
  7777. return result;
  7778. }
  7779. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7780. {
  7781. mtrace();
  7782. int result = PASS;
  7783. char message[4096]={0};
  7784. json_object *SignedUpdateFirmware = json_object_new_object();
  7785. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7786. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7787. sprintf(message,"[%d,\"%s\",%s]"
  7788. ,MESSAGE_TYPE_CALLRESULT
  7789. ,uuid
  7790. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7791. json_object_put(SignedUpdateFirmware);
  7792. LWS_Send(message);
  7793. return result;
  7794. }
  7795. int sendUnknownConfirmation(char *uuid)
  7796. {
  7797. mtrace();
  7798. int result = PASS;
  7799. char message[256]={0};
  7800. DEBUG_INFO("sendUnknownConfirmation...\n");
  7801. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7802. LWS_Send(message);
  7803. return result;
  7804. }
  7805. //==========================================
  7806. // Handle server request routine Start
  7807. //==========================================
  7808. int handleCancelReservationRequest(char *uuid, char *payload)
  7809. {
  7810. mtrace();
  7811. int result = FAIL;
  7812. int gunNO = 0;
  7813. int reservationIdInt = -1;
  7814. char comfirmstr[20];
  7815. DEBUG_INFO("handleCancelReservationRequest...\n");
  7816. json_object *CancelReservation;
  7817. CancelReservation = json_tokener_parse(payload);
  7818. if(!is_error(CancelReservation))
  7819. {
  7820. // Required data
  7821. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7822. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7823. }
  7824. json_object_put(CancelReservation);
  7825. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7826. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7827. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7828. if(reservationIdInt != -1)
  7829. {
  7830. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7831. //check Transaction active
  7832. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7833. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7834. {
  7835. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7836. {
  7837. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7838. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7839. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7840. {
  7841. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7842. }
  7843. else
  7844. {
  7845. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7846. }
  7847. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7848. goto end;
  7849. }
  7850. }
  7851. for (int index = 0; index < CCS_QUANTITY; index++)
  7852. {
  7853. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7854. {
  7855. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7856. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7857. if(gunType[2] == GUN_TYPE_CCS)
  7858. {
  7859. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7860. }
  7861. else
  7862. {
  7863. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7864. }
  7865. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7866. goto end;
  7867. }
  7868. }
  7869. for (int index = 0; index < GB_QUANTITY; index++)
  7870. {
  7871. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7872. {
  7873. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7874. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7875. if(gunType[2] == GUN_TYPE_GBT)
  7876. {
  7877. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7878. }
  7879. else
  7880. {
  7881. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7882. }
  7883. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7884. goto end;
  7885. }
  7886. }
  7887. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7888. {
  7889. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7890. {
  7891. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7892. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7893. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7894. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7895. goto end;
  7896. }
  7897. }
  7898. for (int index = 0; index < AC_QUANTITY; index++)
  7899. {
  7900. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7901. {
  7902. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7903. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7904. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7905. {
  7906. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7907. }
  7908. else
  7909. {
  7910. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7911. }
  7912. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7913. goto end;
  7914. }
  7915. }
  7916. }
  7917. //The reservationId does NOT match the reservationId
  7918. sendCancelReservationConfirmation(uuid, comfirmstr);
  7919. end:
  7920. // Fill in ocpp packet uuid
  7921. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7922. return result;
  7923. }
  7924. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7925. {
  7926. mtrace();
  7927. int result = FAIL;
  7928. int gunIndex = -1;
  7929. char typeStr[16]={0};
  7930. char comfirmstr[20];
  7931. int specificId = FALSE;
  7932. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7933. json_object *ChangeAvailability;
  7934. ChangeAvailability = json_tokener_parse(payload);
  7935. if(!is_error(ChangeAvailability))
  7936. {
  7937. // Required data
  7938. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7939. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7940. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7941. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7942. }
  7943. json_object_put(ChangeAvailability);
  7944. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7945. {
  7946. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7947. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7948. }
  7949. else if(gunIndex == 0)
  7950. {
  7951. for(int i=0; i < gunTotalNumber; i++)
  7952. {
  7953. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7954. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7955. }
  7956. }
  7957. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7958. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7959. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7960. {
  7961. specificId = TRUE;
  7962. }
  7963. if(specificId == FALSE)
  7964. goto end;
  7965. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7966. {
  7967. //----------------------gunIndex is 0 ------------------------------------------------//
  7968. if(gunIndex == 0)
  7969. {
  7970. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7971. {
  7972. for(int i=0; i < gunTotalNumber; i++)
  7973. {
  7974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7975. {
  7976. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7977. {
  7978. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7979. {
  7980. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7981. goto end;
  7982. }
  7983. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7984. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7985. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7986. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7987. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7988. {
  7989. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7990. goto end;
  7991. }
  7992. }
  7993. }//END FOR CHAdeMO_QUANTITY
  7994. for (int index = 0; index < CCS_QUANTITY; index++)
  7995. {
  7996. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7997. {
  7998. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7999. {
  8000. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8001. goto end;
  8002. }
  8003. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8004. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8005. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8006. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8007. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8008. {
  8009. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8010. goto end;
  8011. }
  8012. }
  8013. }//END FOR CCS_QUANTITY
  8014. for (int index = 0; index < GB_QUANTITY; index++)
  8015. {
  8016. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8017. {
  8018. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8019. {
  8020. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8021. goto end;
  8022. }
  8023. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8024. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8025. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8026. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8027. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8028. {
  8029. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8030. goto end;
  8031. }
  8032. }
  8033. }// END FOR GB_QUANTITY
  8034. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8035. {
  8036. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8037. {
  8038. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8039. {
  8040. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8041. goto end;
  8042. }
  8043. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8044. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8045. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8046. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8047. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8048. {
  8049. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8050. goto end;
  8051. }
  8052. }
  8053. }// END FOR GENERAL_GUN_QUANTITY
  8054. for (int index = 0; index < AC_QUANTITY; index++)
  8055. {
  8056. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8057. {
  8058. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8059. {
  8060. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8061. goto end;
  8062. }
  8063. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8064. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8065. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8066. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8067. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8068. {
  8069. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8070. goto end;
  8071. }
  8072. }
  8073. }//END FOR AC_QUANTITY
  8074. }// END FOR gunTotalNumber
  8075. }
  8076. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8077. {
  8078. for(int i=0; i < gunTotalNumber; i++)
  8079. {
  8080. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8081. {
  8082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8083. goto end;
  8084. }
  8085. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8086. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8087. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8088. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8089. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8090. {
  8091. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8092. goto end;
  8093. }
  8094. }
  8095. }
  8096. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8097. goto end;
  8098. }
  8099. //----------------------gunIndex is not 0 ------------------------------------------------//
  8100. //check Transaction active
  8101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8102. {
  8103. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8104. {
  8105. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8106. {
  8107. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8108. goto end;
  8109. }
  8110. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8111. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8112. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8113. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8114. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8115. {
  8116. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8117. goto end;
  8118. }
  8119. else
  8120. {
  8121. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8122. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8123. goto end;
  8124. }
  8125. }
  8126. }//END FOR CHAdeMO_QUANTITY
  8127. for (int index = 0; index < CCS_QUANTITY; index++)
  8128. {
  8129. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8130. {
  8131. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8132. {
  8133. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8134. goto end;
  8135. }
  8136. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8138. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8141. {
  8142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8143. goto end;
  8144. }
  8145. else
  8146. {
  8147. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8148. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8149. goto end;
  8150. }
  8151. }
  8152. }//END FOR CCS_QUANTITY
  8153. for (int index = 0; index < GB_QUANTITY; index++)
  8154. {
  8155. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8156. {
  8157. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8158. {
  8159. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8160. goto end;
  8161. }
  8162. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8163. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8164. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8165. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8167. {
  8168. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8169. goto end;
  8170. }
  8171. else
  8172. {
  8173. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8174. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8175. goto end;
  8176. }
  8177. }
  8178. }// END FOR GB_QUANTITY
  8179. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8180. {
  8181. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8182. {
  8183. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8184. {
  8185. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8186. goto end;
  8187. }
  8188. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8189. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8190. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8191. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8192. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8193. {
  8194. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8195. goto end;
  8196. }
  8197. else
  8198. {
  8199. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8201. goto end;
  8202. }
  8203. }
  8204. }// END FOR GENERAL_GUN_QUANTITY
  8205. for (int index = 0; index < AC_QUANTITY; index++)
  8206. {
  8207. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8208. {
  8209. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8210. {
  8211. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8212. goto end;
  8213. }
  8214. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8215. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8216. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8217. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8218. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8219. {
  8220. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8221. goto end;
  8222. }
  8223. else
  8224. {
  8225. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8226. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8227. goto end;
  8228. }
  8229. }
  8230. }//END FOR AC_QUANTITY
  8231. }//END FOR AvailabilityTypeStr[Inoperative]
  8232. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8233. {
  8234. //----------------------gunIndex is 0 ------------------------------------------------//
  8235. if(gunIndex == 0)
  8236. {
  8237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8238. {
  8239. for(int i=0; i < gunTotalNumber; i++)
  8240. {
  8241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8242. {
  8243. 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
  8244. {
  8245. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8246. goto end;
  8247. }
  8248. }//END FOR CHAdeMO_QUANTITY
  8249. for (int index = 0; index < CCS_QUANTITY; index++)
  8250. {
  8251. 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
  8252. {
  8253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8254. goto end;
  8255. }
  8256. }//END FOR CCS_QUANTITY
  8257. for (int index = 0; index < GB_QUANTITY; index++)
  8258. {
  8259. 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
  8260. {
  8261. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8262. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8263. goto end;
  8264. }
  8265. }// END FOR GB_QUANTITY
  8266. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8267. {
  8268. 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
  8269. {
  8270. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8271. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8272. goto end;
  8273. }
  8274. }// END FOR GENERAL_GUN_QUANTITY
  8275. for (int index = 0; index < AC_QUANTITY; index++)
  8276. {
  8277. 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
  8278. {
  8279. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8280. goto end;
  8281. }
  8282. }//END FOR CHAdeMO_QUANTITY
  8283. }// END FOR gunTotalNumber
  8284. }
  8285. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8286. {
  8287. for(int i=0; i < gunTotalNumber; i++)
  8288. {
  8289. for (int index = 0; index < AC_QUANTITY; index++)
  8290. {
  8291. 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
  8292. {
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8294. goto end;
  8295. }
  8296. }//END FOR CHAdeMO_QUANTITY
  8297. } // END FOR gunTotalNumber
  8298. }
  8299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8300. goto end;
  8301. }
  8302. //----------------------gunIndex is not 0 ------------------------------------------------//
  8303. //check Transaction active
  8304. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8305. {
  8306. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8307. {
  8308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8309. goto end;
  8310. }
  8311. }//END FOR CHAdeMO_QUANTITY
  8312. for (int index = 0; index < CCS_QUANTITY; index++)
  8313. {
  8314. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8315. {
  8316. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8317. goto end;
  8318. }
  8319. }//END FOR CCS_QUANTITY
  8320. for (int index = 0; index < GB_QUANTITY; index++)
  8321. {
  8322. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8323. {
  8324. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8325. goto end;
  8326. }
  8327. }// END FOR GB_QUANTITY
  8328. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8329. {
  8330. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8331. {
  8332. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8333. goto end;
  8334. }
  8335. }// END FOR GENERAL_GUN_QUANTITY
  8336. for (int index = 0; index < AC_QUANTITY; index++)
  8337. {
  8338. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8339. {
  8340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8341. goto end;
  8342. }
  8343. }//END FOR AC_QUANTITY
  8344. }//END FOR AvailabilityTypeStr[Operative]
  8345. end:
  8346. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8347. {
  8348. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8349. }
  8350. else
  8351. {
  8352. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8353. }
  8354. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8355. {
  8356. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8357. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8358. }
  8359. else if(gunIndex == 0)
  8360. {
  8361. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8362. {
  8363. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8364. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8365. }
  8366. }
  8367. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8368. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8369. return result;
  8370. }
  8371. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8372. {
  8373. mtrace();
  8374. int valueInvalid = NO;
  8375. int result = FAIL;
  8376. char keystr[40]={0};
  8377. char valuestr[501]={0}; //value should be limited in 500 bytes
  8378. char comfirmstr[20]={0};
  8379. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8380. json_object *ChangeConfiguration;
  8381. ChangeConfiguration = json_tokener_parse(payload);
  8382. if(!is_error(ChangeConfiguration))
  8383. {
  8384. // Required data
  8385. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8386. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8387. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8388. {
  8389. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8390. }
  8391. else
  8392. {
  8393. valueInvalid = YES;
  8394. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8395. }
  8396. }
  8397. json_object_put(ChangeConfiguration);
  8398. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8399. {
  8400. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8401. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8402. }
  8403. else
  8404. {
  8405. int status = setKeyValue(keystr, valuestr);
  8406. switch(status)
  8407. {
  8408. case ConfigurationStatus_Accepted:
  8409. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8410. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8411. StoreConfigurationTable();
  8412. break;
  8413. case RebootRequired:
  8414. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8415. StoreConfigurationTable();
  8416. break;
  8417. case NotSupported:
  8418. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8419. break;
  8420. case ConfigurationStatus_Rejected:
  8421. default:
  8422. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8423. break;
  8424. }
  8425. }
  8426. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8427. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8428. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8429. {
  8430. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8431. SetOcppConnStatus(FALSE);
  8432. }
  8433. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8434. {
  8435. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8436. }
  8437. return result;
  8438. }
  8439. int handleClearCacheRequest(char *uuid, char *payload)
  8440. {
  8441. mtrace();
  8442. int result = FAIL;
  8443. char comfirmstr[20];
  8444. char rmFileCmd[100]={0};
  8445. struct stat stats;
  8446. DEBUG_INFO("handleClearCacheRequest...\n");
  8447. stat("/Storage/OCPP", &stats);
  8448. // Check for directory existence
  8449. if (S_ISDIR(stats.st_mode) == 1)
  8450. {}
  8451. else
  8452. {
  8453. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8454. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8455. system(rmFileCmd);
  8456. }
  8457. if(OCPP_cleanLocalCache())
  8458. {
  8459. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8460. }
  8461. else
  8462. {
  8463. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8464. }
  8465. sendClearCacheConfirmation(uuid, comfirmstr);
  8466. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8467. return result;
  8468. }
  8469. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8470. {
  8471. mtrace();
  8472. int result = FAIL;
  8473. int resultRename;
  8474. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8475. char chargingProfilePurposeStr[26]={0};
  8476. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8477. char tempchargingProfilePurposeStr[26]={0};
  8478. char str[100]={0};
  8479. char fname[200]={0};
  8480. char comfirmstr[20]={0};
  8481. char word[1600]={0};
  8482. int clearflag = FALSE;
  8483. int chargingProfileIdIsNULL = FALSE;
  8484. int connectorIsNULL = FALSE;
  8485. int chargingProfilePurposeIsNULL = FALSE;
  8486. int stackLevelIsNULL = FALSE;
  8487. //int GotoEnd = FALSE;
  8488. FILE *fptr1, *fptr2;
  8489. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8490. int n_chargingProfile=0;
  8491. int isEmptyFile = FALSE;
  8492. char sLineWord[1600]={0};
  8493. char chargingProfiles[10][100]={0};
  8494. int ChargeProfileCount = 0;
  8495. int ch;
  8496. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8497. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8498. json_object *ClearChargingProfile;
  8499. ClearChargingProfile = json_tokener_parse(payload);
  8500. if(!is_error(ClearChargingProfile))
  8501. {
  8502. // Optional data
  8503. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8504. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8505. else
  8506. chargingProfileIdIsNULL = TRUE;
  8507. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8508. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8509. else
  8510. connectorIsNULL = TRUE;
  8511. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8512. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8513. else
  8514. chargingProfilePurposeIsNULL = TRUE;
  8515. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8516. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8517. else
  8518. stackLevelIsNULL = TRUE;
  8519. }
  8520. json_object_put(ClearChargingProfile);
  8521. if(connectorIsNULL == FALSE)
  8522. {
  8523. switch(connectorIdInt)
  8524. {
  8525. case 0:
  8526. if(chargingProfilePurposeIsNULL == TRUE)
  8527. {
  8528. int l = 0;
  8529. strcpy(fname, ChargePointMaxProfile_JSON);
  8530. if((access(fname,F_OK))!=-1)
  8531. {
  8532. strcpy(chargingProfiles[l], fname);
  8533. l = l + 1;
  8534. }
  8535. strcpy(fname, TxDefaultProfile_0_JSON);
  8536. if((access(fname,F_OK))!=-1)
  8537. {
  8538. strcpy(chargingProfiles[l], fname);
  8539. l = l + 1;
  8540. }
  8541. ChargeProfileCount = l;
  8542. }
  8543. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8544. {
  8545. strcpy(fname, ChargePointMaxProfile_JSON);
  8546. if((access(fname,F_OK))!=-1)
  8547. {
  8548. strcpy(chargingProfiles[0], fname);
  8549. ChargeProfileCount = 1;
  8550. }
  8551. }
  8552. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8553. {
  8554. strcpy(fname, TxDefaultProfile_0_JSON);
  8555. if((access(fname,F_OK))!=-1)
  8556. {
  8557. strcpy(chargingProfiles[0], fname);
  8558. ChargeProfileCount = 1;
  8559. }
  8560. }
  8561. break;
  8562. default:
  8563. if(chargingProfilePurposeIsNULL == TRUE)
  8564. {
  8565. int m = 0;
  8566. memset(fname, 0, ARRAY_SIZE(fname));
  8567. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8568. if((access(fname,F_OK))!=-1)
  8569. {
  8570. strcpy(chargingProfiles[m], fname);
  8571. m = m + 1;
  8572. }
  8573. memset(fname, 0, ARRAY_SIZE(fname));
  8574. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8575. if((access(fname,F_OK))!=-1)
  8576. {
  8577. strcpy(chargingProfiles[m], fname);
  8578. m = m + 1;
  8579. }
  8580. ChargeProfileCount = m;
  8581. }
  8582. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8583. {
  8584. //strcpy(fname, TxDefaultProfile_1_JSON);
  8585. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8586. if((access(fname,F_OK))!=-1)
  8587. {
  8588. strcpy(chargingProfiles[0], fname);
  8589. ChargeProfileCount = 1;
  8590. }
  8591. }
  8592. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8593. {
  8594. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8595. if((access(fname,F_OK))!=-1)
  8596. {
  8597. strcpy(chargingProfiles[0], fname);
  8598. ChargeProfileCount = 1;
  8599. }
  8600. //strcpy(fname, TxProfile_1_JSON);
  8601. }
  8602. //strcpy(fname, ChargePointMaxProfile_JSON );
  8603. break;
  8604. }
  8605. }
  8606. else // Check all Charging Profiles
  8607. {
  8608. int i = 0;
  8609. char fnametemp[200]={0};
  8610. ChargeProfileCount = 0;
  8611. //Check ChargePointMaxProfile.json exit
  8612. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8613. {
  8614. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8615. i = i + 1;
  8616. }
  8617. //Check TxDefaultProfile_0.json exit
  8618. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8619. {
  8620. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8621. i = i + 1;
  8622. }
  8623. //Check TxDefaultProfile_%d.json
  8624. for(int j=1; j <= gunTotalNumber; j++)
  8625. {
  8626. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8627. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8628. if((access(fnametemp,F_OK))!=-1)
  8629. {
  8630. strcpy(chargingProfiles[i], fnametemp);
  8631. i = i + 1;
  8632. }
  8633. }
  8634. //Check TxProfile_%d.json
  8635. for(int j=1; j <= gunTotalNumber; j++)
  8636. {
  8637. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8638. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8639. if((access(fnametemp,F_OK))!=-1)
  8640. {
  8641. strcpy(chargingProfiles[i], fnametemp);
  8642. i = i + 1;
  8643. }
  8644. }
  8645. ChargeProfileCount = i;
  8646. }// End connectorIsNULL is TRUE
  8647. if(ChargeProfileCount == 0)
  8648. {
  8649. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8650. goto end;
  8651. }
  8652. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8653. {
  8654. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8655. goto end;
  8656. }
  8657. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8658. {
  8659. memset(str, 0, ARRAY_SIZE(str));
  8660. // clear temp file
  8661. sprintf(str,"rm -f %s",temp);
  8662. system(str);
  8663. for(int k=0; k < ChargeProfileCount; k++)
  8664. {
  8665. memset(str, 0, ARRAY_SIZE(str));
  8666. //clear file in C
  8667. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8668. system(str);
  8669. }
  8670. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8671. goto end;
  8672. }
  8673. else if(connectorIsNULL == TRUE)
  8674. {
  8675. for(int k=0; k < ChargeProfileCount; k++)
  8676. {
  8677. fptr1 = fopen(chargingProfiles[k], "r");
  8678. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8679. //Check Charging Profile Count
  8680. while(fscanf(fptr1, "%s", word) != EOF)
  8681. {
  8682. //DEBUG_INFO("word=%s\n",word);
  8683. if(strstr(word, "chargingProfileId")!= NULL)
  8684. {
  8685. //DEBUG_INFO("test chargingProfileId \n");
  8686. n_chargingProfile = n_chargingProfile + 1;
  8687. //DEBUG_INFO("chargingProfileId Found\n");
  8688. }
  8689. }
  8690. rewind(fptr1);
  8691. //search Charging Profile Element
  8692. //int i= 0;
  8693. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8694. {
  8695. json_object *tmpProfilee;
  8696. tmpProfilee = json_tokener_parse(sLineWord);
  8697. if(!is_error(tmpProfilee))
  8698. {
  8699. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8700. {
  8701. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8702. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8703. }
  8704. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8705. {
  8706. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8707. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8708. }
  8709. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8710. {
  8711. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8712. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8713. }
  8714. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8715. {
  8716. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8717. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8718. }
  8719. }
  8720. json_object_put(tmpProfilee);
  8721. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8722. {
  8723. //------- not write to fptr2-------//
  8724. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8725. //clearflag = TRUE;
  8726. }
  8727. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8728. {
  8729. //------- not write to fptr2-------//
  8730. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8731. }
  8732. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8733. {
  8734. //------- not write to fptr2-------//
  8735. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8736. }
  8737. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8738. {
  8739. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8740. }
  8741. else
  8742. {
  8743. fprintf(fptr2, sLineWord);//writing data into file
  8744. }
  8745. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8746. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8747. if(clearflag == TRUE)
  8748. {
  8749. fclose(fptr1);
  8750. fclose(fptr2);
  8751. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8752. system(str);
  8753. // clear temp file
  8754. sprintf(str,"rm -f %s",temp);
  8755. system(str);
  8756. }
  8757. else
  8758. {
  8759. fclose(fptr1);
  8760. fclose(fptr2);
  8761. memset(str, 0, ARRAY_SIZE(str));
  8762. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8763. system(str);
  8764. resultRename = rename(temp, chargingProfiles[k]);
  8765. if(resultRename == 0)
  8766. {
  8767. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8768. }
  8769. else
  8770. {
  8771. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8772. }
  8773. if(comfirmstr[0]== 0)
  8774. {
  8775. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8776. }
  8777. //Check chargingProfile is empty file
  8778. /*------ Read the file ----------------*/
  8779. fptr1=fopen(chargingProfiles[k],"r");
  8780. ch=fgetc(fptr1);
  8781. rewind(fptr1);
  8782. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8783. if(ch!=EOF)
  8784. {
  8785. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8786. {
  8787. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8788. if(sLineWord[0]=='\0')
  8789. {
  8790. isEmptyFile = TRUE;
  8791. break;
  8792. }
  8793. else
  8794. {
  8795. isEmptyFile = FALSE;
  8796. break;
  8797. }
  8798. }
  8799. }
  8800. else
  8801. isEmptyFile = TRUE;
  8802. fclose(fptr1);
  8803. if(isEmptyFile == TRUE)
  8804. {
  8805. memset(str, 0, ARRAY_SIZE(str));
  8806. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8807. system(str);
  8808. }
  8809. }
  8810. }// End of while(int k=0; k < ChargePointCount; k++)
  8811. }
  8812. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8813. {
  8814. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8815. for(int k=0; k < ChargeProfileCount; k++)
  8816. {
  8817. fptr1 = fopen(chargingProfiles[k], "r");
  8818. fptr2 = fopen(temp, "w+");
  8819. //Check Charging Profile Count
  8820. while(fscanf(fptr1, "%s", word) != EOF)
  8821. {
  8822. //DEBUG_INFO("word=%s\n",word);
  8823. if(strstr(word, "chargingProfileId")!= NULL)
  8824. {
  8825. n_chargingProfile = n_chargingProfile + 1;
  8826. }
  8827. }
  8828. rewind(fptr1);
  8829. //search Charging Profile Element
  8830. //int i= 0;
  8831. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8832. {
  8833. json_object *tmpProfilee;
  8834. tmpProfilee = json_tokener_parse(sLineWord);
  8835. if(!is_error(tmpProfilee))
  8836. {
  8837. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8838. {
  8839. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8840. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8841. }
  8842. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8843. {
  8844. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8845. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8846. }
  8847. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8848. {
  8849. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8850. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8851. }
  8852. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8853. {
  8854. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8855. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8856. }
  8857. }
  8858. json_object_put(tmpProfilee);
  8859. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8860. {
  8861. //------- not write to fptr2-------//
  8862. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8863. //clearflag = TRUE;
  8864. }
  8865. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8866. {
  8867. //------- not write to fptr2-------//
  8868. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8869. }
  8870. else if(stackLevelIsNULL == TRUE)
  8871. {
  8872. //Clear Whole File
  8873. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8874. clearflag = TRUE;
  8875. break;
  8876. }
  8877. else
  8878. {
  8879. fprintf(fptr2, sLineWord);//writing data into file
  8880. }
  8881. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8882. }
  8883. if(clearflag == TRUE)
  8884. {
  8885. fclose(fptr1);
  8886. fclose(fptr2);
  8887. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8888. system(str);
  8889. // clear temp file
  8890. sprintf(str,"rm -f %s",temp);
  8891. system(str);
  8892. }
  8893. else
  8894. {
  8895. fclose(fptr1);
  8896. fclose(fptr2);
  8897. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8898. system(str);
  8899. resultRename = rename(temp, chargingProfiles[k]);
  8900. if(resultRename == 0)
  8901. {
  8902. DEBUG_INFO("File ChargingProfile renamed successfully");
  8903. }
  8904. else
  8905. {
  8906. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8907. }
  8908. if(comfirmstr[0]== 0)
  8909. {
  8910. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8911. }
  8912. //Check chargingProfile is empty file
  8913. /*------ Read the file ----------------*/
  8914. fptr1=fopen(chargingProfiles[k],"r");
  8915. ch=fgetc(fptr1);
  8916. rewind(fptr1);
  8917. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8918. if(ch!=EOF)
  8919. {
  8920. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8921. {
  8922. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8923. if(sLineWord[0]=='\0')
  8924. {
  8925. isEmptyFile = TRUE;
  8926. break;
  8927. }
  8928. else
  8929. {
  8930. isEmptyFile = FALSE;
  8931. break;
  8932. }
  8933. }
  8934. }
  8935. else
  8936. isEmptyFile = TRUE;
  8937. fclose(fptr1);
  8938. if(isEmptyFile == TRUE)
  8939. {
  8940. memset(str, 0, ARRAY_SIZE(str));
  8941. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8942. system(str);
  8943. }
  8944. /*------- End of reading ---------------*/
  8945. }
  8946. } // while(int k=0; k < ChargeProfileCount; k++)
  8947. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8948. end:
  8949. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8950. {
  8951. if(connectorIdInt == 0)
  8952. {
  8953. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8954. {
  8955. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8956. }
  8957. }
  8958. else
  8959. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8960. }
  8961. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8962. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8963. return result;
  8964. }
  8965. void createFirmwareVersionByDataTransfer(void)
  8966. {
  8967. json_object *FirmwareDataTransfer = json_object_new_object();
  8968. // AC & DC model
  8969. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8970. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8971. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8972. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8973. // DC model
  8974. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8975. {
  8976. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8977. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8978. (gunType[3] != GUN_TYPE_UNKNOWN))
  8979. {
  8980. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8981. }
  8982. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8983. {
  8984. // DS DM DW
  8985. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8986. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8987. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8988. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8989. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8990. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8991. }
  8992. else
  8993. {
  8994. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8995. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8996. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8997. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8998. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8999. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9000. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9001. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9002. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9003. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9004. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9005. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9006. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9007. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9008. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9009. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9010. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9011. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9012. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9013. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9014. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9015. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9016. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9017. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9018. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9019. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9020. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9021. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9022. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9023. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9024. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9025. }
  9026. }
  9027. // 4G model
  9028. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9029. {
  9030. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9031. }
  9032. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9033. json_object_put(FirmwareDataTransfer);
  9034. }
  9035. int handleDataTransferRequest(char *uuid, char *payload)
  9036. {
  9037. mtrace();
  9038. json_object *response = json_object_new_object();
  9039. int result = FAIL;
  9040. char tempvendorId[255]={0};
  9041. char tempmessageId[50]={0};
  9042. char tempdata[512]={0};
  9043. char message[2048]={0};
  9044. DEBUG_INFO("handleDataTransferRequest...\n");
  9045. if((uuid != NULL) && (payload != NULL))
  9046. {
  9047. json_object *DataTransfer;
  9048. DataTransfer = json_tokener_parse(payload);
  9049. if(!is_error(DataTransfer))
  9050. {
  9051. // Required data
  9052. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9053. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9054. // Optional data
  9055. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9056. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9057. if(json_object_object_get(DataTransfer, "data") != NULL)
  9058. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9059. result = PASS;
  9060. }
  9061. json_object_put(DataTransfer);
  9062. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9063. {
  9064. // Send all moudle firmware version on EVSE
  9065. createFirmwareVersionByDataTransfer();
  9066. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9067. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9068. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9069. json_object_put(response);
  9070. }
  9071. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9072. {
  9073. system("/usr/bin/run_tmate_restart.sh &");
  9074. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9075. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9076. json_object_put(response);
  9077. }
  9078. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9079. {
  9080. json_object *data;
  9081. data = json_tokener_parse(tempdata);
  9082. if(!is_error(data))
  9083. {
  9084. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9085. {
  9086. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9087. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9088. if(json_object_object_get(data, "SOC") != NULL)
  9089. {
  9090. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9091. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9092. }
  9093. if(json_object_object_get(data, "Energy") != NULL)
  9094. {
  9095. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9096. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9097. }
  9098. if(json_object_object_get(data, "Duration") != NULL)
  9099. {
  9100. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9101. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9102. }
  9103. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9104. }
  9105. else
  9106. {
  9107. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9108. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9109. }
  9110. }
  9111. else
  9112. {
  9113. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9114. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9115. }
  9116. json_object_put(data);
  9117. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9118. json_object_put(response);
  9119. }
  9120. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9121. {
  9122. json_object *data;
  9123. data = json_tokener_parse(tempdata);
  9124. if(!is_error(data))
  9125. {
  9126. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9127. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9128. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9129. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9130. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9131. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9132. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9133. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9134. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9135. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9136. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9137. }
  9138. else
  9139. {
  9140. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9141. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9142. }
  9143. json_object_put(data);
  9144. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9145. json_object_put(response);
  9146. }
  9147. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9148. {
  9149. json_object *data;
  9150. data = json_tokener_parse(tempdata);
  9151. if(!is_error(data))
  9152. {
  9153. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9154. if(json_object_object_get(data, "idToken") != NULL)
  9155. {
  9156. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9157. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9158. }
  9159. if(json_object_object_get(data, "price") != NULL)
  9160. {
  9161. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9162. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9163. }
  9164. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9165. }
  9166. else
  9167. {
  9168. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9169. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9170. }
  9171. json_object_put(data);
  9172. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9173. json_object_put(response);
  9174. }
  9175. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9176. {
  9177. json_object *data;
  9178. data = json_tokener_parse(tempdata);
  9179. if(!is_error(data))
  9180. {
  9181. if(json_object_object_get(data, "txId") != NULL)
  9182. {
  9183. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9184. for(int idx = 0;idx<gunTotalNumber;idx++)
  9185. {
  9186. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9187. {
  9188. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9189. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9190. if(json_object_object_get(data, "description") != NULL)
  9191. {
  9192. // California pricing V1.0
  9193. DEBUG_INFO("California pricing V1.0\n");
  9194. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9195. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9196. }
  9197. else
  9198. {
  9199. // California pricing V1.1
  9200. DEBUG_INFO("California pricing V1.1\n");
  9201. if(json_object_object_get(data, "timestamp") != NULL)
  9202. {
  9203. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9204. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9205. }
  9206. if(json_object_object_get(data, "meterValue") != NULL)
  9207. {
  9208. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9209. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9210. }
  9211. if(json_object_object_get(data, "cost") != NULL)
  9212. {
  9213. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9214. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9215. }
  9216. if(json_object_object_get(data, "state") != NULL)
  9217. {
  9218. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9219. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9220. }
  9221. if(json_object_object_get(data, "chargingPrice") != NULL)
  9222. {
  9223. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9224. {
  9225. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9226. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9227. }
  9228. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9229. {
  9230. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9231. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9232. }
  9233. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9234. {
  9235. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9236. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9237. }
  9238. }
  9239. if(json_object_object_get(data, "idlePrice") != NULL)
  9240. {
  9241. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9242. {
  9243. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9244. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9245. }
  9246. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9247. {
  9248. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9249. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9250. }
  9251. }
  9252. if(json_object_object_get(data, "nextPeriod") != NULL)
  9253. {
  9254. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9255. {
  9256. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9257. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9258. }
  9259. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9260. {
  9261. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9262. {
  9263. 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")));
  9264. 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"));
  9265. }
  9266. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9267. {
  9268. 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")));
  9269. 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"));
  9270. }
  9271. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9272. {
  9273. 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")));
  9274. 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"));
  9275. }
  9276. }
  9277. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9278. {
  9279. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9280. {
  9281. 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")));
  9282. 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"));
  9283. }
  9284. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9285. {
  9286. 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")));
  9287. 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"));
  9288. }
  9289. }
  9290. }
  9291. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9292. {
  9293. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9294. {
  9295. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9296. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9297. }
  9298. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9299. {
  9300. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9301. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9302. }
  9303. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9304. {
  9305. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9306. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9307. }
  9308. }
  9309. }
  9310. }
  9311. }
  9312. }
  9313. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9314. }
  9315. else
  9316. {
  9317. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9318. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9319. }
  9320. json_object_put(data);
  9321. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9322. json_object_put(response);
  9323. }
  9324. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9325. {
  9326. json_object *data;
  9327. data = json_tokener_parse(tempdata);
  9328. if(!is_error(data))
  9329. {
  9330. if(json_object_object_get(data, "txId") != NULL)
  9331. {
  9332. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9333. for(int idx = 0;idx<gunTotalNumber;idx++)
  9334. {
  9335. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9336. {
  9337. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9338. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9339. if(json_object_object_get(data, "description") != NULL)
  9340. {
  9341. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9342. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9343. }
  9344. }
  9345. }
  9346. }
  9347. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9348. }
  9349. else
  9350. {
  9351. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9352. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9353. }
  9354. json_object_put(data);
  9355. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9356. json_object_put(response);
  9357. }
  9358. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9359. {
  9360. json_object *data;
  9361. data = json_tokener_parse(tempdata);
  9362. if(!is_error(data))
  9363. {
  9364. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9365. if(json_object_object_get(data, "Content_Type") != NULL)
  9366. {
  9367. 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))
  9368. {
  9369. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9370. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9371. {
  9372. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9373. }
  9374. }
  9375. else
  9376. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9377. }
  9378. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9379. }
  9380. else
  9381. {
  9382. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9383. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9384. }
  9385. json_object_put(data);
  9386. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9387. json_object_put(response);
  9388. }
  9389. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9390. {
  9391. json_object *data;
  9392. data = json_tokener_parse(tempdata);
  9393. if(!is_error(data))
  9394. {
  9395. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9396. if(json_object_object_get(data, "Page_Index") != NULL)
  9397. {
  9398. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9399. }
  9400. if(json_object_object_get(data, "Duration") != NULL)
  9401. {
  9402. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9403. }
  9404. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9405. }
  9406. else
  9407. {
  9408. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9409. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9410. }
  9411. json_object_put(data);
  9412. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9413. json_object_put(response);
  9414. }
  9415. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9416. {
  9417. json_object *data;
  9418. data = json_tokener_parse(tempdata);
  9419. if(!is_error(data))
  9420. {
  9421. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9422. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9423. {
  9424. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9425. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9426. else
  9427. {
  9428. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9429. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9430. }
  9431. }
  9432. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9433. {
  9434. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9435. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9436. else
  9437. {
  9438. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9439. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9440. }
  9441. }
  9442. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9443. {
  9444. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9445. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9446. else
  9447. {
  9448. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9449. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9450. }
  9451. }
  9452. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9453. {
  9454. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9455. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9456. else
  9457. {
  9458. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9459. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9460. }
  9461. }
  9462. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9463. {
  9464. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9465. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9466. else
  9467. {
  9468. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9469. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9470. }
  9471. }
  9472. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9473. {
  9474. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9475. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9476. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9477. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9478. else
  9479. {
  9480. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9481. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9482. }
  9483. }
  9484. if(json_object_object_get(data, "isAuthentication") != NULL)
  9485. {
  9486. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9487. {
  9488. case 0:
  9489. case 1:
  9490. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9491. break;
  9492. default:
  9493. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9494. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9495. break;
  9496. }
  9497. }
  9498. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9499. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9500. }
  9501. else
  9502. {
  9503. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9504. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9505. }
  9506. json_object_put(data);
  9507. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9508. json_object_put(response);
  9509. }
  9510. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9511. {
  9512. json_object *data;
  9513. data = json_tokener_parse(tempdata);
  9514. if(!is_error(data))
  9515. {
  9516. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9517. {
  9518. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9519. {
  9520. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9521. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9522. }
  9523. else
  9524. {
  9525. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9526. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9527. }
  9528. }
  9529. else
  9530. {
  9531. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9532. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9533. }
  9534. }
  9535. else
  9536. {
  9537. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9538. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9539. }
  9540. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9541. json_object_put(response);
  9542. }
  9543. else if(strstr(tempmessageId, "refund_status") != NULL)
  9544. {
  9545. json_object *data;
  9546. data = json_tokener_parse(tempdata);
  9547. if(!is_error(data))
  9548. {
  9549. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9550. if(json_object_object_get(data, "status") != NULL)
  9551. {
  9552. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9553. if(strcmp(json_object_get_string(json_object_object_get(data, "status")), "T") || strcmp(json_object_get_string(json_object_object_get(data, "status")), "F"))
  9554. {
  9555. sprintf((char*)ShmYesCustomData->RefundStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9556. }
  9557. else
  9558. {
  9559. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9560. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9561. }
  9562. }
  9563. else
  9564. {
  9565. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9566. json_object_object_add(response, "data", json_object_new_string("status data can not get."));
  9567. }
  9568. if(json_object_object_get(data, "chargeDate") != NULL)
  9569. {
  9570. sprintf((char *)ShmYesCustomData->RefundStatus.chargeDate, "%s", json_object_get_string(json_object_object_get(data,"chargeDate")));
  9571. }
  9572. else
  9573. {
  9574. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9575. json_object_object_add(response, "data", json_object_new_string("chargeDate data can not get."));
  9576. }
  9577. if(json_object_object_get(data, "holdAmt") != NULL)
  9578. {
  9579. if(json_object_get_int(json_object_object_get(data, "holdAmt")) >= 0)
  9580. ShmYesCustomData->RefundStatus.holdAmt = json_object_get_int(json_object_object_get(data, "holdAmt"));
  9581. else
  9582. {
  9583. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9584. json_object_object_add(response, "data", json_object_new_string("holdAmt data is invalid."));
  9585. }
  9586. }
  9587. else
  9588. {
  9589. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9590. json_object_object_add(response, "data", json_object_new_string("holdAmt data can not get."));
  9591. }
  9592. if(json_object_object_get(data, "chargeAmt") != NULL)
  9593. {
  9594. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9595. ShmYesCustomData->RefundStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9596. else
  9597. {
  9598. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9599. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9600. }
  9601. }
  9602. else
  9603. {
  9604. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9605. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9606. }
  9607. if(json_object_object_get(data, "refundAmt") != NULL)
  9608. {
  9609. if(json_object_get_int(json_object_object_get(data, "refundAmt")) >= 0)
  9610. ShmYesCustomData->RefundStatus.refundAmt = json_object_get_int(json_object_object_get(data, "refundAmt"));
  9611. else
  9612. {
  9613. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9614. json_object_object_add(response, "data", json_object_new_string("refundAmt data is invalid."));
  9615. }
  9616. }
  9617. else
  9618. {
  9619. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9620. json_object_object_add(response, "data", json_object_new_string("refundAmt data can not get."));
  9621. }
  9622. if(json_object_object_get(data, "page") != NULL)
  9623. {
  9624. if(json_object_get_int(json_object_object_get(data, "page")) >= 0 && json_object_get_int(json_object_object_get(data, "page")) <= 3)
  9625. ShmYesCustomData->RefundStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9626. else
  9627. {
  9628. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9629. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9630. }
  9631. }
  9632. else
  9633. {
  9634. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9635. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9636. }
  9637. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9638. {
  9639. ShmYesCustomData->RefundStatusReq = 1;
  9640. DEBUG_INFO("<<< RefundStatus:{status:%s, chargeDate:%s, holdAmt:%d, chargeAmt:%d, refundAmt:%d, page:%d}\n",
  9641. ShmYesCustomData->RefundStatus.status,
  9642. ShmYesCustomData->RefundStatus.chargeDate,
  9643. ShmYesCustomData->RefundStatus.holdAmt,
  9644. ShmYesCustomData->RefundStatus.chargeAmt,
  9645. ShmYesCustomData->RefundStatus.refundAmt,
  9646. ShmYesCustomData->RefundStatus.page);
  9647. }
  9648. }
  9649. else
  9650. {
  9651. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9652. json_object_object_add(response, "data", json_object_new_string("refund_status content got something wrong."));
  9653. }
  9654. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9655. json_object_put(response);
  9656. }
  9657. else if(strstr(tempmessageId, "deduct_status") != NULL)
  9658. {
  9659. json_object *data;
  9660. data = json_tokener_parse(tempdata);
  9661. if(!is_error(data))
  9662. {
  9663. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9664. if(json_object_object_get(data, "status") != NULL)
  9665. {
  9666. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9667. if((strcmp(json_object_get_string(json_object_object_get(data, "status")), "T")==0) || (strcmp(json_object_get_string(json_object_object_get(data, "status")), "F")==0))
  9668. {
  9669. sprintf((char*)ShmYesCustomData->DeductStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9670. }
  9671. else
  9672. {
  9673. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9674. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9675. }
  9676. }
  9677. else
  9678. {
  9679. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9680. json_object_object_add(response, "data", json_object_new_string("status data can not get."));
  9681. }
  9682. if(json_object_object_get(data, "autoLoadAmt") != NULL)
  9683. {
  9684. if(json_object_get_int(json_object_object_get(data, "autoLoadAmt")) >= 0)
  9685. ShmYesCustomData->DeductStatus.autoLoadAmt = json_object_get_int(json_object_object_get(data, "autoLoadAmt"));
  9686. else
  9687. {
  9688. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9689. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt is invalid."));
  9690. }
  9691. }
  9692. else
  9693. {
  9694. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9695. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt data can not get."));
  9696. }
  9697. if(json_object_object_get(data, "beforeAmt") != NULL)
  9698. {
  9699. if(json_object_get_int(json_object_object_get(data, "beforeAmt")) >= 0)
  9700. ShmYesCustomData->DeductStatus.beforeAmt = json_object_get_int(json_object_object_get(data, "beforeAmt"));
  9701. else
  9702. {
  9703. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9704. json_object_object_add(response, "data", json_object_new_string("beforeAmt data is invalid."));
  9705. }
  9706. }
  9707. else
  9708. {
  9709. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9710. json_object_object_add(response, "data", json_object_new_string("beforeAmt data can not get."));
  9711. }
  9712. if(json_object_object_get(data, "chargeAmt") != NULL)
  9713. {
  9714. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9715. ShmYesCustomData->DeductStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9716. else
  9717. {
  9718. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9719. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9720. }
  9721. }
  9722. else
  9723. {
  9724. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9725. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9726. }
  9727. if(json_object_object_get(data, "afterAmt") != NULL)
  9728. {
  9729. if(json_object_get_int(json_object_object_get(data, "afterAmt")) >= 0)
  9730. ShmYesCustomData->DeductStatus.afterAmt = json_object_get_int(json_object_object_get(data, "afterAmt"));
  9731. else
  9732. {
  9733. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9734. json_object_object_add(response, "data", json_object_new_string("afterAmt data is invalid."));
  9735. }
  9736. }
  9737. else
  9738. {
  9739. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9740. json_object_object_add(response, "data", json_object_new_string("afterAmt data can not get."));
  9741. }
  9742. if(json_object_object_get(data, "page") != NULL)
  9743. {
  9744. if(json_object_get_int(json_object_object_get(data, "page")) >= 0)
  9745. ShmYesCustomData->DeductStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9746. else
  9747. {
  9748. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9749. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9750. }
  9751. }
  9752. else
  9753. {
  9754. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9755. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9756. }
  9757. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9758. {
  9759. ShmYesCustomData->DeductStatusReq = 1;
  9760. DEBUG_INFO("<<< deduct_status:{status:%s, autoLoadAmt:%d, beforeAmt:%d, chargeAmt:%d, afterAmt:%d, page:%d}\n",
  9761. ShmYesCustomData->DeductStatus.status,
  9762. ShmYesCustomData->DeductStatus.autoLoadAmt,
  9763. ShmYesCustomData->DeductStatus.beforeAmt,
  9764. ShmYesCustomData->DeductStatus.chargeAmt,
  9765. ShmYesCustomData->DeductStatus.afterAmt,
  9766. ShmYesCustomData->DeductStatus.page);
  9767. }
  9768. }
  9769. else
  9770. {
  9771. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9772. json_object_object_add(response, "data", json_object_new_string("deduct_status content got something wrong."));
  9773. }
  9774. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9775. json_object_put(response);
  9776. }
  9777. else if(strstr(tempmessageId, "charge_info") != NULL)
  9778. {
  9779. json_object *data;
  9780. data = json_tokener_parse(tempdata);
  9781. if(!is_error(data))
  9782. {
  9783. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9784. if(json_object_object_get(data, "station_name") != NULL)
  9785. {
  9786. sprintf((char *)ShmYesCustomData->ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"station_name")));
  9787. }
  9788. else
  9789. {
  9790. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9791. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9792. }
  9793. if(json_object_object_get(data, "station_id") != NULL)
  9794. {
  9795. sprintf((char *)ShmYesCustomData->ChargerInfo.station_id, "%s", json_object_get_string(json_object_object_get(data,"station_id")));
  9796. }
  9797. else
  9798. {
  9799. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9800. json_object_object_add(response, "data", json_object_new_string("station_id data can not get."));
  9801. }
  9802. if(json_object_object_get(data, "charge_id") != NULL)
  9803. {
  9804. for(int idx=0;idx<json_object_array_length(json_object_object_get(data, "charge_id"));idx++)
  9805. {
  9806. sprintf((char*)ShmYesCustomData->ChargerInfo.charge_id[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(data, "charge_id"), idx)));
  9807. }
  9808. }
  9809. else
  9810. {
  9811. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9812. json_object_object_add(response, "data", json_object_new_string("charge_id data can not get."));
  9813. }
  9814. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9815. {
  9816. ShmYesCustomData->ChargerInfoReq = 1;
  9817. DEBUG_INFO("<<< charge_info:{station_name:%s, station_id:%s, charge_id[0]:%s, charge_id[1]:%s}\n",
  9818. ShmYesCustomData->ChargerInfo.station_name,
  9819. ShmYesCustomData->ChargerInfo.station_id,
  9820. ShmYesCustomData->ChargerInfo.charge_id[0],
  9821. ShmYesCustomData->ChargerInfo.charge_id[1]);
  9822. }
  9823. }
  9824. else
  9825. {
  9826. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9827. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9828. }
  9829. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9830. json_object_put(response);
  9831. }
  9832. else if(strstr(tempmessageId, "weather_info") != NULL)
  9833. {
  9834. json_object *data;
  9835. data = json_tokener_parse(tempdata);
  9836. if(!is_error(data))
  9837. {
  9838. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9839. if(json_object_object_get(data, "weather") != NULL)
  9840. {
  9841. ShmYesCustomData->WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weather"));
  9842. }
  9843. else
  9844. {
  9845. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9846. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9847. }
  9848. if(json_object_object_get(data, "temperature") != NULL)
  9849. {
  9850. sprintf((char *)ShmYesCustomData->WeatherInfo.temperature, "%s", json_object_get_string(json_object_object_get(data,"temperature")));
  9851. }
  9852. else
  9853. {
  9854. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9855. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9856. }
  9857. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9858. {
  9859. ShmYesCustomData->WeatherInfoReq = 1;
  9860. DEBUG_INFO("<<< weather_info:{weather:%d, temperature:%s}\n",
  9861. ShmYesCustomData->WeatherInfo.weatherId,
  9862. ShmYesCustomData->WeatherInfo.temperature
  9863. );
  9864. }
  9865. }
  9866. else
  9867. {
  9868. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9869. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9870. }
  9871. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9872. json_object_put(response);
  9873. }
  9874. else if(strstr(tempmessageId, "set_qrcode") != NULL)
  9875. {
  9876. json_object *data;
  9877. data = json_tokener_parse(tempdata);
  9878. if(!is_error(data))
  9879. {
  9880. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9881. if(json_object_object_get(data, "connectorId") != NULL)
  9882. {
  9883. if((json_object_get_int(json_object_object_get(data, "connectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "connectorId")) <= gunTotalNumber))
  9884. {
  9885. int idx = json_object_get_int(json_object_object_get(data, "connectorId"))-1;
  9886. if(json_object_object_get(data, "qrcode") != NULL)
  9887. {
  9888. sprintf((char *)ShmYesCustomData->QrCode[idx], "%s", json_object_get_string(json_object_object_get(data,"qrcode")));
  9889. ShmYesCustomData->SetQrCodeReq = 1;
  9890. DEBUG_INFO("<<< set_qrcode:{connectorId:%d, qrcode:%s}\n",
  9891. idx,
  9892. ShmYesCustomData->QrCode[idx]
  9893. );
  9894. }
  9895. else
  9896. {
  9897. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9898. json_object_object_add(response, "data", json_object_new_string("qrcode data can not get."));
  9899. }
  9900. }
  9901. else
  9902. {
  9903. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9904. json_object_object_add(response, "data", json_object_new_string("connectorId data is invalid."));
  9905. }
  9906. }
  9907. else
  9908. {
  9909. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9910. json_object_object_add(response, "data", json_object_new_string("connectorId data can not get."));
  9911. }
  9912. }
  9913. else
  9914. {
  9915. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9916. json_object_object_add(response, "data", json_object_new_string("set_qrcode content got something wrong."));
  9917. }
  9918. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9919. json_object_put(response);
  9920. }
  9921. else
  9922. {
  9923. // Can not find valid message id
  9924. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9925. }
  9926. }
  9927. else
  9928. {
  9929. // Payload is null
  9930. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9931. }
  9932. LWS_Send(message);
  9933. return result;
  9934. }
  9935. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9936. {
  9937. mtrace();
  9938. int result = FAIL;
  9939. int connectorIdInt, durationInt;
  9940. char chargingRateUnitStr[4]={0};
  9941. char comfirmstr[20];
  9942. int confirmPeriods = 0;
  9943. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9944. json_object *GetCompositeSchedule;
  9945. GetCompositeSchedule = json_tokener_parse(payload);
  9946. if(!is_error(GetCompositeSchedule))
  9947. {
  9948. // Required data
  9949. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9950. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9951. else
  9952. connectorIdInt = -1;
  9953. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9954. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9955. else
  9956. durationInt = 86400;
  9957. // Optional data
  9958. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9959. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9960. }
  9961. json_object_put(GetCompositeSchedule);
  9962. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9963. if((connectorIdInt == 0) ||
  9964. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9965. {
  9966. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9967. struct StructChargingProfile tmpProfile[1];
  9968. if(strstr(chargingRateUnitStr, "W") != NULL)
  9969. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9970. else
  9971. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9972. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9973. {
  9974. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9975. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9976. }
  9977. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9978. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9979. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9980. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9981. {
  9982. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9983. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9984. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9985. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9986. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9987. {
  9988. confirmPeriods = idx;
  9989. break;
  9990. }
  9991. }
  9992. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9993. {
  9994. confirmPeriods += 1;
  9995. }
  9996. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9997. }
  9998. else
  9999. {
  10000. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10001. }
  10002. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10003. return result;
  10004. }
  10005. int handleGetConfigurationRequest(char *uuid, char *payload)
  10006. {
  10007. mtrace();
  10008. int result = FAIL;
  10009. int MaxKeySupported = 0;
  10010. int n_keys = 0;
  10011. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10012. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10013. json_object *GetConfiguration;
  10014. GetConfiguration = json_tokener_parse(payload);
  10015. if(!is_error(GetConfiguration))
  10016. {
  10017. // Optional data
  10018. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10019. {
  10020. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10021. {
  10022. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10023. n_keys = idx + 1;
  10024. }
  10025. }
  10026. }
  10027. json_object_put(GetConfiguration);
  10028. UnknownKeynum = 0;
  10029. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10030. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10031. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10032. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10033. if(n_keys != 0)
  10034. {
  10035. for(int i=0;i<n_keys;i++)
  10036. {
  10037. getKeyValue(requestKey[i]);
  10038. }
  10039. }
  10040. else
  10041. {
  10042. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10043. getKeyValue("");
  10044. }
  10045. processUnkownKey();
  10046. sendGetConfigurationConfirmation(uuid);
  10047. return result;
  10048. }
  10049. static char fnamePlusPath[100]={0};
  10050. static char fnamePWithNoPath[60]={0};
  10051. void checkUploadLog(void)
  10052. {
  10053. FILE *fp;
  10054. /* Open the command for reading. */
  10055. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10056. if (fp == NULL) {
  10057. DEBUG_WARN("Failed to run command\n" );
  10058. exit(1);
  10059. }
  10060. int ftppathlen = 0;
  10061. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10062. int i = 0;
  10063. /* Read the output a line at a time - output it. */
  10064. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10065. if(i==0)
  10066. {
  10067. ftppathlen = strlen(fnamePlusPath);
  10068. DEBUG_INFO("%s\n", fnamePlusPath);
  10069. fnamePlusPath[ftppathlen]='\0';
  10070. break;
  10071. }
  10072. i= i+1;
  10073. }
  10074. /* close */
  10075. pclose(fp);
  10076. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10077. {
  10078. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10079. {
  10080. fnamePlusPath[k]='\0';
  10081. }
  10082. }
  10083. i=1;
  10084. //char fname[60]={0};
  10085. while(i < ftppathlen)
  10086. {
  10087. int len=ftppathlen-i;
  10088. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10089. {
  10090. DEBUG_INFO("compare '/' all right\n");
  10091. break;
  10092. }
  10093. i=i+1;
  10094. }
  10095. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10096. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10097. fnamePWithNoPath[i+1] = '\0';
  10098. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10099. {
  10100. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10101. {
  10102. fnamePWithNoPath[j]='\0';
  10103. }
  10104. }
  10105. FILE* fp1 = fopen(fnamePlusPath, "r");
  10106. if (fp1)
  10107. {
  10108. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10109. // file exists
  10110. fclose(fp1);
  10111. }
  10112. else
  10113. {
  10114. // file doesn't exist
  10115. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10116. }
  10117. }
  10118. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10119. {
  10120. mtrace();
  10121. int result = FAIL;
  10122. time_t CurrentTime;
  10123. struct tm *tm;
  10124. pthread_t th_Status;
  10125. CurrentTime = time(NULL);
  10126. tm = localtime(&CurrentTime);
  10127. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10128. 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);
  10129. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10130. if(!interLock.isGetDiagnosticGoing)
  10131. {
  10132. interLock.isGetDiagnosticGoing = 1;
  10133. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10134. sleep(1);
  10135. }
  10136. else
  10137. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10138. return result;
  10139. }
  10140. void* GetDiagnosticsProcess(void* data)
  10141. {
  10142. pthread_detach(pthread_self());
  10143. mtrace();
  10144. int retriesInt=0, retryIntervalInt=0;
  10145. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10146. 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};
  10147. int port=0;
  10148. int isSuccess = FALSE;
  10149. char cmdBuf[2048];
  10150. struct tm *tmNow;
  10151. time_t CurrentTime;
  10152. struct tm tmStart;
  10153. struct tm tmStop;
  10154. CurrentTime = time(NULL);
  10155. tmNow=localtime(&CurrentTime);
  10156. uint16_t targetYear, targetMonth;
  10157. json_object *GetDiagnostics;
  10158. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10159. GetDiagnostics = json_tokener_parse(data);
  10160. if(!is_error(GetDiagnostics))
  10161. {
  10162. // Required data
  10163. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10164. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10165. // Optional data
  10166. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10167. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10168. else
  10169. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10170. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10171. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10172. else
  10173. retryIntervalInt = 30;
  10174. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10175. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10176. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10177. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10178. }
  10179. json_object_put(GetDiagnostics);
  10180. // Pack log to compress file
  10181. 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) &&
  10182. (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))
  10183. {
  10184. // Pack system log
  10185. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10186. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10187. targetYear = tmStart.tm_year;
  10188. targetMonth = tmStart.tm_mon;
  10189. do
  10190. {
  10191. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10192. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10193. if(targetMonth+1>=13)
  10194. {
  10195. targetYear += 1;
  10196. targetMonth = 1;
  10197. }
  10198. else
  10199. {
  10200. targetMonth += 1;
  10201. }
  10202. }while((targetYear < (tmNow->tm_year+1900)) ||
  10203. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10204. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10205. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10206. system(cmdBuf);
  10207. // Pack charging & event log
  10208. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10209. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10210. targetYear = tmStart.tm_year;
  10211. targetMonth = tmStart.tm_mon;
  10212. do
  10213. {
  10214. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10215. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10216. if(targetMonth+1>=13)
  10217. {
  10218. targetYear += 1;
  10219. targetMonth = 1;
  10220. }
  10221. else
  10222. {
  10223. targetMonth += 1;
  10224. }
  10225. }while((targetYear < (tmNow->tm_year+1900)) ||
  10226. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10227. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10228. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10229. system(cmdBuf);
  10230. // Combine log file
  10231. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10232. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10233. }
  10234. else
  10235. {
  10236. system("exec /root/logPackTools 'log' 6");
  10237. }
  10238. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10239. system(cmdBuf);
  10240. checkUploadLog();
  10241. //****************location*******************/
  10242. if(strcmp(locationstr,"")==0)
  10243. {
  10244. DEBUG_INFO("location is <Empty>!\n");
  10245. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10246. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10247. goto end;
  10248. }
  10249. memset(protocol, 0, ARRAY_SIZE(protocol));
  10250. memset(user, 0, ARRAY_SIZE(user) );
  10251. memset(password, 0, ARRAY_SIZE(password));
  10252. memset(host, 0, ARRAY_SIZE(host));
  10253. memset(path, 0, ARRAY_SIZE(path));
  10254. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10255. memset(host1, 0, ARRAY_SIZE(host1));
  10256. memset(path1, 0, ARRAY_SIZE(path1));
  10257. /*location: ftp://user:password@host:port/path*/
  10258. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10259. if((access(fnamePlusPath,F_OK))!=-1)
  10260. {
  10261. DEBUG_INFO("fnamePlusPath exist.\n");
  10262. }
  10263. else
  10264. {
  10265. DEBUG_INFO("fnamePlusPath not exist!\n");
  10266. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10267. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10268. goto end;
  10269. }
  10270. if(strchr(locationstr,'@')==NULL)
  10271. {
  10272. sscanf(locationstr,
  10273. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10274. protocol, host, &port, path);
  10275. strcpy(user,"anonymous");
  10276. strcpy(password,"");
  10277. }
  10278. else
  10279. {
  10280. //DEBUG_INFO("pch=%s\n", pch);
  10281. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10282. protocol, user, password, host, &port, path);
  10283. }
  10284. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10285. {
  10286. DEBUG_INFO("protocol is not ftp/http ! \n");
  10287. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10288. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10289. goto end;
  10290. }
  10291. if(strncmp(locationstr,"http", 4) == 0)
  10292. {
  10293. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10294. sprintf(ftppath,"/%s", path);
  10295. do
  10296. {
  10297. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10298. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10299. sleep(3);
  10300. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10301. if(!isSuccess)
  10302. {
  10303. DEBUG_INFO("Diagnostics fail.\n");
  10304. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10305. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10306. sleep(retryIntervalInt);
  10307. }
  10308. else
  10309. {
  10310. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10311. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10312. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10313. }
  10314. retriesInt--;
  10315. }while((isSuccess == 0)&&(retriesInt >= 0));
  10316. }
  10317. else
  10318. {
  10319. sscanf(host,"%[^/]%s",host1, path1);
  10320. if(strlen(path) > 0)
  10321. sprintf(ftppath,"/%s", path);
  10322. else
  10323. sprintf(ftppath,"/%s", path1);
  10324. int ftppathlen=strlen(ftppath);
  10325. int i=1;
  10326. char filenametemp[50];
  10327. while(i < ftppathlen)
  10328. {
  10329. int len=ftppathlen-i;
  10330. if(ftppath[len]== 47) // '/' ascll code: 47
  10331. {
  10332. DEBUG_INFO("find '/' all right\n");
  10333. break;
  10334. }
  10335. i=i+1;
  10336. }
  10337. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10338. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10339. filenametemp[i+1] = 0;
  10340. if(port == 0)
  10341. port = 21;
  10342. do
  10343. {
  10344. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10345. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10346. sleep(3);
  10347. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10348. if(!isSuccess)
  10349. {
  10350. DEBUG_INFO("Diagnostics fail.\n");
  10351. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10352. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10353. sleep(retryIntervalInt);
  10354. }
  10355. else
  10356. {
  10357. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10358. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10359. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10360. }
  10361. retriesInt--;
  10362. }while((!isSuccess)&&(retriesInt >= 0));
  10363. }
  10364. end:
  10365. system("rm -f /mnt/*");
  10366. sleep(5);
  10367. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10368. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10369. interLock.isGetDiagnosticGoing = 0;
  10370. pthread_exit(NULL);
  10371. }
  10372. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10373. {
  10374. mtrace();
  10375. int result = FAIL;
  10376. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10377. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10378. {
  10379. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10380. locallistVersion = -1;
  10381. }
  10382. else
  10383. {
  10384. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10385. OCPP_getListVerion();
  10386. }
  10387. //from db.OCPP_getListVerion
  10388. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10389. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10390. sendGetLocalListVersionConfirmation(uuid,"");
  10391. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10392. return result;
  10393. }
  10394. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10395. {
  10396. mtrace();
  10397. int result = FAIL;
  10398. int connectorIdInt=-1;
  10399. int tempIndex = 0;
  10400. int connectorIdIsNULL, chargingProfileIsNULL;
  10401. char comfirmstr[20]={0};
  10402. char cmdBuf[512];
  10403. json_object *RemoteStartTransaction;
  10404. FILE *fp;
  10405. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10406. if(server_pending == TRUE)
  10407. {
  10408. return 0;
  10409. }
  10410. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10411. RemoteStartTransaction = json_tokener_parse(payload);
  10412. if(!is_error(RemoteStartTransaction))
  10413. {
  10414. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10415. {
  10416. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10417. }
  10418. else
  10419. {
  10420. connectorIdIsNULL = TRUE;
  10421. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10422. {
  10423. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10424. {
  10425. connectorIdIsNULL = FALSE;
  10426. connectorIdInt = (gun_index+1);
  10427. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10428. break;
  10429. }
  10430. }
  10431. }
  10432. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10433. {
  10434. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10435. // Required data
  10436. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10437. // Optional data
  10438. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10439. {
  10440. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10441. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10442. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10443. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10444. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10445. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10446. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10447. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10448. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10449. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10450. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10451. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10452. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10453. {
  10454. 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")));
  10455. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10456. 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"));
  10457. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10458. 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"));
  10459. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10460. 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")));
  10461. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10462. {
  10463. 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++)
  10464. {
  10465. 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"));
  10466. 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"));
  10467. 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)
  10468. 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"));
  10469. }
  10470. }
  10471. }
  10472. }
  10473. else
  10474. {
  10475. chargingProfileIsNULL = TRUE;
  10476. }
  10477. }
  10478. }
  10479. else
  10480. {
  10481. connectorIdIsNULL = TRUE;
  10482. }
  10483. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10484. {
  10485. DEBUG_WARN("Connector id is NULL\n.");
  10486. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10487. goto end;
  10488. }
  10489. /*
  10490. enum _SYSTEM_STATUS
  10491. {
  10492. S_BOOTING = 0,
  10493. S_IDLE, = 1
  10494. S_AUTHORIZING, = 2
  10495. S_REASSIGN_CHECK, = 3
  10496. S_REASSIGN, = 4
  10497. S_PRECHARGE, = 5
  10498. S_PREPARING_FOR_EV, = 6
  10499. S_PREPARING_FOR_EVSE, = 7
  10500. S_CHARGING, = 8
  10501. S_TERMINATING, = 9
  10502. S_COMPLETE, = 10
  10503. S_ALARM, = 11
  10504. S_FAULT = 12
  10505. }
  10506. */
  10507. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10508. {
  10509. //check Transaction active
  10510. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10511. {
  10512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10513. {
  10514. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10515. }
  10516. else
  10517. {
  10518. tempIndex = connectorIdInt -1;
  10519. }
  10520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10521. {
  10522. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10523. {
  10524. 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))
  10525. {
  10526. //Reserved
  10527. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10528. }
  10529. 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))
  10530. {
  10531. //Reserved
  10532. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10533. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10534. goto end;
  10535. }
  10536. else
  10537. {
  10538. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10539. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10540. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10541. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10542. {
  10543. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10544. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10545. goto end;
  10546. }
  10547. }//END FOR ELSE
  10548. }
  10549. }// END FOR CHAdeMO_QUANTITY
  10550. }
  10551. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10552. {
  10553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10554. {
  10555. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10556. }
  10557. else
  10558. {
  10559. tempIndex = connectorIdInt -1;
  10560. }
  10561. for (int index = 0; index < CCS_QUANTITY; index++)
  10562. {
  10563. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10564. {
  10565. 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))
  10566. {
  10567. //Reserved
  10568. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10569. }
  10570. 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))
  10571. {
  10572. //Reserved
  10573. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10574. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10575. goto end;
  10576. }
  10577. else
  10578. {
  10579. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10580. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10581. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10582. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10583. {
  10584. DEBUG_WARN("CCS connector not allow start\n.");
  10585. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10586. goto end;
  10587. }
  10588. }// END FOR ELSE
  10589. }
  10590. }// END FOR CCS_QUANTITY
  10591. }
  10592. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10593. {
  10594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10595. {
  10596. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10597. }
  10598. else
  10599. {
  10600. tempIndex = connectorIdInt -1;
  10601. }
  10602. for (int index = 0; index < GB_QUANTITY; index++)
  10603. {
  10604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10605. {
  10606. 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))
  10607. {
  10608. //Reserved
  10609. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10610. }
  10611. 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))
  10612. {
  10613. //Reserved
  10614. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10615. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10616. goto end;
  10617. }
  10618. else
  10619. {
  10620. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10621. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10622. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10623. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10624. {
  10625. DEBUG_WARN("GB connector not allow start\n.");
  10626. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10627. goto end;
  10628. }
  10629. }// END FOR ELSE
  10630. }
  10631. } // END FOR GB_QUANTITY
  10632. }
  10633. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10634. {
  10635. tempIndex = connectorIdInt -1;
  10636. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10637. {
  10638. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10639. {
  10640. 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))
  10641. {
  10642. //Reserved
  10643. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10644. }
  10645. 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))
  10646. {
  10647. //Reserved
  10648. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10649. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10650. goto end;
  10651. }
  10652. else
  10653. {
  10654. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10655. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10656. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10657. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10658. {
  10659. DEBUG_WARN("GB connector not allow start\n.");
  10660. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10661. goto end;
  10662. }
  10663. }// END FOR ELSE
  10664. }
  10665. } // END FOR GB_QUANTITY
  10666. }
  10667. else
  10668. {
  10669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10670. {
  10671. tempIndex = 2;
  10672. }
  10673. else
  10674. {
  10675. tempIndex = connectorIdInt -1;
  10676. }
  10677. for (int index = 0; index < AC_QUANTITY; index++)
  10678. {
  10679. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10680. {
  10681. 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))
  10682. {
  10683. //Reserved
  10684. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10685. }
  10686. 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))
  10687. {
  10688. //Reserved
  10689. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10691. goto end;
  10692. }
  10693. else
  10694. {
  10695. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10696. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10697. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10698. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10699. {
  10700. DEBUG_WARN("AC connector not allow start\n.");
  10701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10702. goto end;
  10703. }
  10704. }//END FOR ELSE
  10705. }
  10706. }// END FOR AC_QUANTITY
  10707. }
  10708. if(chargingProfileIsNULL == FALSE)
  10709. {
  10710. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10711. {
  10712. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10713. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10714. //memset idTag
  10715. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10716. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10717. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10718. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10719. // Save profile to file
  10720. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10721. system(cmdBuf);
  10722. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10723. fp = fopen(cmdBuf, "w");
  10724. 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));
  10725. fclose(fp);
  10726. }
  10727. else
  10728. {
  10729. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10730. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10731. }
  10732. }
  10733. else
  10734. {
  10735. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10736. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10737. //memset idTag
  10738. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10739. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10740. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10741. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10742. }
  10743. }
  10744. else
  10745. {
  10746. DEBUG_WARN("Connector id over\n.");
  10747. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10748. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10749. }
  10750. end:
  10751. json_object_put(RemoteStartTransaction);
  10752. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10753. {
  10754. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10755. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10756. }
  10757. //OCPP send RemoteStartConfirmation by first.
  10758. sendRemoteStartConfirmation(uuid, comfirmstr);
  10759. return result;
  10760. }
  10761. int handleRemoteStartRequest(char *uuid, char *payload)
  10762. {
  10763. mtrace();
  10764. int result = PASS;
  10765. int connectorIdInt=-1;
  10766. int tempIndex = 0;
  10767. char comfirmstr[20]={0};
  10768. char cmdBuf[512];
  10769. json_object *RemoteStartTransaction;
  10770. FILE *fp;
  10771. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10772. if(server_pending == TRUE)
  10773. {
  10774. result = FAIL;
  10775. }
  10776. RemoteStartTransaction = json_tokener_parse(payload);
  10777. if(!is_error(RemoteStartTransaction))
  10778. {
  10779. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10780. {
  10781. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10782. }
  10783. else
  10784. {
  10785. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10786. {
  10787. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10788. {
  10789. connectorIdInt = (gun_index+1);
  10790. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10791. break;
  10792. }
  10793. }
  10794. }
  10795. if(connectorIdInt == 0)
  10796. {
  10797. DEBUG_WARN("Connector id shall not equal 0.\n");
  10798. result = FAIL;
  10799. }
  10800. else if(connectorIdInt == -1)
  10801. {
  10802. DEBUG_INFO("Connector id does not specific.\n");
  10803. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10804. {
  10805. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10806. // Required data
  10807. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10808. // Optional data
  10809. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10810. {
  10811. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10812. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10813. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10814. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10815. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10816. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10817. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10818. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10819. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10820. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10821. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10822. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10823. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10824. {
  10825. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10826. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10827. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10828. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10829. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10830. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10831. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10832. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10833. {
  10834. 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++)
  10835. {
  10836. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  10837. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  10838. 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)
  10839. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  10840. }
  10841. }
  10842. }
  10843. }
  10844. else
  10845. {
  10846. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10847. }
  10848. }
  10849. }
  10850. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10851. {
  10852. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10853. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10854. // Required data
  10855. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10856. // Optional data
  10857. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10858. {
  10859. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10860. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10861. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10862. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10863. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10864. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10865. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10866. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10867. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10868. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10869. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10870. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10871. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10872. {
  10873. 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")));
  10874. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10875. 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"));
  10876. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10877. 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"));
  10878. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10879. 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")));
  10880. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10881. {
  10882. 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++)
  10883. {
  10884. 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"));
  10885. 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"));
  10886. 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)
  10887. 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"));
  10888. }
  10889. }
  10890. }
  10891. }
  10892. else
  10893. {
  10894. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10895. }
  10896. }
  10897. else
  10898. {
  10899. DEBUG_WARN("Connector id is over maximun value.\n");
  10900. result = FAIL;
  10901. }
  10902. }
  10903. if(result == PASS)
  10904. {
  10905. if(connectorIdInt > 0)
  10906. {
  10907. //check Transaction active
  10908. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10909. {
  10910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10911. {
  10912. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10913. }
  10914. else
  10915. {
  10916. tempIndex = connectorIdInt -1;
  10917. }
  10918. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10919. {
  10920. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10921. {
  10922. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10923. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10924. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10925. {
  10926. //Reserved
  10927. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10928. }
  10929. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10930. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10931. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10932. {
  10933. //Reserved
  10934. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10935. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10936. goto end;
  10937. }
  10938. else
  10939. {
  10940. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10941. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10942. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10943. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10944. {
  10945. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10946. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10947. goto end;
  10948. }
  10949. }//END FOR ELSE
  10950. }
  10951. }// END FOR CHAdeMO_QUANTITY
  10952. }
  10953. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10954. {
  10955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10956. {
  10957. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10958. }
  10959. else
  10960. {
  10961. tempIndex = connectorIdInt -1;
  10962. }
  10963. for (int index = 0; index < CCS_QUANTITY; index++)
  10964. {
  10965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10966. {
  10967. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10968. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10969. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10970. {
  10971. //Reserved
  10972. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10973. }
  10974. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10975. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10976. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10977. {
  10978. //Reserved
  10979. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10980. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10981. goto end;
  10982. }
  10983. else
  10984. {
  10985. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10986. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10987. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10988. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10989. {
  10990. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10991. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10992. goto end;
  10993. }
  10994. }// END FOR ELSE
  10995. }
  10996. }// END FOR CCS_QUANTITY
  10997. }
  10998. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10999. {
  11000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11001. {
  11002. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11003. }
  11004. else
  11005. {
  11006. tempIndex = connectorIdInt -1;
  11007. }
  11008. for (int index = 0; index < GB_QUANTITY; index++)
  11009. {
  11010. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11011. {
  11012. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11013. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11014. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11015. {
  11016. //Reserved
  11017. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11018. }
  11019. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11020. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11021. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11022. {
  11023. //Reserved
  11024. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11025. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11026. goto end;
  11027. }
  11028. else
  11029. {
  11030. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11031. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11032. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11033. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11034. {
  11035. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11036. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11037. goto end;
  11038. }
  11039. }// END FOR ELSE
  11040. }
  11041. } // END FOR GB_QUANTITY
  11042. }
  11043. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11044. {
  11045. tempIndex = connectorIdInt -1;
  11046. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11047. {
  11048. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11049. {
  11050. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11051. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11052. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11053. {
  11054. //Reserved
  11055. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11056. }
  11057. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11058. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11059. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11060. {
  11061. //Reserved
  11062. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11063. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11064. goto end;
  11065. }
  11066. else
  11067. {
  11068. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11069. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11070. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11071. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11072. {
  11073. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11075. goto end;
  11076. }
  11077. }// END FOR ELSE
  11078. }
  11079. } // END FOR GB_QUANTITY
  11080. }
  11081. else
  11082. {
  11083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11084. {
  11085. tempIndex = 2;
  11086. }
  11087. else
  11088. {
  11089. tempIndex = connectorIdInt -1;
  11090. }
  11091. for (int index = 0; index < AC_QUANTITY; index++)
  11092. {
  11093. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11094. {
  11095. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11096. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11097. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11098. {
  11099. //Reserved
  11100. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11101. }
  11102. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11103. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11104. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11105. {
  11106. //Reserved
  11107. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11108. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11109. goto end;
  11110. }
  11111. else
  11112. {
  11113. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11114. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11115. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11116. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11117. {
  11118. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11119. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11120. goto end;
  11121. }
  11122. }//END FOR ELSE
  11123. }
  11124. }// END FOR AC_QUANTITY
  11125. }
  11126. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11127. {
  11128. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11129. {
  11130. // Save profile to file
  11131. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11132. system(cmdBuf);
  11133. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11134. fp = fopen(cmdBuf, "w");
  11135. 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));
  11136. fclose(fp);
  11137. }
  11138. else
  11139. {
  11140. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11141. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11142. goto end;
  11143. }
  11144. }
  11145. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11146. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11147. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11148. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11149. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11150. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11151. }
  11152. else
  11153. {
  11154. uint8_t isHasIdleConnector = FALSE;
  11155. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11156. {
  11157. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11158. {
  11159. isHasIdleConnector = TRUE;
  11160. break;
  11161. }
  11162. }
  11163. if(isHasIdleConnector == TRUE)
  11164. {
  11165. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11166. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11167. {
  11168. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11169. {
  11170. // Save profile to file
  11171. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11172. system(cmdBuf);
  11173. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11174. fp = fopen(cmdBuf, "w");
  11175. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11176. fclose(fp);
  11177. refreshStartTimer(&clientTime.RemoteStartWait);
  11178. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11179. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11180. }
  11181. else
  11182. {
  11183. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11184. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11185. }
  11186. }
  11187. else
  11188. {
  11189. refreshStartTimer(&clientTime.RemoteStartWait);
  11190. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11191. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11192. }
  11193. }
  11194. else
  11195. {
  11196. DEBUG_INFO("There is not any connector is idle.\n");
  11197. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11198. }
  11199. }
  11200. }
  11201. else
  11202. {
  11203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11204. }
  11205. end:
  11206. json_object_put(RemoteStartTransaction);
  11207. sendRemoteStartConfirmation(uuid, comfirmstr);
  11208. return result;
  11209. }
  11210. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11211. {
  11212. mtrace();
  11213. int result = FAIL;
  11214. int match = FALSE;
  11215. int GunNO = 0;
  11216. int tempIndex = 0;
  11217. int transactionIdInt=0;
  11218. int transactionIdIsNULL= TRUE;
  11219. char comfirmstr[20];
  11220. json_object *RemoteStopTransaction;
  11221. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11222. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11223. if(server_pending == TRUE)
  11224. {
  11225. return 0;
  11226. }
  11227. RemoteStopTransaction = json_tokener_parse(payload);
  11228. if(!is_error(RemoteStopTransaction))
  11229. {
  11230. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11231. {
  11232. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11233. transactionIdIsNULL = FALSE;
  11234. }
  11235. }
  11236. json_object_put(RemoteStopTransaction);
  11237. if(transactionIdIsNULL == FALSE)
  11238. {
  11239. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11240. {
  11241. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11242. {
  11243. //check Transaction active
  11244. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11245. {
  11246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11247. {
  11248. tempIndex = ((gun_index==2) ? 1: 0);
  11249. }
  11250. else
  11251. {
  11252. tempIndex = gun_index;
  11253. }
  11254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11255. {
  11256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11257. {
  11258. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11259. {
  11260. match = TRUE;
  11261. GunNO = gun_index;
  11262. }
  11263. }
  11264. }// END FOR CHAdeMO_QUANTITY
  11265. }
  11266. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11267. {
  11268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11269. {
  11270. tempIndex = ((gun_index==2) ? 1: 0);
  11271. }
  11272. else
  11273. {
  11274. tempIndex = gun_index;
  11275. }
  11276. for (int index = 0; index < CCS_QUANTITY; index++)
  11277. {
  11278. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11279. {
  11280. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11281. {
  11282. match = TRUE;
  11283. GunNO = gun_index;
  11284. }
  11285. }
  11286. }// END FOR CCS_QUANTITY
  11287. }
  11288. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11289. {
  11290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11291. {
  11292. tempIndex = ((gun_index==2) ? 1: 0);
  11293. }
  11294. else
  11295. {
  11296. tempIndex = gun_index;
  11297. }
  11298. for (int index = 0; index < GB_QUANTITY; index++)
  11299. {
  11300. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11301. {
  11302. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11303. {
  11304. match = TRUE;
  11305. GunNO = gun_index;
  11306. }
  11307. }
  11308. }// END FOR GB_QUANTITY
  11309. }
  11310. else if(gunType[gun_index] == GUN_TYPE_DO)
  11311. {
  11312. tempIndex = gun_index;
  11313. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11314. {
  11315. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11316. {
  11317. 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
  11318. {
  11319. match = TRUE;
  11320. GunNO = gun_index;
  11321. }
  11322. }
  11323. }// END FOR GB_QUANTITY
  11324. }
  11325. else
  11326. {
  11327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11328. {
  11329. tempIndex = 2;
  11330. }
  11331. else
  11332. {
  11333. tempIndex = gun_index;
  11334. }
  11335. for (int index = 0; index < AC_QUANTITY; index++)
  11336. {
  11337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11338. {
  11339. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11340. {
  11341. match = TRUE;
  11342. GunNO = gun_index;
  11343. }
  11344. }
  11345. }// END FOR CHAdeMO_QUANTITY
  11346. } // END FOR AC ELSE
  11347. }// CHECK IF ResponseTransactionId == transactionIdInt
  11348. }//END FOR
  11349. if( match == TRUE)
  11350. {
  11351. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11352. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11353. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11354. }
  11355. else
  11356. {
  11357. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11358. }
  11359. }
  11360. else
  11361. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11362. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11363. return result;
  11364. }
  11365. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11366. {
  11367. mtrace();
  11368. int result = FAIL;
  11369. int connectorIdInt=0, reservationIdInt=0;
  11370. int tempIndex = 0;
  11371. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11372. char comfirmstr[20]={0};
  11373. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11374. int c = 0;
  11375. char *loc;
  11376. //char *ptr;
  11377. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11378. strcpy(sstrtemp, stringtrimspace(payload));
  11379. //***(1)connectorId ****/
  11380. c=0;
  11381. loc = strstr(sstrtemp, "connectorId");
  11382. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11383. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11384. {
  11385. sstr[c] = loc[strlen("connectorId")+2+c];
  11386. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11387. c++;
  11388. }
  11389. sstr[c] = '\0';
  11390. connectorIdInt = atoi(sstr);
  11391. //***(2)expiryDate ****/
  11392. loc = strstr(sstrtemp, "expiryDate");
  11393. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11394. c = 0;
  11395. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11396. {
  11397. sstr[c] = loc[3+strlen("expiryDate")+c];
  11398. c++;
  11399. }
  11400. sstr[c] = '\0';
  11401. strcpy(expiryDatestr, sstr);
  11402. //***(3)idTag ****/
  11403. loc = strstr(sstrtemp, "idTag");
  11404. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11405. c = 0;
  11406. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11407. {
  11408. sstr[c] = loc[3+strlen("idTag")+c];
  11409. c++;
  11410. }
  11411. sstr[c] = '\0';
  11412. strcpy(idTagstr, sstr);
  11413. //***(4)parentIdTag ****/
  11414. loc = strstr(sstrtemp, "parentIdTag");
  11415. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11416. c = 0;
  11417. if(loc == NULL)
  11418. {
  11419. strcpy(parentIdTagstr, "");
  11420. }
  11421. else
  11422. {
  11423. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11424. {
  11425. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11426. c++;
  11427. }
  11428. sstr[c] = '\0';
  11429. strcpy(parentIdTagstr, sstr);
  11430. }
  11431. //***(5)reservationId ****/
  11432. c=0;
  11433. loc = strstr(sstrtemp, "reservationId");
  11434. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11435. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11436. {
  11437. sstr[c] = loc[strlen("reservationId")+2+c];
  11438. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11439. c++;
  11440. }
  11441. sstr[c] = '\0';
  11442. reservationIdInt = atoi(sstr);
  11443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11444. /*
  11445. enum SYSTEM_STATUS
  11446. {
  11447. SYS_MODE_BOOTING = 0,
  11448. SYS_MODE_IDLE = 1,
  11449. SYS_MODE_AUTHORIZING = 2,
  11450. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11451. SYS_MODE_REASSIGN = 4,
  11452. SYS_MODE_PREPARING = 5,
  11453. SYS_MODE_PREPARE_FOR_EV = 6,
  11454. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11455. SYS_MODE_CHARGING = 8,
  11456. SYS_MODE_TERMINATING = 9,
  11457. SYS_MODE_COMPLETE = 10,
  11458. SYS_MODE_ALARM = 11,
  11459. SYS_MODE_FAULT = 12,
  11460. SYS_MODE_RESERVATION = 13,
  11461. SYS_MODE_BOOKING = 14,
  11462. SYS_MODE_MAINTAIN = 15,
  11463. SYS_MODE_DEBUG = 16,
  11464. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11465. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11466. SYS_MODE_UPDATE = 19
  11467. };
  11468. */
  11469. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11470. {
  11471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11472. goto end;
  11473. }
  11474. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11475. {
  11476. //check Transaction active
  11477. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11478. {
  11479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11480. {
  11481. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11482. }
  11483. else
  11484. {
  11485. tempIndex = connectorIdInt -1;
  11486. }
  11487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11488. {
  11489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11490. {
  11491. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11492. {
  11493. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11494. {
  11495. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11496. {
  11497. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11499. }
  11500. 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'))
  11501. {
  11502. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11503. }
  11504. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11505. {
  11506. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11507. }
  11508. else
  11509. {
  11510. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11511. }
  11512. }
  11513. 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
  11514. {
  11515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11516. }
  11517. }
  11518. else
  11519. {
  11520. //replace reservation
  11521. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11523. }
  11524. }
  11525. } // END FOR CHAdeMO_QUANTITY
  11526. }
  11527. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11528. {
  11529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11530. {
  11531. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11532. }
  11533. else
  11534. {
  11535. tempIndex = connectorIdInt -1;
  11536. }
  11537. for (int index = 0; index < CCS_QUANTITY; index++)
  11538. {
  11539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11540. {
  11541. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11542. {
  11543. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11544. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11545. {
  11546. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11547. {
  11548. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11550. }
  11551. 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'))
  11552. {
  11553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11554. }
  11555. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11556. {
  11557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11558. }
  11559. else
  11560. {
  11561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11562. }
  11563. }
  11564. 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
  11565. {
  11566. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11567. }
  11568. }
  11569. else
  11570. {
  11571. //replace reservation
  11572. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11574. }
  11575. }
  11576. } // END FOR CCS_QUANTITY
  11577. }
  11578. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11579. {
  11580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11581. {
  11582. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11583. }
  11584. else
  11585. {
  11586. tempIndex = connectorIdInt -1;
  11587. }
  11588. for (int index = 0; index < GB_QUANTITY; index++)
  11589. {
  11590. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11591. {
  11592. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11593. {
  11594. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11595. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11596. {
  11597. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11598. {
  11599. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11601. }
  11602. 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'))
  11603. {
  11604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11605. }
  11606. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11607. {
  11608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11609. }
  11610. else
  11611. {
  11612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11613. }
  11614. }
  11615. 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
  11616. {
  11617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11618. }
  11619. }
  11620. else
  11621. {
  11622. //replace reservation
  11623. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11625. }
  11626. }
  11627. }// END FOR GB_QUANTITY
  11628. }
  11629. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11630. {
  11631. tempIndex = connectorIdInt -1;
  11632. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11633. {
  11634. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11635. {
  11636. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11637. {
  11638. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11639. 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
  11640. {
  11641. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11642. {
  11643. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11645. }
  11646. 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'))
  11647. {
  11648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11649. }
  11650. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11651. {
  11652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11653. }
  11654. else
  11655. {
  11656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11657. }
  11658. }
  11659. 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
  11660. {
  11661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11662. }
  11663. }
  11664. else
  11665. {
  11666. //replace reservation
  11667. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11669. }
  11670. }
  11671. }// END FOR GB_QUANTITY
  11672. }
  11673. else
  11674. {
  11675. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11676. {
  11677. tempIndex = 2;
  11678. }
  11679. else
  11680. {
  11681. tempIndex = (connectorIdInt -1);
  11682. }
  11683. for (int index = 0; index < AC_QUANTITY; index++)
  11684. {
  11685. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11686. {
  11687. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11688. {
  11689. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11690. {
  11691. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11692. {
  11693. 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))
  11694. {
  11695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11696. }
  11697. else
  11698. {
  11699. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11701. }
  11702. }
  11703. 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'))
  11704. {
  11705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11706. }
  11707. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11708. {
  11709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11710. }
  11711. else
  11712. {
  11713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11714. }
  11715. }
  11716. 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
  11717. {
  11718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11719. }
  11720. }
  11721. else
  11722. {
  11723. //replace reservation
  11724. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11726. }
  11727. }
  11728. } // END FOR AC_QUANTITY
  11729. }
  11730. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11731. }
  11732. else if(connectorIdInt == 0)
  11733. {
  11734. //check Transaction active
  11735. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11736. {
  11737. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11738. {
  11739. 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'))
  11740. {
  11741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11742. goto end;
  11743. }
  11744. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11745. {
  11746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11747. goto end;
  11748. }
  11749. 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
  11750. {
  11751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11752. goto end;
  11753. }
  11754. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11755. {
  11756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11757. goto end;
  11758. }
  11759. }
  11760. }// END FOR CHAdeMO_QUANTITY
  11761. for (int index = 0; index < CCS_QUANTITY; index++)
  11762. {
  11763. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11764. {
  11765. 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'))
  11766. {
  11767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11768. goto end;
  11769. }
  11770. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11771. {
  11772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11773. goto end;
  11774. }
  11775. 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
  11776. {
  11777. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11778. goto end;
  11779. }
  11780. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11781. {
  11782. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11783. goto end;
  11784. }
  11785. }
  11786. } // END FOR CCS_QUANTITY
  11787. for (int index = 0; index < GB_QUANTITY; index++)
  11788. {
  11789. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11790. {
  11791. 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'))
  11792. {
  11793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11794. goto end;
  11795. }
  11796. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11797. {
  11798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11799. goto end;
  11800. }
  11801. 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
  11802. {
  11803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11804. goto end;
  11805. }
  11806. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11807. {
  11808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11809. goto end;
  11810. }
  11811. }
  11812. } // END FOR GB_QUANTITY
  11813. for (int index = 0; index < AC_QUANTITY; index++)
  11814. {
  11815. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11816. {
  11817. 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'))
  11818. {
  11819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11820. goto end;
  11821. }
  11822. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11823. {
  11824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11825. goto end;
  11826. }
  11827. 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
  11828. {
  11829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11830. goto end;
  11831. }
  11832. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11833. {
  11834. 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))
  11835. {
  11836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11837. goto end;
  11838. }
  11839. }
  11840. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11841. {
  11842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11843. goto end;
  11844. }
  11845. }
  11846. }// END FOR AC_QUANTITY
  11847. //The connectorId is 0
  11848. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11850. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11851. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11852. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11853. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11854. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11855. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11856. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11857. result = TRUE;
  11858. return result;
  11859. }
  11860. else
  11861. {
  11862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11863. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11864. }
  11865. if(strcmp(comfirmstr,"Accepted") == 0)
  11866. {
  11867. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11868. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11869. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11870. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11871. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11872. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11873. result = TRUE;
  11874. return result;
  11875. }
  11876. end:
  11877. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11878. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11879. return result;
  11880. }
  11881. int handleResetRequest(char *uuid, char *payload)
  11882. {
  11883. mtrace();
  11884. int result = FAIL;
  11885. char sstr[10]={0},sstrtemp[30]={ 0 };
  11886. char typestr[10]={0};
  11887. char comfirmstr[20]={0};
  11888. int c = 0;
  11889. char *loc;
  11890. DEBUG_INFO("handleResetRequest...\n");
  11891. strcpy(sstrtemp, stringtrimspace(payload));
  11892. loc = strstr(sstrtemp, "type");
  11893. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11894. c = 0;
  11895. while (loc[3+strlen("type")+c] != '\"')
  11896. {
  11897. sstr[c] = loc[3+strlen("type")+c];
  11898. c++;
  11899. }
  11900. sstr[c] = '\0';
  11901. strcpy(typestr,sstr);
  11902. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11903. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11904. {
  11905. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11906. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11907. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11908. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11909. }
  11910. else
  11911. {
  11912. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11913. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11914. result = PASS;
  11915. }
  11916. sendResetConfirmation(uuid, comfirmstr);
  11917. return result;
  11918. }
  11919. int handleSendLocalListRequest(char *uuid, char *payload)
  11920. {
  11921. mtrace();
  11922. int result = FAIL;
  11923. char comfirmstr[20];
  11924. int checkState_Faulted = FALSE;
  11925. json_object *SendLocalList;
  11926. DEBUG_INFO("handleSendLocalListRequest...\n");
  11927. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11928. {
  11929. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11930. goto end;
  11931. }
  11932. //check Charge Point state
  11933. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11934. {
  11935. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11936. {
  11937. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11938. }
  11939. }
  11940. for (int index = 0; index < CCS_QUANTITY; index++)
  11941. {
  11942. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11943. {
  11944. checkState_Faulted = TRUE; //OCPP Status
  11945. }
  11946. }
  11947. for (int index = 0; index < GB_QUANTITY; index++)
  11948. {
  11949. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11950. {
  11951. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11952. }
  11953. }
  11954. //check Charge Point state
  11955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11956. {
  11957. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11958. {
  11959. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11960. }
  11961. }
  11962. //check Charge Point state
  11963. for (int index = 0; index < AC_QUANTITY; index++)
  11964. {
  11965. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11966. {
  11967. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11968. }
  11969. }
  11970. if(checkState_Faulted == TRUE)
  11971. {
  11972. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11973. goto end;
  11974. }
  11975. // Parsing payload
  11976. SendLocalList = json_tokener_parse(payload);
  11977. if(!is_error(SendLocalList))
  11978. {
  11979. // Required data
  11980. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11981. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11982. // Optional data
  11983. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11984. {
  11985. //Check UpdateType
  11986. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11987. {
  11988. //Local list full update
  11989. DEBUG_INFO("Local list full update.\n");
  11990. OCPP_getListVerion();
  11991. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11992. {
  11993. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11994. goto end;
  11995. }
  11996. OCPP_cleanLocalList();
  11997. }
  11998. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11999. {
  12000. //Local list different update
  12001. DEBUG_INFO("Local list different update.\n");
  12002. OCPP_getListVerion();
  12003. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12004. {
  12005. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12006. goto end;
  12007. }
  12008. }
  12009. else
  12010. {
  12011. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12012. goto end;
  12013. }
  12014. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12015. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12016. {
  12017. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  12018. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12019. {
  12020. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].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")));
  12021. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12022. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].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")));
  12023. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12024. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].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")));
  12025. }
  12026. // Add to db
  12027. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12028. {
  12029. //Local list full update
  12030. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12031. idx,
  12032. ShmOCPP16Data->SendLocalList.ListVersion,
  12033. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12034. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12035. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12036. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12037. // update list
  12038. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12039. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12040. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12041. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12042. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12043. }
  12044. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12045. {
  12046. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12047. idx,
  12048. ShmOCPP16Data->SendLocalList.ListVersion,
  12049. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12050. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12051. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12052. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12053. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12054. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12055. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12056. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12057. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12058. }
  12059. }
  12060. }
  12061. else
  12062. {
  12063. //Check UpdateType
  12064. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12065. {
  12066. //Local list full update
  12067. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12068. OCPP_cleanLocalList();
  12069. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12070. goto end;
  12071. }
  12072. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12073. {
  12074. //Local list different update
  12075. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12076. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12077. goto end;
  12078. }
  12079. }
  12080. result = PASS;
  12081. }
  12082. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12083. end:
  12084. json_object_put(SendLocalList);
  12085. sendSendLocalListConfirmation(uuid, comfirmstr);
  12086. return result;
  12087. }
  12088. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12089. {
  12090. mtrace();
  12091. int result = FAIL;
  12092. struct StructSetChargingProfile SetProfileReq = {0};
  12093. int tempchargingProfileIdInt;
  12094. int chargingSchedulePeriodCount = 0;
  12095. char comfirmstr[20]={0};
  12096. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12097. char rmFileCmd[128]={0};
  12098. int profileQuantity = 0;
  12099. json_object *SetChargingProfile;
  12100. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12101. SetChargingProfile = json_tokener_parse(payload);
  12102. if(!is_error(SetChargingProfile))
  12103. {
  12104. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12105. {
  12106. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12107. }
  12108. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12109. {
  12110. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12111. {
  12112. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12113. }
  12114. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12115. {
  12116. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12117. }
  12118. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12119. {
  12120. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12121. }
  12122. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12123. {
  12124. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12125. }
  12126. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12127. {
  12128. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12129. }
  12130. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12131. {
  12132. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12133. }
  12134. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12135. {
  12136. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12137. }
  12138. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12139. {
  12140. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12141. }
  12142. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12143. {
  12144. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12145. {
  12146. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  12147. }
  12148. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12149. {
  12150. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12151. }
  12152. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12153. {
  12154. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12155. }
  12156. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12157. {
  12158. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  12159. }
  12160. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12161. {
  12162. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12163. if(chargingSchedulePeriodCount <= 10)
  12164. {
  12165. 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++)
  12166. {
  12167. 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)
  12168. {
  12169. SetProfileReq.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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  12170. }
  12171. 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)
  12172. {
  12173. SetProfileReq.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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  12174. }
  12175. 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)
  12176. {
  12177. SetProfileReq.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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  12178. }
  12179. }
  12180. }
  12181. }
  12182. }
  12183. }
  12184. }
  12185. // Profile periods quantity check
  12186. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12187. {
  12188. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12189. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12190. goto end;
  12191. }
  12192. // Check invalid limit
  12193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12194. {
  12195. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12196. {
  12197. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12198. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12199. {
  12200. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12201. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12202. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12203. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12204. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12205. goto end;
  12206. }
  12207. }
  12208. }
  12209. else
  12210. {
  12211. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12212. {
  12213. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower))
  12214. {
  12215. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12216. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12217. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12218. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12219. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12220. goto end;
  12221. }
  12222. }
  12223. }
  12224. // Profile purpose info check
  12225. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12226. {
  12227. FILE *fp;
  12228. char dataLine[4096]={0};
  12229. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12230. if(SetProfileReq.ConnectorId != 0)
  12231. {
  12232. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12233. DEBUG_WARN("Profile connector id is not 0.\n");
  12234. goto end;
  12235. }
  12236. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12237. if (!fp)
  12238. {
  12239. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12240. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12241. }
  12242. else
  12243. {
  12244. while(fscanf(fp, "%s", dataLine) != EOF)
  12245. {
  12246. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12247. {
  12248. profileQuantity += 1;
  12249. }
  12250. }
  12251. }
  12252. fclose(fp);
  12253. }
  12254. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12255. {
  12256. FILE *fp;
  12257. char dataLine[4096]={0};
  12258. char filename[128]={0};
  12259. int tmpProfileQuantity;
  12260. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12261. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12262. {
  12263. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12264. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12265. goto end;
  12266. }
  12267. if(SetProfileReq.ConnectorId == 0)
  12268. {
  12269. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12270. {
  12271. tmpProfileQuantity = 0;
  12272. memset(filename, 0, ARRAY_SIZE(filename));
  12273. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12274. fp = fopen(filename, "r");
  12275. if (!fp)
  12276. {
  12277. DEBUG_INFO("%s does not create.\n", filename);
  12278. fp = fopen(filename, "w+");
  12279. }
  12280. else
  12281. {
  12282. while(fscanf(fp, "%s", dataLine) != EOF)
  12283. {
  12284. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12285. {
  12286. tmpProfileQuantity += 1;
  12287. }
  12288. }
  12289. }
  12290. fclose(fp);
  12291. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12292. }
  12293. }
  12294. else
  12295. {
  12296. memset(filename, 0, ARRAY_SIZE(filename));
  12297. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12298. fp = fopen(filename, "r");
  12299. if (!fp)
  12300. {
  12301. DEBUG_INFO("%s does not create.\n", filename);
  12302. fp = fopen(filename, "w+");
  12303. }
  12304. else
  12305. {
  12306. while(fscanf(fp, "%s", dataLine) != EOF)
  12307. {
  12308. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12309. {
  12310. profileQuantity += 1;
  12311. }
  12312. }
  12313. }
  12314. fclose(fp);
  12315. }
  12316. }
  12317. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12318. {
  12319. int isMatchTransactiodId= FALSE;
  12320. FILE *fp;
  12321. char dataLine[4096]={0};
  12322. char filename[128]={0};
  12323. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12324. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12325. if(SetProfileReq.ConnectorId == 0)
  12326. {
  12327. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12328. DEBUG_WARN("Profile connector id is 0.\n");
  12329. goto end;
  12330. }
  12331. int tempIndex = 0;
  12332. //check Transaction active
  12333. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12334. {
  12335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12336. {
  12337. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12338. }
  12339. else
  12340. {
  12341. tempIndex = SetProfileReq.ConnectorId -1;
  12342. }
  12343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12344. {
  12345. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12346. {
  12347. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12348. {
  12349. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12350. {
  12351. isMatchTransactiodId = TRUE;
  12352. break;
  12353. }
  12354. }
  12355. }
  12356. }
  12357. }
  12358. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12359. {
  12360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12361. {
  12362. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12363. }
  12364. else
  12365. {
  12366. tempIndex = SetProfileReq.ConnectorId -1;
  12367. }
  12368. for (int index = 0; index < CCS_QUANTITY; index++)
  12369. {
  12370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12371. {
  12372. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12373. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12374. {
  12375. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12376. {
  12377. isMatchTransactiodId = TRUE;
  12378. break;
  12379. }
  12380. }
  12381. }
  12382. }
  12383. }
  12384. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12385. {
  12386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12387. {
  12388. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12389. }
  12390. else
  12391. {
  12392. tempIndex = SetProfileReq.ConnectorId -1;
  12393. }
  12394. for (int index = 0; index < GB_QUANTITY; index++)
  12395. {
  12396. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12397. {
  12398. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12399. {
  12400. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12401. {
  12402. isMatchTransactiodId = TRUE;
  12403. break;
  12404. }
  12405. }
  12406. }
  12407. }
  12408. }
  12409. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12410. {
  12411. tempIndex = SetProfileReq.ConnectorId -1;
  12412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12413. {
  12414. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12415. {
  12416. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12417. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12418. {
  12419. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12420. {
  12421. isMatchTransactiodId = TRUE;
  12422. break;
  12423. }
  12424. }
  12425. }
  12426. }
  12427. }
  12428. else
  12429. {
  12430. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12431. {
  12432. tempIndex = 2;
  12433. }
  12434. else
  12435. {
  12436. tempIndex = (SetProfileReq.ConnectorId -1);
  12437. }
  12438. for (int index = 0; index < AC_QUANTITY; index++)
  12439. {
  12440. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12441. {
  12442. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12443. {
  12444. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12445. {
  12446. isMatchTransactiodId = TRUE;
  12447. break;
  12448. }
  12449. }
  12450. }
  12451. }
  12452. }
  12453. //check Transaction active
  12454. if(isMatchTransactiodId == FALSE)
  12455. {
  12456. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12457. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12458. goto end;
  12459. }
  12460. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12461. {
  12462. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12463. DEBUG_WARN("Connector id is over max gun number.\n");
  12464. goto end;
  12465. }
  12466. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12467. fp = fopen(filename, "r");
  12468. if (!fp)
  12469. {
  12470. DEBUG_INFO("%s does not create.\n", filename);
  12471. fp = fopen(filename, "w+");
  12472. }
  12473. else
  12474. {
  12475. //Check Charging Profile Count
  12476. while(fscanf(fp, "%s", dataLine) != EOF)
  12477. {
  12478. //DEBUG_INFO("word=%s\n",word);
  12479. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12480. {
  12481. profileQuantity += 1;
  12482. }
  12483. }
  12484. }
  12485. fclose(fp);
  12486. }
  12487. // Check ChargeProfileMaxStackLevel
  12488. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12489. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12490. {
  12491. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12492. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12493. goto end;
  12494. }
  12495. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12496. {
  12497. FILE *fp;
  12498. char dataLine[4096]={0};
  12499. char fnametemp[128]={0};
  12500. int tmpProfileQuantity;
  12501. //Check ChargePointMaxProfile.json exit
  12502. profileQuantity = 0;
  12503. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12504. {
  12505. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12506. //Check Charging Profile Count
  12507. tmpProfileQuantity = 0;
  12508. while(fscanf(fp, "%s", dataLine) != EOF)
  12509. {
  12510. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12511. {
  12512. profileQuantity += 1;
  12513. tmpProfileQuantity += 1;
  12514. }
  12515. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12516. }
  12517. fclose(fp);
  12518. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12519. }
  12520. //Check TxDefaultProfile_%d.json
  12521. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12522. {
  12523. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12524. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12525. if((access(fnametemp,F_OK))!=-1)
  12526. {
  12527. fp = fopen(fnametemp, "r");
  12528. //Check Charging Profile Count
  12529. tmpProfileQuantity = 0;
  12530. while(fscanf(fp, "%s", dataLine) != EOF)
  12531. {
  12532. //DEBUG_INFO("word=%s\n",word);
  12533. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12534. {
  12535. profileQuantity += 1;
  12536. tmpProfileQuantity += 1;
  12537. }
  12538. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12539. }
  12540. fclose(fp);
  12541. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12542. }
  12543. }
  12544. //Check TxProfile_%d.json
  12545. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12546. {
  12547. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12548. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12549. if((access(fnametemp,F_OK))!=-1)
  12550. {
  12551. fp = fopen(fnametemp, "r");
  12552. //Check Charging Profile Count
  12553. tmpProfileQuantity = 0;
  12554. while(fscanf(fp, "%s", dataLine) != EOF)
  12555. {
  12556. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12557. {
  12558. profileQuantity += 1;
  12559. tmpProfileQuantity += 1;
  12560. }
  12561. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12562. }
  12563. fclose(fp);
  12564. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12565. }
  12566. }
  12567. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12568. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12569. {
  12570. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12571. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12572. goto end;
  12573. }
  12574. }
  12575. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12576. //**********************************Write to File********************************************************/
  12577. {
  12578. FILE *infile;
  12579. FILE *outfile;
  12580. char dataLine[4096]={0};
  12581. char filename[128]={0};
  12582. int chkChar=0;
  12583. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12584. {
  12585. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12586. {
  12587. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12588. }
  12589. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12590. {
  12591. if(SetProfileReq.ConnectorId==0)
  12592. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12593. else
  12594. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12595. }
  12596. else
  12597. {
  12598. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12599. }
  12600. infile = fopen (filename, "r");
  12601. outfile = fopen (tempfile, "w");
  12602. chkChar = fgetc(infile);
  12603. rewind(infile);
  12604. if(chkChar == EOF)
  12605. {
  12606. // Profile is empty
  12607. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12608. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12609. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12610. fclose(infile);
  12611. fclose(outfile);
  12612. sprintf(rmFileCmd,"rm -f %s",filename);
  12613. system(rmFileCmd);
  12614. rename(tempfile, filename);
  12615. }
  12616. else
  12617. {
  12618. // Profile is not empty
  12619. int ChargingProfileAdded = FALSE;
  12620. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12621. {
  12622. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12623. json_object *tmpChargingProfile;
  12624. tmpChargingProfile = json_tokener_parse(dataLine);
  12625. if(!is_error(SetChargingProfile))
  12626. {
  12627. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12628. {
  12629. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12630. {
  12631. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12632. }
  12633. }
  12634. }
  12635. json_object_put(tmpChargingProfile);
  12636. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12637. {
  12638. if(ChargingProfileAdded == FALSE)
  12639. {
  12640. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12641. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12642. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12643. ChargingProfileAdded = TRUE;
  12644. }
  12645. }
  12646. else
  12647. {
  12648. fprintf(outfile,"%s\n",dataLine);
  12649. if(ChargingProfileAdded == FALSE)
  12650. {
  12651. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12652. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12653. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12654. ChargingProfileAdded = TRUE;
  12655. }
  12656. }
  12657. } // end of while loop
  12658. fclose(infile);
  12659. fclose(outfile);
  12660. sprintf(rmFileCmd,"rm -f %s",filename);
  12661. system(rmFileCmd);
  12662. rename(tempfile, filename);
  12663. }
  12664. }
  12665. sleep(1);
  12666. result = TRUE;
  12667. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12668. }
  12669. end:
  12670. json_object_put(SetChargingProfile);
  12671. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12672. {
  12673. if(SetProfileReq.ConnectorId == 0)
  12674. {
  12675. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12676. {
  12677. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12678. }
  12679. }
  12680. else
  12681. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12682. }
  12683. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12684. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12685. return result;
  12686. }
  12687. int handleTriggerMessageRequest(char *uuid, char *payload)
  12688. {
  12689. mtrace();
  12690. int result = FAIL;
  12691. int connectorIdIsNULL = FALSE;
  12692. int connectorIdInt =0;
  12693. char sstr[40]={0},sstrtemp[100]={ 0 };
  12694. char requestedMessagestr[40]={0};
  12695. char comfirmstr[20]={0};
  12696. int c = 0;
  12697. char *loc;
  12698. DEBUG_INFO("handleTriggerMessageRequest\n");
  12699. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12700. strcpy(sstrtemp, stringtrimspace(payload));
  12701. c = 0;
  12702. loc = strstr(sstrtemp, "requestedMessage");
  12703. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12704. {
  12705. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12706. c++;
  12707. }
  12708. sstr[c] = '\0';
  12709. strcpy(requestedMessagestr, sstr);
  12710. c = 0;
  12711. loc = strstr(sstrtemp, "connectorId");
  12712. if(loc == NULL)
  12713. {
  12714. connectorIdIsNULL = TRUE;
  12715. }
  12716. else
  12717. {
  12718. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12719. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12720. {
  12721. sstr[c] = loc[strlen("connectorId")+2+c];
  12722. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12723. c++;
  12724. }
  12725. sstr[c] = '\0';
  12726. connectorIdInt = atoi(sstr);
  12727. }
  12728. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12729. {
  12730. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12731. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12732. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12733. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12734. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12735. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12736. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12737. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12738. {
  12739. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12740. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12741. return TRUE;
  12742. }
  12743. else
  12744. {
  12745. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12746. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12747. }
  12748. }
  12749. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12750. {
  12751. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12752. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12753. return TRUE;
  12754. }
  12755. //==========================
  12756. // Trigger message
  12757. //==========================
  12758. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12759. {
  12760. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12761. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12762. {
  12763. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12764. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12765. }
  12766. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12767. }
  12768. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12769. {
  12770. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12771. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12772. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12773. }
  12774. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12775. {
  12776. //sendBootNotificationRequest();
  12777. server_sign = FALSE;
  12778. }
  12779. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12780. {
  12781. refreshStartTimer(&clientTime.Heartbeat);
  12782. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12783. }
  12784. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12785. {
  12786. if(connectorIdIsNULL == FALSE)
  12787. {
  12788. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12789. {
  12790. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12791. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12792. }
  12793. }
  12794. else
  12795. {
  12796. for(int idx=0;idx< gunTotalNumber;idx++)
  12797. {
  12798. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12799. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12800. }
  12801. }
  12802. }
  12803. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12804. {
  12805. if(connectorIdIsNULL == FALSE)
  12806. {
  12807. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12808. {
  12809. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12810. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12811. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12812. }
  12813. }
  12814. else
  12815. {
  12816. for(int idx=0;idx< gunTotalNumber;idx++)
  12817. {
  12818. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12819. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12820. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12821. }
  12822. }
  12823. }
  12824. return result;
  12825. }
  12826. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12827. {
  12828. mtrace();
  12829. int result = FAIL;
  12830. int connectorIdInt =0;
  12831. char comfirmstr[20]={0};
  12832. int tempIndex = 0;
  12833. json_object *UnlockConnector;
  12834. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12835. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12836. UnlockConnector = json_tokener_parse(payload);
  12837. if(!is_error(UnlockConnector))
  12838. {
  12839. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12840. {
  12841. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12842. }
  12843. }
  12844. json_object_put(UnlockConnector);
  12845. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12846. if(gunTotalNumber == 0)
  12847. {
  12848. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12849. goto end;
  12850. }
  12851. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12852. {
  12853. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12854. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12855. goto end;
  12856. }
  12857. else
  12858. {
  12859. //check Transaction active
  12860. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12861. {
  12862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12863. {
  12864. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12865. }
  12866. else
  12867. {
  12868. tempIndex = connectorIdInt -1;
  12869. }
  12870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12871. {
  12872. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12873. {
  12874. //stop Transaction
  12875. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12876. }
  12877. }
  12878. }
  12879. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12880. {
  12881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12882. {
  12883. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12884. }
  12885. else
  12886. {
  12887. tempIndex = connectorIdInt -1;
  12888. }
  12889. for (int index = 0; index < CCS_QUANTITY; index++)
  12890. {
  12891. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12892. {
  12893. //stop Transaction
  12894. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12895. }
  12896. }
  12897. }
  12898. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12899. {
  12900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12901. {
  12902. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12903. }
  12904. else
  12905. {
  12906. tempIndex = connectorIdInt -1;
  12907. }
  12908. for (int index = 0; index < GB_QUANTITY; index++)
  12909. {
  12910. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12911. {
  12912. //stop Transaction
  12913. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12914. }
  12915. }
  12916. }
  12917. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12918. {
  12919. tempIndex = connectorIdInt -1;
  12920. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12921. {
  12922. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12923. {
  12924. //stop Transaction
  12925. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12926. }
  12927. }
  12928. }
  12929. else
  12930. {
  12931. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12932. {
  12933. tempIndex = 2;
  12934. }
  12935. else
  12936. {
  12937. tempIndex = connectorIdInt-1;
  12938. }
  12939. for (int index = 0; index < AC_QUANTITY; index++)
  12940. {
  12941. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12942. {
  12943. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12944. }
  12945. }
  12946. }
  12947. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12948. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12949. result = TRUE;
  12950. return result;
  12951. }
  12952. end:
  12953. //json_object_put(obj); --- remove temporally
  12954. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12955. return result;
  12956. }
  12957. static char UpdateFirmwarepayloadData[300]={0};
  12958. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12959. {
  12960. mtrace();
  12961. int result = FAIL;
  12962. pthread_t t;
  12963. sendUpdateFirmwareConfirmation(uuid);
  12964. memset(UpdateFirmwarepayloadData, 0, 300);
  12965. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12966. if(!interLock.isUpdateFirmwareGoing)
  12967. {
  12968. interLock.isUpdateFirmwareGoing = 1;
  12969. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12970. sleep(1);
  12971. }
  12972. else
  12973. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12974. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12975. return result;
  12976. }
  12977. void *UpdateFirmwareProcess(void *data)
  12978. {
  12979. pthread_detach(pthread_self());
  12980. mtrace();
  12981. int retriesInt =0, retryIntervalInt=0;
  12982. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12983. int port=0;
  12984. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12985. int isSuccess = 0;
  12986. char ftpbuf[1024];
  12987. char temp[1024];
  12988. char * pch;
  12989. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12990. json_object *UpdateFirmware;
  12991. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12992. if(!is_error(UpdateFirmware))
  12993. {
  12994. // Required data
  12995. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12996. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12997. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12998. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12999. // Optional data
  13000. if(json_object_object_get(UpdateFirmware, "retries"))
  13001. {
  13002. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13003. }
  13004. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13005. {
  13006. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13007. }
  13008. }
  13009. json_object_put(UpdateFirmware);
  13010. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13011. memset(path, 0, ARRAY_SIZE(path));
  13012. // Wait retrieveData
  13013. if(strlen(retrieveDatestr) > 10)
  13014. {
  13015. do
  13016. {
  13017. sleep(1);
  13018. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13019. }
  13020. // Ready to download
  13021. system("rm -f /mnt/*");
  13022. if(strncmp(locationstr,"http", 4) == 0)
  13023. {
  13024. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13025. sprintf(ftppath,"/%s", path);
  13026. DEBUG_INFO("locationstr: %s\n", locationstr);
  13027. DEBUG_INFO("protocol: %s\n",protocol);
  13028. DEBUG_INFO("host: %s\n",host);
  13029. DEBUG_INFO("path: %s\n",path);
  13030. DEBUG_INFO("ftppath: %s\n",ftppath);
  13031. int ftppathlen=strlen(ftppath);
  13032. int i=1;
  13033. char filenametemp[50];
  13034. while(i < ftppathlen)
  13035. {
  13036. int len=ftppathlen-i;
  13037. if(ftppath[len]== 47) // '/' ascll code: 47
  13038. {
  13039. DEBUG_INFO("compare '/' all right\n");
  13040. break;
  13041. }
  13042. i=i+1;
  13043. }
  13044. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13045. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13046. filenametemp[i+1] = 0;
  13047. do
  13048. {
  13049. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13050. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13051. sleep(1);
  13052. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13053. if(!isSuccess)
  13054. {
  13055. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13056. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13057. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13058. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13059. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13060. }
  13061. else
  13062. {
  13063. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13064. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13065. }
  13066. retriesInt--;
  13067. }while((isSuccess == 0)&&(retriesInt >= 0));
  13068. }
  13069. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13070. {
  13071. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13072. memset(temp, 0, ARRAY_SIZE(temp));
  13073. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13074. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13075. int ftppathlen=strlen(ftpbuf);
  13076. int i=1;
  13077. char filenametemp[50];
  13078. while(i < ftppathlen)
  13079. {
  13080. int len=ftppathlen-i;
  13081. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13082. {
  13083. DEBUG_INFO(" compare '/' all right\n");
  13084. break;
  13085. }
  13086. i=i+1;
  13087. }
  13088. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13089. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13090. filenametemp[i+1] = 0;
  13091. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13092. pch=strchr(temp,'@');
  13093. if(pch==NULL)
  13094. {
  13095. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13096. protocol, host, &port, path);
  13097. strcpy(user,"anonymous");
  13098. strcpy(password,"");
  13099. }
  13100. else
  13101. {
  13102. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13103. protocol, user, password, host, &port, path);
  13104. }
  13105. sscanf(host,"%[^/]%s",host1, path1);
  13106. sprintf(ftppath,"%s", path1);
  13107. //DEBUG_INFO("protocol =%s\n",protocol);
  13108. //DEBUG_INFO("user =%s\n",user);
  13109. //DEBUG_INFO("password =%s\n",password);
  13110. //DEBUG_INFO("host1 =%s\n",host1);
  13111. //DEBUG_INFO("port =%d\n",port);
  13112. //DEBUG_INFO("path1 =%s\n",path1);
  13113. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13114. //ftpFile(host, user, password, port, ftppath, fname);
  13115. //download firmware pthred
  13116. if(port == 0)
  13117. {
  13118. port = 21;
  13119. }
  13120. do
  13121. {
  13122. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13123. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13124. sleep(1);
  13125. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13126. if(!isSuccess)
  13127. {
  13128. //BulldogUtil.sleepMs(interval*1000);
  13129. DEBUG_INFO("Update firmware request and download file fail.\n");
  13130. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13131. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13132. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13133. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13134. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13135. }
  13136. else
  13137. {
  13138. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13139. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13140. }
  13141. retriesInt--;
  13142. }while((!isSuccess)&&(retriesInt >= 0));
  13143. }
  13144. else
  13145. {
  13146. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13147. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13148. sleep(1);
  13149. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13150. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13151. }
  13152. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13153. interLock.isUpdateFirmwareGoing = 0;
  13154. pthread_exit(NULL);
  13155. }
  13156. int handleCertificateSignedRequest(char *uuid, char *payload)
  13157. {
  13158. mtrace();
  13159. int result = PASS;
  13160. json_object *CertificateSigned;
  13161. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13162. CertificateSigned = json_tokener_parse(payload);
  13163. if(!is_error(CertificateSigned))
  13164. {
  13165. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13166. }
  13167. json_object_put(CertificateSigned);
  13168. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13169. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13170. fclose(fp);
  13171. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13172. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13173. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13174. sendCertificateSignedConfirmation(uuid);
  13175. return result;
  13176. }
  13177. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13178. {
  13179. mtrace();
  13180. int result = PASS;
  13181. json_object *DeleteCertificate;
  13182. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13183. DeleteCertificate = json_tokener_parse(payload);
  13184. if(!is_error(DeleteCertificate))
  13185. {
  13186. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13187. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13188. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13189. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13190. }
  13191. json_object_put(DeleteCertificate);
  13192. /*
  13193. * TODO: Delete certificateSigned process
  13194. */
  13195. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13196. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13197. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13198. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13199. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13200. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13201. sendDeleteCertificateConfirmation(uuid);
  13202. return result;
  13203. }
  13204. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13205. {
  13206. mtrace();
  13207. int result = PASS;
  13208. json_object *ExtendedTriggerMessage;
  13209. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13210. ExtendedTriggerMessage = json_tokener_parse(payload);
  13211. if(!is_error(ExtendedTriggerMessage))
  13212. {
  13213. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13214. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13215. {
  13216. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13217. }
  13218. else
  13219. {
  13220. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13221. }
  13222. }
  13223. json_object_put(ExtendedTriggerMessage);
  13224. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13225. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13226. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13227. {
  13228. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13229. }
  13230. else
  13231. {
  13232. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13233. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13234. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13235. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13236. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13237. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13238. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13239. {
  13240. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13241. }
  13242. else
  13243. {
  13244. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13245. }
  13246. }
  13247. sendExtendedTriggerMessageConfirmation(uuid);
  13248. //==========================
  13249. // Trigger message
  13250. //==========================
  13251. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13252. {
  13253. //sendBootNotificationRequest();
  13254. server_sign = FALSE;
  13255. }
  13256. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13257. {
  13258. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13259. }
  13260. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13261. {
  13262. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13263. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13264. {
  13265. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13266. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13267. }
  13268. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13269. }
  13270. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13271. {
  13272. refreshStartTimer(&clientTime.Heartbeat);
  13273. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13274. }
  13275. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13276. {
  13277. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13278. {
  13279. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13280. }
  13281. else
  13282. {
  13283. for(int idx=0;idx< gunTotalNumber;idx++)
  13284. {
  13285. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13286. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13287. }
  13288. }
  13289. }
  13290. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13291. {
  13292. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13293. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13294. {
  13295. 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\" &");
  13296. }
  13297. }
  13298. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13299. {
  13300. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13301. {
  13302. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13303. }
  13304. else
  13305. {
  13306. for(int idx=0;idx< gunTotalNumber;idx++)
  13307. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13308. }
  13309. }
  13310. return result;
  13311. }
  13312. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13313. {
  13314. mtrace();
  13315. int result = PASS;
  13316. json_object *GetInstalledCertificateIds;
  13317. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13318. GetInstalledCertificateIds = json_tokener_parse(payload);
  13319. if(!is_error(GetInstalledCertificateIds))
  13320. {
  13321. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13322. }
  13323. json_object_put(GetInstalledCertificateIds);
  13324. /*
  13325. * TODO: Return installed certificate process
  13326. */
  13327. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13328. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13329. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13330. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13331. sendGetInstalledCertificateIdsConfirmation(uuid);
  13332. return result;
  13333. }
  13334. int handleGetLogRequest(char *uuid, char *payload)
  13335. {
  13336. mtrace();
  13337. int result = PASS;
  13338. json_object *GetLog;
  13339. DEBUG_INFO("handleGetLogRequest...\n");
  13340. GetLog = json_tokener_parse(payload);
  13341. if(!is_error(GetLog))
  13342. {
  13343. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13344. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13345. if(json_object_object_get(GetLog, "retries") != NULL)
  13346. {
  13347. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13348. }
  13349. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13350. {
  13351. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13352. }
  13353. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13354. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13355. {
  13356. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13357. }
  13358. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13359. {
  13360. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13361. }
  13362. }
  13363. json_object_put(GetLog);
  13364. /*
  13365. * TODO: Upload log process
  13366. */
  13367. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13368. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13369. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13370. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13371. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13372. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13373. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13374. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13375. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13376. sendGetLogConfirmation(uuid);
  13377. return result;
  13378. }
  13379. int handleInstallCertificateRequest(char *uuid, char *payload)
  13380. {
  13381. mtrace();
  13382. int result = PASS;
  13383. json_object *InstallCertificate;
  13384. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13385. InstallCertificate = json_tokener_parse(payload);
  13386. if(!is_error(InstallCertificate))
  13387. {
  13388. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13389. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13390. /*
  13391. * TODO: Install certificate process
  13392. */
  13393. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13394. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13395. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13396. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13397. sendInstallCertificateConfirmation(uuid);
  13398. }
  13399. json_object_put(InstallCertificate);
  13400. return result;
  13401. }
  13402. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13403. {
  13404. mtrace();
  13405. int result = PASS;
  13406. json_object *SignedUpdateFirmware;
  13407. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13408. SignedUpdateFirmware = json_tokener_parse(payload);
  13409. if(!is_error(SignedUpdateFirmware))
  13410. {
  13411. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13412. {
  13413. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13414. }
  13415. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13416. {
  13417. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13418. }
  13419. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13420. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13421. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13422. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13423. {
  13424. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13425. }
  13426. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13427. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13428. }
  13429. json_object_put(SignedUpdateFirmware);
  13430. /*
  13431. * TODO: Upgrade firmware process
  13432. */
  13433. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13434. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13435. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13436. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13437. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13438. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13439. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13440. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13441. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13442. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13443. sendInstallCertificateConfirmation(uuid);
  13444. return result;
  13445. }
  13446. int handleUnknownRequest(char *uuid, char *payload)
  13447. {
  13448. mtrace();
  13449. int result = PASS;
  13450. DEBUG_INFO("handleUnknownRequest...\n");
  13451. sendUnknownConfirmation(uuid);
  13452. result = PASS;
  13453. return result;
  13454. }
  13455. //==========================================
  13456. // Handle server response routine
  13457. //==========================================
  13458. void handleAuthorizeResponse(char *payload, int gun_index)
  13459. {
  13460. mtrace();
  13461. char expiryDatestr[30]={0};
  13462. char parentIdTagstr[20]={0};
  13463. char statusstr[20]={0};
  13464. int expiryDateISNULL=FALSE;
  13465. int parentIdTagISNULL=FALSE;
  13466. DEBUG_INFO("handleAuthorizeResponse...\n");
  13467. json_object *Authorize;
  13468. Authorize = json_tokener_parse(payload);
  13469. if(!is_error(Authorize))
  13470. {
  13471. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13472. {
  13473. // Required data
  13474. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13475. // Optional data
  13476. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13477. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13478. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13479. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13480. }
  13481. }
  13482. json_object_put(Authorize);
  13483. if(expiryDateISNULL == FALSE)
  13484. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13485. if(parentIdTagISNULL == FALSE)
  13486. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13487. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13488. //Update idTag information to authorization cache if supproted
  13489. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13490. {
  13491. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13492. }
  13493. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13494. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13495. authorizeRetryTimes = 0;
  13496. }
  13497. void handleBootNotificationResponse(char *payload, int gun_index)
  13498. {
  13499. mtrace();
  13500. char statusStr[12]={0};
  13501. char currentTimeStr[30]={0};
  13502. int intervalInt = 0;
  13503. DEBUG_INFO("handleBootNotificationResponse...\n");
  13504. json_object *BootNotification;
  13505. BootNotification = json_tokener_parse(payload);
  13506. if(!is_error(BootNotification))
  13507. {
  13508. // Required data
  13509. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13510. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13511. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13512. }
  13513. json_object_put(BootNotification);
  13514. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13515. BootNotificationInterval = intervalInt;
  13516. //write back to ShmOCPP16Data->BootNotification
  13517. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13518. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13519. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13520. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13521. {
  13522. if((intervalInt == 0) || (intervalInt >= 10))
  13523. {
  13524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13525. HeartBeatWaitTime = intervalInt;
  13526. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13527. }
  13528. server_sign = TRUE;
  13529. server_pending =FALSE;
  13530. }
  13531. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13532. {
  13533. server_pending = TRUE;
  13534. }
  13535. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13536. srand(time(NULL));
  13537. refreshStartTimer(&clientTime.Heartbeat);
  13538. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13539. SetOcppConnStatus(TRUE);
  13540. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13541. }
  13542. void handleDataTransferResponse(char *payload, int gun_index)
  13543. {
  13544. json_object *DataTransfer = json_tokener_parse(payload);
  13545. char status[32];
  13546. if(!is_error(DataTransfer))
  13547. {
  13548. // Required data
  13549. sprintf(status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13550. DEBUG_INFO("Status: %s.\n", status);
  13551. // Optional data
  13552. if(json_object_object_get(DataTransfer, "data") != NULL)
  13553. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13554. // YES call_reader message confirm
  13555. if(ShmYesCustomData->CallReaderReq == 1)
  13556. {
  13557. sprintf((char *)ShmYesCustomData->CallReaderStatus, "%s",status);
  13558. ShmYesCustomData->CallReaderConf = 1;
  13559. ShmYesCustomData->CallReaderReq = 0;
  13560. DEBUG_INFO("Report CallReader status to CSU: %s\n",ShmYesCustomData->CallReaderStatus);
  13561. }
  13562. }
  13563. }
  13564. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13565. {
  13566. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13567. //struct json_object *obj;
  13568. // obj = json_tokener_parse(payload);
  13569. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13570. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13571. //No fields are defined.
  13572. }
  13573. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13574. {
  13575. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13576. //struct json_object *obj;
  13577. // obj = json_tokener_parse(payload);
  13578. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13579. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13580. //No fields are defined.
  13581. }
  13582. void handleHeartbeatResponse(char *payload, int gun_index)
  13583. {
  13584. mtrace();
  13585. DEBUG_INFO("handleHeartbeatResponse...\n");
  13586. json_object *Heartbeat;
  13587. Heartbeat = json_tokener_parse(payload);
  13588. if(!is_error(Heartbeat))
  13589. {
  13590. // Required data
  13591. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13592. }
  13593. json_object_put(Heartbeat);
  13594. if(FirstHeartBeat == 0)
  13595. {
  13596. FirstHeartBeat = 1;
  13597. DEBUG_INFO("FirstHeartBeat \n");
  13598. }
  13599. HeartBeatWithNOResponse = 0;
  13600. refreshStartTimer(&clientTime.Heartbeat);
  13601. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13602. }
  13603. void handleMeterValuesResponse(char *payload, int gun_index)
  13604. {
  13605. mtrace();
  13606. DEBUG_INFO("handleMeterValuesResponse...\n");
  13607. isQueueSendable = 1;
  13608. }
  13609. void handleStartTransactionResponse(char *payload, int gun_index)
  13610. {
  13611. mtrace();
  13612. //int transactionIdInt = 0;
  13613. FILE *outfile;
  13614. char data[100]={0};
  13615. DEBUG_INFO("handleStartTransactionResponse...\n");
  13616. json_object *StartTransaction;
  13617. StartTransaction = json_tokener_parse(payload);
  13618. if(!is_error(StartTransaction))
  13619. {
  13620. // Required data
  13621. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13622. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13623. // Optional data
  13624. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13625. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13626. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13627. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13628. }
  13629. json_object_put(StartTransaction);
  13630. isQueueSendable = 1;
  13631. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13632. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13633. //-----------Start : write to the Queue TransactionId file -----------------//
  13634. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13635. {}
  13636. else
  13637. {
  13638. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13639. if(log == NULL)
  13640. {
  13641. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13642. return ;
  13643. }
  13644. else
  13645. {
  13646. fclose(log);
  13647. }
  13648. }
  13649. // open file for writing
  13650. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13651. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13652. {
  13653. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13654. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13655. fputs(data, outfile);
  13656. fclose (outfile);
  13657. }
  13658. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13659. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13660. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13661. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13662. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13663. }
  13664. void handleStatusNotificationResponse(char *payload, int gun_index)
  13665. {
  13666. mtrace();
  13667. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13668. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13669. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13670. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13671. }
  13672. void handleStopTransactionnResponse(char *payload, int gun_index)
  13673. {
  13674. mtrace();
  13675. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13676. json_object *StopTransaction;
  13677. StopTransaction = json_tokener_parse(payload);
  13678. if(!is_error(StopTransaction))
  13679. {
  13680. // Optional data
  13681. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13682. {
  13683. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13684. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13685. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13686. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13687. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13688. }
  13689. }
  13690. json_object_put(StopTransaction);
  13691. isQueueSendable = 1;
  13692. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13693. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13694. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13695. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13696. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13697. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13698. }
  13699. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13700. {
  13701. mtrace();
  13702. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13703. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13704. }
  13705. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13706. {
  13707. mtrace();
  13708. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13709. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13710. }
  13711. void handleSignCertificateResponse(char *payload, int gun_index)
  13712. {
  13713. mtrace();
  13714. DEBUG_INFO("handleSignCertificateResponse...\n");
  13715. json_object *SignCertificate;
  13716. SignCertificate = json_tokener_parse(payload);
  13717. if(!is_error(SignCertificate))
  13718. {
  13719. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13720. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13721. }
  13722. json_object_put(SignCertificate);
  13723. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13724. }
  13725. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13726. {
  13727. mtrace();
  13728. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13729. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13730. }
  13731. //==========================================
  13732. // Handle Error routine
  13733. //==========================================
  13734. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13735. {
  13736. mtrace();
  13737. #ifdef SystemLogMessage
  13738. DEBUG_INFO("errorCode: %s\n", errorCode);
  13739. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13740. DEBUG_INFO("errorDetails: %s\n", payload);
  13741. #endif
  13742. }
  13743. //===============================================
  13744. // Common routine
  13745. //===============================================
  13746. int initialConfigurationTable(void)
  13747. {
  13748. //clock_t start_t, end_t, total_t;
  13749. FILE *fp;
  13750. FILE *outfile;
  13751. char str[512]={0};
  13752. char sstr[256]={0};
  13753. int c = 0;
  13754. char *loc;
  13755. int confVersion = 11;
  13756. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13757. //start_t = clock();
  13758. //printf("Starting of the program, start_t = %ld\n", start_t);
  13759. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13760. // Check configuration file size is correct
  13761. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13762. {
  13763. struct stat st;
  13764. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13765. if(st.st_size < 3100)
  13766. {
  13767. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13768. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13769. }
  13770. }
  13771. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13772. {
  13773. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13774. if(outfile == NULL)
  13775. {
  13776. DEBUG_INFO("Error opening file\n");
  13777. return FALSE;
  13778. }
  13779. /*Core Profile*/
  13780. //AllowOfflineTxForUnknownId
  13781. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13785. //AuthorizationCacheEnabled
  13786. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13790. //AuthorizeRemoteTxRequests
  13791. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13795. //BlinkRepeat
  13796. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13800. //ClockAlignedDataInterval
  13801. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13805. //ConnectionTimeOut
  13806. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13810. //GetConfigurationMaxKeys
  13811. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13815. // HeartbeatInterval
  13816. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13820. // LightIntensity
  13821. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13825. // LocalAuthorizeOffline
  13826. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13830. // LocalPreAuthorize
  13831. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13835. // MaxEnergyOnInvalidId
  13836. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13840. // MeterValuesAlignedData
  13841. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13845. else
  13846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13848. // MeterValuesAlignedDataMaxLength
  13849. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13853. else
  13854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13856. // MeterValuesSampledData
  13857. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13861. else
  13862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13864. // MeterValuesSampledDataMaxLength
  13865. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13867. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13869. else
  13870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13872. // MeterValueSampleInterval
  13873. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13877. // MinimumStatusDuration
  13878. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13881. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13883. // NumberOfConnectors
  13884. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13887. {
  13888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13889. }
  13890. else
  13891. {
  13892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13893. }
  13894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13895. // ResetRetries
  13896. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13900. // ConnectorPhaseRotation
  13901. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13905. // ConnectorPhaseRotationMaxLength
  13906. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13910. // StopTransactionOnEVSideDisconnect
  13911. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13915. // StopTransactionOnInvalidId
  13916. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13920. // StopTxnAlignedData
  13921. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13925. // StopTxnAlignedDataMaxLength
  13926. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13930. // StopTxnSampledData
  13931. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13933. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13935. else
  13936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13938. // StopTxnSampledDataMaxLength
  13939. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13942. {
  13943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13944. }
  13945. else
  13946. {
  13947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13948. }
  13949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13950. // SupportedFeatureProfiles
  13951. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13955. // SupportedFeatureProfilesMaxLength
  13956. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13960. // TransactionMessageAttempts
  13961. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13964. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13966. // TransactionMessageRetryInterval
  13967. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13970. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13972. // UnlockConnectorOnEVSideDisconnect
  13973. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13977. // WebSocketPingInterval
  13978. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13982. // QueueOffLineMeterValues
  13983. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13987. // AuthorizationKey
  13988. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13992. // SecurityProfile
  13993. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13997. // DefaultPrice
  13998. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14002. // CustomDisplayCostAndPrice
  14003. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14007. // CustomIdleFeeAfterStop
  14008. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14012. // TimeOffset
  14013. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14017. // NextTimeOffsetTransitionDateTime
  14018. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14022. // TimeOffsetNextTransition
  14023. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14027. // SystemUptimeSec
  14028. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14032. // FreeVend
  14033. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  14035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14037. // OcppServer
  14038. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14040. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14042. // MaintainServer
  14043. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14045. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14047. // Configuration Version
  14048. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14052. //* Local Auth List Management Profile*/
  14053. #if 0
  14054. //For OCTT Test Case
  14055. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14058. #endif
  14059. #if 1
  14060. //LocalAuthListEnabled
  14061. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14065. #endif
  14066. //LocalAuthListMaxLength
  14067. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14071. //SendLocalListMaxLength
  14072. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14076. //ReserveConnectorZeroSupported
  14077. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14081. //* Smart Charging Profile */
  14082. //ChargeProfileMaxStackLevel
  14083. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14087. // ChargingScheduleAllowedChargingRateUnit
  14088. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14092. // ChargingScheduleMaxPeriods
  14093. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14097. // ConnectorSwitch3to1PhaseSupported
  14098. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14102. // MaxChargingProfilesInstalled
  14103. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14107. fclose(outfile);
  14108. }
  14109. else
  14110. {
  14111. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14112. char keystr[60]={0};
  14113. char readonlystr[10]={0};
  14114. char valuestr[256]={0};
  14115. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14116. if(fp == NULL) {
  14117. DEBUG_INFO("Error opening file");
  14118. return FALSE;
  14119. }
  14120. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14121. {
  14122. //DEBUG_INFO("Get Configuration \n");
  14123. if(strlen(str) > 0)
  14124. {
  14125. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14126. //*************************key*********************************/
  14127. if(strstr(str, "key") != NULL)
  14128. {
  14129. loc = strstr(str, "key");
  14130. c = 0;
  14131. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14132. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14133. {
  14134. sstr[c] = loc[strlen("key")+3+c];
  14135. c++;
  14136. }
  14137. sstr[c] = '\0';
  14138. strcpy(keystr,sstr);
  14139. }
  14140. //*************************readonly*********************************/
  14141. if(strstr(str, "readonly") != NULL)
  14142. {
  14143. loc = strstr(str, "readonly");
  14144. c = 0;
  14145. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14146. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14147. {
  14148. sstr[c] = loc[strlen("readonly")+2+c];
  14149. c++;
  14150. }
  14151. sstr[c] = '\0';
  14152. strcpy(readonlystr,sstr);
  14153. }
  14154. //*************************value*********************************/
  14155. if(strstr(str, "value") != NULL)
  14156. {
  14157. loc = strstr(str, "value");
  14158. c = 0;
  14159. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14160. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14161. {
  14162. sstr[c] = loc[strlen("value")+3+c];
  14163. c++;
  14164. }
  14165. sstr[c] = '\0';
  14166. strcpy(valuestr,sstr);
  14167. }
  14168. // DEBUG_INFO("keystr=%s\n",keystr);
  14169. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14170. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14171. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14172. {
  14173. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14174. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14176. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14177. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14178. }
  14179. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14180. {
  14181. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14182. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14184. }
  14185. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14186. {
  14187. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14189. }
  14190. if(strcmp(keystr, "BlinkRepeat") == 0)
  14191. {
  14192. //Charger.BlinkRepeat = Integer.parseInt(value);
  14193. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14195. }
  14196. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14197. {
  14198. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14200. }
  14201. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14202. {
  14203. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14205. }
  14206. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14207. {
  14208. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14210. }
  14211. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14212. {
  14213. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14215. HeartBeatWaitTime = atoi(valuestr);
  14216. }
  14217. if(strcmp(keystr, "LightIntensity") == 0)
  14218. {
  14219. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14221. }
  14222. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14223. {
  14224. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14226. }
  14227. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14228. {
  14229. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14231. }
  14232. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14233. {
  14234. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14236. }
  14237. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14238. {
  14239. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14241. }
  14242. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14243. {
  14244. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14246. }
  14247. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14248. {
  14249. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14251. }
  14252. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14253. {
  14254. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14256. }
  14257. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14258. {
  14259. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14261. }
  14262. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14263. {
  14264. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14266. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14267. }
  14268. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14269. {
  14270. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14272. }
  14273. if(strcmp(keystr, "ResetRetries") == 0)
  14274. {
  14275. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14277. }
  14278. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14279. {
  14280. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14282. }
  14283. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14284. {
  14285. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14287. }
  14288. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14289. {
  14290. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14292. }
  14293. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14294. {
  14295. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14297. }
  14298. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14299. {
  14300. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14302. }
  14303. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14304. {
  14305. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14307. }
  14308. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14309. {
  14310. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14312. }
  14313. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14314. {
  14315. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14317. }
  14318. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14319. {
  14320. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14322. }
  14323. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14324. {
  14325. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14327. }
  14328. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14329. {
  14330. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14332. TransactionMessageAttemptsValue = atoi(valuestr);
  14333. }
  14334. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14335. {
  14336. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14338. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14339. }
  14340. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14341. {
  14342. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14344. }
  14345. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14346. {
  14347. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14349. }
  14350. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14351. {
  14352. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14354. }
  14355. if(strcmp(keystr, "AuthorizationKey") == 0)
  14356. {
  14357. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14358. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14360. }
  14361. if(strcmp(keystr, "SecurityProfile") == 0)
  14362. {
  14363. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14365. }
  14366. if(strcmp(keystr, "DefaultPrice") == 0)
  14367. {
  14368. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14370. }
  14371. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14372. {
  14373. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14375. }
  14376. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14377. {
  14378. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14380. }
  14381. if(strcmp(keystr, "TimeOffset") == 0)
  14382. {
  14383. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14385. }
  14386. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14387. {
  14388. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14390. }
  14391. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14392. {
  14393. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14395. }
  14396. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14397. {
  14398. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14400. }
  14401. if(strcmp(keystr, "FreeVend") == 0)
  14402. {
  14403. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14405. }
  14406. if(strcmp(keystr, "OcppServer") == 0)
  14407. {
  14408. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14409. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14410. }
  14411. if(strcmp(keystr, "MaintainServer") == 0)
  14412. {
  14413. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14414. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14415. }
  14416. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14417. {
  14418. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14420. }
  14421. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14422. {
  14423. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14425. }
  14426. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14427. {
  14428. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14430. }
  14431. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14432. {
  14433. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14435. }
  14436. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14437. {
  14438. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14440. }
  14441. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14442. {
  14443. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14445. }
  14446. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14447. {
  14448. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14450. }
  14451. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14452. {
  14453. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14455. }
  14456. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14457. {
  14458. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14460. }
  14461. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14462. {
  14463. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14465. }
  14466. }
  14467. }
  14468. fclose(fp);
  14469. }
  14470. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14471. {
  14472. return PASS;
  14473. }
  14474. else
  14475. {
  14476. return FAIL;
  14477. }
  14478. }
  14479. void StoreConfigurationTable(void)
  14480. {
  14481. FILE *outfile;
  14482. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14483. if(outfile == NULL)
  14484. {
  14485. DEBUG_INFO("Error opening file");
  14486. return ;
  14487. }
  14488. /*Core Profile*/
  14489. //AllowOfflineTxForUnknownId
  14490. /*
  14491. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14492. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14495. */
  14496. //DEBUG_INFO("data=%s\n",data);
  14497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14498. //AuthorizationCacheEnabled
  14499. /*
  14500. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14503. */
  14504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14505. //AuthorizeRemoteTxRequests
  14506. /*
  14507. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14510. */
  14511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14512. //BlinkRepeat
  14513. /*
  14514. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14517. */
  14518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14519. //ClockAlignedDataInterval
  14520. /*
  14521. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14524. */
  14525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14526. //ConnectionTimeOut
  14527. /*
  14528. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14531. */
  14532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14533. //GetConfigurationMaxKeys
  14534. /*
  14535. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14538. */
  14539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14540. // HeartbeatInterval
  14541. /*
  14542. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14545. */
  14546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14547. // LightIntensity
  14548. /*
  14549. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14552. */
  14553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14554. // LocalAuthorizeOffline
  14555. /*
  14556. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14559. */
  14560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14561. // LocalPreAuthorize
  14562. /*
  14563. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14566. */
  14567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14568. // MaxEnergyOnInvalidId
  14569. /*
  14570. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14573. */
  14574. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14576. // MeterValuesAlignedData
  14577. /*
  14578. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14581. */
  14582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14583. // MeterValuesAlignedDataMaxLength
  14584. /*
  14585. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14588. */
  14589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14590. // MeterValuesSampledData
  14591. /*
  14592. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14595. */
  14596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14597. // MeterValuesSampledDataMaxLength
  14598. /*
  14599. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14602. */
  14603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14604. // MeterValueSampleInterval
  14605. /*
  14606. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14609. */
  14610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14611. // MinimumStatusDuration
  14612. /*
  14613. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14616. */
  14617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14618. // NumberOfConnectors
  14619. /*
  14620. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14623. {
  14624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14625. }
  14626. else
  14627. {
  14628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14629. }
  14630. */
  14631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14632. // ResetRetries
  14633. /*
  14634. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14637. */
  14638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14639. // ConnectorPhaseRotation
  14640. /*
  14641. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14644. */
  14645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14646. // ConnectorPhaseRotationMaxLength
  14647. /*
  14648. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14651. */
  14652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14653. // StopTransactionOnEVSideDisconnect
  14654. /*
  14655. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14658. */
  14659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14660. // StopTransactionOnInvalidId
  14661. /*
  14662. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14665. */
  14666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14667. // StopTxnAlignedData
  14668. /*
  14669. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14672. */
  14673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14674. // StopTxnAlignedDataMaxLength
  14675. /*
  14676. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14679. */
  14680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14681. // StopTxnSampledData
  14682. /*
  14683. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14686. */
  14687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14688. // StopTxnSampledDataMaxLength
  14689. /*
  14690. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14693. */
  14694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14695. // SupportedFeatureProfiles
  14696. /*
  14697. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14700. */
  14701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14702. // SupportedFeatureProfilesMaxLength
  14703. /*
  14704. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14707. */
  14708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14709. // TransactionMessageAttempts
  14710. /*
  14711. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14714. */
  14715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14716. // TransactionMessageRetryInterval
  14717. /*
  14718. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14721. */
  14722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14723. // UnlockConnectorOnEVSideDisconnect
  14724. /*
  14725. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14728. */
  14729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14730. // WebSocketPingInterval
  14731. /*
  14732. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14735. */
  14736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14737. // QueueOffLineMeterValues
  14738. /*
  14739. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14742. */
  14743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14744. // AuthorizationKey
  14745. /*
  14746. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14749. */
  14750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14751. // SecurityProfile
  14752. /*
  14753. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14756. */
  14757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14758. // DefaultPrice
  14759. /*
  14760. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14763. */
  14764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14765. // CustomDisplayCostAndPrice
  14766. /*
  14767. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14770. */
  14771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14772. // CustomIdleFeeAfterStop
  14773. /*
  14774. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14777. */
  14778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14779. // TimeOffset
  14780. /*
  14781. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14784. */
  14785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14786. // NextTimeOffsetTransitionDateTime
  14787. /*
  14788. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14791. */
  14792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14793. // TimeOffsetNextTransition
  14794. /*
  14795. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14798. */
  14799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14800. // SystemUptimeSec
  14801. /*
  14802. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14805. */
  14806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14807. // FreeVend
  14808. /*
  14809. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14812. */
  14813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14814. // OcppServer
  14815. /*
  14816. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14819. */
  14820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14821. // MaintainServer
  14822. /*
  14823. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14826. */
  14827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14828. // ConfigurationVersion
  14829. /*
  14830. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14833. */
  14834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14835. //* Local Auth List Management Profile*/
  14836. //LocalAuthListEnabled
  14837. /*
  14838. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14841. */
  14842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14843. //LocalAuthListMaxLength
  14844. /*
  14845. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14848. */
  14849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14850. //SendLocalListMaxLength
  14851. /*
  14852. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14855. */
  14856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14857. //ReserveConnectorZeroSupported
  14858. /*
  14859. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14862. */
  14863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14864. //* Smart Charging Profile */
  14865. //ChargeProfileMaxStackLevel
  14866. /*
  14867. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14870. */
  14871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14872. // ChargingScheduleAllowedChargingRateUnit
  14873. /*
  14874. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14877. */
  14878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14879. // ChargingScheduleMaxPeriods
  14880. /*
  14881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14884. */
  14885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14886. // ConnectorSwitch3to1PhaseSupported
  14887. /*
  14888. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14891. */
  14892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14893. // MaxChargingProfilesInstalled
  14894. /*
  14895. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14898. */
  14899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14900. fclose(outfile);
  14901. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14902. }
  14903. void getKeyValue(char *keyReq)
  14904. {
  14905. int isEmpty = FALSE;
  14906. int isKnowKey = FALSE;
  14907. DEBUG_INFO("keyReq = %s\n", keyReq);
  14908. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14909. isEmpty = TRUE;
  14910. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14911. {
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14915. {
  14916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14917. }
  14918. else
  14919. {
  14920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14921. }
  14922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14923. isKnowKey = TRUE;
  14924. }
  14925. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14926. {
  14927. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14929. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14930. {
  14931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14932. }
  14933. else
  14934. {
  14935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14936. }
  14937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14938. isKnowKey = TRUE;
  14939. }
  14940. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14941. {
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14945. {
  14946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14947. }
  14948. else
  14949. {
  14950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14951. }
  14952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14953. isKnowKey = TRUE;
  14954. }
  14955. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14956. {
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14960. {
  14961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14962. }
  14963. else
  14964. {
  14965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14966. }
  14967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14968. isKnowKey = TRUE;
  14969. }
  14970. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14971. {
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14974. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14975. {
  14976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14977. }
  14978. else
  14979. {
  14980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14981. }
  14982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14983. isKnowKey = TRUE;
  14984. }
  14985. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14986. {
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14990. {
  14991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14992. }
  14993. else
  14994. {
  14995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14996. }
  14997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14998. isKnowKey = TRUE;
  14999. }
  15000. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15001. {
  15002. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15005. {
  15006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15007. }
  15008. else
  15009. {
  15010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15011. }
  15012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15013. isKnowKey = TRUE;
  15014. }
  15015. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15016. {
  15017. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15020. {
  15021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15022. }
  15023. else
  15024. {
  15025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15026. }
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15028. isKnowKey = TRUE;
  15029. }
  15030. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15031. {
  15032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15035. {
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15037. }
  15038. else
  15039. {
  15040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15041. }
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15043. isKnowKey = TRUE;
  15044. }
  15045. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15046. {
  15047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15050. {
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15052. }
  15053. else
  15054. {
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15056. }
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15058. isKnowKey = TRUE;
  15059. }
  15060. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15061. {
  15062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15065. {
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15067. }
  15068. else
  15069. {
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15071. }
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15073. isKnowKey = TRUE;
  15074. }
  15075. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15076. {
  15077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15080. {
  15081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15082. }
  15083. else
  15084. {
  15085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15086. }
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15088. isKnowKey = TRUE;
  15089. }
  15090. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15091. {
  15092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15095. {
  15096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15097. }
  15098. else
  15099. {
  15100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15101. }
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15103. isKnowKey = TRUE;
  15104. }
  15105. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15106. {
  15107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15110. {
  15111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15112. }
  15113. else
  15114. {
  15115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15116. }
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15118. isKnowKey = TRUE;
  15119. }
  15120. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15121. {
  15122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15125. {
  15126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15127. }
  15128. else
  15129. {
  15130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15131. }
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15133. isKnowKey = TRUE;
  15134. }
  15135. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15136. {
  15137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15140. {
  15141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15142. }
  15143. else
  15144. {
  15145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15146. }
  15147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15148. isKnowKey = TRUE;
  15149. }
  15150. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15151. {
  15152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15155. {
  15156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15157. }
  15158. else
  15159. {
  15160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15161. }
  15162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15163. isKnowKey = TRUE;
  15164. }
  15165. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15166. {
  15167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15170. {
  15171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15172. }
  15173. else
  15174. {
  15175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15176. }
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15178. isKnowKey = TRUE;
  15179. }
  15180. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15181. {
  15182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15185. {
  15186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15187. }
  15188. else
  15189. {
  15190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15191. }
  15192. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15194. isKnowKey = TRUE;
  15195. }
  15196. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15197. {
  15198. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15201. {
  15202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15203. }
  15204. else
  15205. {
  15206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15207. }
  15208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15209. isKnowKey = TRUE;
  15210. }
  15211. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15212. {
  15213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15216. {
  15217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15218. }
  15219. else
  15220. {
  15221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15222. }
  15223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15224. isKnowKey = TRUE;
  15225. }
  15226. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15227. {
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15231. {
  15232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15233. }
  15234. else
  15235. {
  15236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15237. }
  15238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15239. isKnowKey = TRUE;
  15240. }
  15241. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15242. {
  15243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15246. {
  15247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15248. }
  15249. else
  15250. {
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15252. }
  15253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15254. isKnowKey = TRUE;
  15255. }
  15256. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15257. {
  15258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15261. {
  15262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15263. }
  15264. else
  15265. {
  15266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15267. }
  15268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15269. isKnowKey = TRUE;
  15270. }
  15271. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15272. {
  15273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15276. {
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15278. }
  15279. else
  15280. {
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15282. }
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15284. isKnowKey = TRUE;
  15285. }
  15286. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15287. {
  15288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15291. {
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15293. }
  15294. else
  15295. {
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15297. }
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15299. isKnowKey = TRUE;
  15300. }
  15301. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15302. {
  15303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15306. {
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15308. }
  15309. else
  15310. {
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15312. }
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15314. isKnowKey = TRUE;
  15315. }
  15316. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15317. {
  15318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15321. {
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15323. }
  15324. else
  15325. {
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15327. }
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15329. isKnowKey = TRUE;
  15330. }
  15331. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15332. {
  15333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15336. {
  15337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15338. }
  15339. else
  15340. {
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15342. }
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15344. isKnowKey = TRUE;
  15345. }
  15346. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15347. {
  15348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15351. {
  15352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15353. }
  15354. else
  15355. {
  15356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15357. }
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15359. isKnowKey = TRUE;
  15360. }
  15361. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15362. {
  15363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15366. {
  15367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15368. }
  15369. else
  15370. {
  15371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15372. }
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15374. isKnowKey = TRUE;
  15375. }
  15376. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15377. {
  15378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15381. {
  15382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15383. }
  15384. else
  15385. {
  15386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15387. }
  15388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15389. isKnowKey = TRUE;
  15390. }
  15391. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15392. {
  15393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15396. {
  15397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15398. }
  15399. else
  15400. {
  15401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15402. }
  15403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15404. isKnowKey = TRUE;
  15405. }
  15406. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15407. {
  15408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15411. {
  15412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15413. }
  15414. else
  15415. {
  15416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15417. }
  15418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15419. isKnowKey = TRUE;
  15420. }
  15421. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15422. {
  15423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15426. {
  15427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15428. }
  15429. else
  15430. {
  15431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15432. }
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15434. isKnowKey = TRUE;
  15435. }
  15436. /*
  15437. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15438. {
  15439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15442. {
  15443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15444. }
  15445. else
  15446. {
  15447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15448. }
  15449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15450. isKnowKey = TRUE;
  15451. }*/
  15452. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15453. {
  15454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15457. {
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15459. }
  15460. else
  15461. {
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15463. }
  15464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15465. isKnowKey = TRUE;
  15466. }
  15467. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15468. {
  15469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15472. {
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15474. }
  15475. else
  15476. {
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15478. }
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15480. isKnowKey = TRUE;
  15481. }
  15482. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15483. {
  15484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15487. {
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15489. }
  15490. else
  15491. {
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15493. }
  15494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15495. isKnowKey = TRUE;
  15496. }
  15497. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15498. {
  15499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15502. {
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15504. }
  15505. else
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15508. }
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15510. isKnowKey = TRUE;
  15511. }
  15512. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15513. {
  15514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15517. {
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15519. }
  15520. else
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15523. }
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15525. isKnowKey = TRUE;
  15526. }
  15527. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15528. {
  15529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15532. {
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15534. }
  15535. else
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15538. }
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15540. isKnowKey = TRUE;
  15541. }
  15542. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15543. {
  15544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15549. }
  15550. else
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15553. }
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15555. isKnowKey = TRUE;
  15556. }
  15557. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15558. {
  15559. struct sysinfo s_info;
  15560. int error = sysinfo(&s_info);
  15561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15564. {
  15565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15566. }
  15567. else
  15568. {
  15569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15570. }
  15571. if(error != 0)
  15572. {
  15573. DEBUG_WARN("System uptime get error: %d\n", error);
  15574. }
  15575. else
  15576. {
  15577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15578. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15579. }
  15580. isKnowKey = TRUE;
  15581. }
  15582. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15583. {
  15584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15587. {
  15588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15589. }
  15590. else
  15591. {
  15592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15593. }
  15594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15595. isKnowKey = TRUE;
  15596. }
  15597. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15598. {
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15602. {
  15603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15604. }
  15605. else
  15606. {
  15607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15608. }
  15609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15610. isKnowKey = TRUE;
  15611. }
  15612. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15613. {
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15617. {
  15618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15619. }
  15620. else
  15621. {
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15623. }
  15624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15625. isKnowKey = TRUE;
  15626. }
  15627. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15628. {
  15629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15632. {
  15633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15634. }
  15635. else
  15636. {
  15637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15638. }
  15639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15640. isKnowKey = TRUE;
  15641. }
  15642. #if 1
  15643. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15644. {
  15645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15647. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15648. {
  15649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15650. }
  15651. else
  15652. {
  15653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15654. }
  15655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15656. isKnowKey = TRUE;
  15657. }
  15658. #endif
  15659. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15660. {
  15661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15663. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15664. {
  15665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15666. }
  15667. else
  15668. {
  15669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15670. }
  15671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15672. isKnowKey = TRUE;
  15673. }
  15674. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15675. {
  15676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15678. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15679. {
  15680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15681. }
  15682. else
  15683. {
  15684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15685. }
  15686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15687. isKnowKey = TRUE;
  15688. }
  15689. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15690. {
  15691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15693. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15694. {
  15695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15696. }
  15697. else
  15698. {
  15699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15700. }
  15701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15702. isKnowKey = TRUE;
  15703. }
  15704. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15705. {
  15706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15708. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15709. {
  15710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15711. }
  15712. else
  15713. {
  15714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15715. }
  15716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15717. isKnowKey = TRUE;
  15718. }
  15719. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15720. {
  15721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15723. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15724. {
  15725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15726. }
  15727. else
  15728. {
  15729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15730. }
  15731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15732. isKnowKey = TRUE;
  15733. }
  15734. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15735. {
  15736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15738. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15739. {
  15740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15741. }
  15742. else
  15743. {
  15744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15745. }
  15746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15747. isKnowKey = TRUE;
  15748. }
  15749. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15750. {
  15751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15753. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15754. {
  15755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15756. }
  15757. else
  15758. {
  15759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15760. }
  15761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15762. isKnowKey = TRUE;
  15763. }
  15764. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15765. {
  15766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15768. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15769. {
  15770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15771. }
  15772. else
  15773. {
  15774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15775. }
  15776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15777. isKnowKey = TRUE;
  15778. }
  15779. //=========================================================
  15780. if(!isEmpty && !isKnowKey)
  15781. {
  15782. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15783. strcpy(unknownkey[UnknownKeynum], keyReq);
  15784. UnknownKeynum = UnknownKeynum + 1;
  15785. }
  15786. }
  15787. void processUnkownKey(void)
  15788. {
  15789. DEBUG_INFO("processUnkownKey...\n");
  15790. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15791. for(int index=0; index < UnknownKeynum; index++)
  15792. {
  15793. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15794. {
  15795. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15796. }
  15797. }
  15798. }
  15799. int setKeyValue(char *key, char *value)
  15800. {
  15801. int isSuccess = NotSupported;
  15802. int check_ascii=0;
  15803. char str[501]={0};
  15804. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15805. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15806. {
  15807. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15809. {
  15810. strcpy(str, (const char*)value);
  15811. for(int i = 0; str[i]; i++){
  15812. str[i] = tolower(str[i]);
  15813. }
  15814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15815. isSuccess = ConfigurationStatus_Accepted;
  15816. }
  15817. else
  15818. {
  15819. isSuccess = ConfigurationStatus_Rejected;
  15820. }
  15821. }
  15822. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15823. {
  15824. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15826. {
  15827. strcpy(str, (const char*)value);
  15828. for(int i = 0; str[i]; i++){
  15829. str[i] = tolower(str[i]);
  15830. }
  15831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15832. isSuccess = ConfigurationStatus_Accepted;
  15833. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15834. }
  15835. else
  15836. {
  15837. isSuccess = ConfigurationStatus_Rejected;
  15838. }
  15839. }
  15840. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15841. {
  15842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15843. {
  15844. strcpy(str, (const char*)value);
  15845. for(int i = 0; str[i]; i++)
  15846. {
  15847. str[i] = tolower(str[i]);
  15848. }
  15849. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15851. isSuccess = ConfigurationStatus_Accepted;
  15852. }
  15853. else
  15854. {
  15855. isSuccess = ConfigurationStatus_Rejected;
  15856. }
  15857. }
  15858. if(strcmp(key, "BlinkRepeat") == 0)
  15859. {
  15860. //Charger.BlinkRepeat = Integer.parseInt(value);
  15861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15862. {
  15863. check_ascii = value[0];
  15864. if( (check_ascii < 48) || (check_ascii > 57) )
  15865. {
  15866. isSuccess = ConfigurationStatus_Rejected;
  15867. }
  15868. else
  15869. {
  15870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15871. isSuccess = ConfigurationStatus_Accepted;
  15872. }
  15873. }
  15874. else
  15875. {
  15876. isSuccess = ConfigurationStatus_Rejected;
  15877. }
  15878. }
  15879. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15880. {
  15881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15882. {
  15883. check_ascii = value[0];
  15884. if( (check_ascii < 48) || (check_ascii > 57) )
  15885. {
  15886. isSuccess = ConfigurationStatus_Rejected;
  15887. }
  15888. else
  15889. {
  15890. if((atoi(value) == 0) || (atoi(value) >= 5))
  15891. {
  15892. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15894. isSuccess = ConfigurationStatus_Accepted;
  15895. }
  15896. else
  15897. isSuccess = ConfigurationStatus_Rejected;
  15898. }
  15899. }
  15900. else
  15901. {
  15902. isSuccess = ConfigurationStatus_Rejected;
  15903. }
  15904. }
  15905. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15906. {
  15907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15908. {
  15909. check_ascii = value[0];
  15910. if( (check_ascii < 48) || (check_ascii > 57) )
  15911. {
  15912. isSuccess = ConfigurationStatus_Rejected;
  15913. }
  15914. else
  15915. {
  15916. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15918. isSuccess = ConfigurationStatus_Accepted;
  15919. }
  15920. }
  15921. else
  15922. {
  15923. isSuccess = ConfigurationStatus_Rejected;
  15924. }
  15925. }
  15926. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15927. {
  15928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15929. {
  15930. check_ascii = value[0];
  15931. if( (check_ascii < 48) || (check_ascii > 57) )
  15932. {
  15933. isSuccess = ConfigurationStatus_Rejected;
  15934. }
  15935. else
  15936. {
  15937. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15939. isSuccess = ConfigurationStatus_Accepted;
  15940. }
  15941. }
  15942. else
  15943. {
  15944. isSuccess = ConfigurationStatus_Rejected;
  15945. }
  15946. }
  15947. if(strcmp(key, "HeartbeatInterval") == 0)
  15948. {
  15949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15950. {
  15951. check_ascii = value[0];
  15952. if( (check_ascii < 48) || (check_ascii > 57) )
  15953. {
  15954. isSuccess = ConfigurationStatus_Rejected;
  15955. }
  15956. else
  15957. {
  15958. if((atoi(value) == 0) || (atoi(value) >= 10))
  15959. {
  15960. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15962. HeartBeatWaitTime = atoi(value);
  15963. isSuccess = ConfigurationStatus_Accepted;
  15964. }
  15965. else
  15966. {
  15967. isSuccess = ConfigurationStatus_Rejected;
  15968. }
  15969. }
  15970. }
  15971. else
  15972. {
  15973. isSuccess = ConfigurationStatus_Rejected;
  15974. }
  15975. }
  15976. if(strcmp(key, "LightIntensity") == 0)
  15977. {
  15978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15979. {
  15980. check_ascii = value[0];
  15981. if( (check_ascii < 48) || (check_ascii > 57) )
  15982. {
  15983. isSuccess = ConfigurationStatus_Rejected;
  15984. }
  15985. else
  15986. {
  15987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15988. isSuccess = ConfigurationStatus_Accepted;
  15989. }
  15990. }
  15991. else
  15992. {
  15993. isSuccess = ConfigurationStatus_Rejected;
  15994. }
  15995. }
  15996. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15997. {
  15998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15999. {
  16000. strcpy(str, (const char*)value);
  16001. for(int i = 0; str[i]; i++)
  16002. {
  16003. str[i] = tolower(str[i]);
  16004. }
  16005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16006. isSuccess = ConfigurationStatus_Accepted;
  16007. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16008. }
  16009. else
  16010. {
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. }
  16014. if(strcmp(key, "LocalPreAuthorize") == 0)
  16015. {
  16016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16017. {
  16018. strcpy(str, (const char*)value);
  16019. for(int i = 0; str[i]; i++)
  16020. {
  16021. str[i] = tolower(str[i]);
  16022. }
  16023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16024. isSuccess = ConfigurationStatus_Accepted;
  16025. }
  16026. else
  16027. {
  16028. isSuccess = ConfigurationStatus_Rejected;
  16029. }
  16030. }
  16031. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16032. {
  16033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16034. {
  16035. check_ascii = value[0];
  16036. if( (check_ascii < 48) || (check_ascii > 57) )
  16037. {
  16038. isSuccess = ConfigurationStatus_Rejected;
  16039. }
  16040. else
  16041. {
  16042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16043. isSuccess = ConfigurationStatus_Accepted;
  16044. }
  16045. }
  16046. else
  16047. {
  16048. isSuccess = ConfigurationStatus_Rejected;
  16049. }
  16050. }
  16051. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16052. {
  16053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16054. {
  16055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16056. isSuccess = ConfigurationStatus_Accepted;
  16057. }
  16058. else
  16059. {
  16060. isSuccess = ConfigurationStatus_Rejected;
  16061. }
  16062. }
  16063. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16064. {
  16065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16066. {
  16067. check_ascii = value[0];
  16068. if( (check_ascii < 48) || (check_ascii > 57) )
  16069. {
  16070. isSuccess = ConfigurationStatus_Rejected;
  16071. }
  16072. else
  16073. {
  16074. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16076. isSuccess = ConfigurationStatus_Accepted;
  16077. }
  16078. }
  16079. else
  16080. {
  16081. isSuccess = ConfigurationStatus_Rejected;
  16082. }
  16083. }
  16084. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16085. {
  16086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16087. {
  16088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16089. isSuccess = ConfigurationStatus_Accepted;
  16090. }
  16091. else
  16092. {
  16093. isSuccess = ConfigurationStatus_Rejected;
  16094. }
  16095. }
  16096. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16097. {
  16098. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16099. {
  16100. check_ascii = value[0];
  16101. if( (check_ascii < 48) || (check_ascii > 57) )
  16102. {
  16103. isSuccess = ConfigurationStatus_Rejected;
  16104. }
  16105. else
  16106. {
  16107. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16109. isSuccess = ConfigurationStatus_Accepted;
  16110. }
  16111. }
  16112. else
  16113. {
  16114. isSuccess = ConfigurationStatus_Rejected;
  16115. }
  16116. }
  16117. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16118. {
  16119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16120. {
  16121. check_ascii = value[0];
  16122. if( (check_ascii < 48) || (check_ascii > 57) )
  16123. {
  16124. isSuccess = ConfigurationStatus_Rejected;
  16125. }
  16126. else
  16127. {
  16128. if((atoi(value) == 0) || (atoi(value) >= 3))
  16129. {
  16130. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16132. isSuccess = ConfigurationStatus_Accepted;
  16133. }
  16134. else
  16135. {
  16136. isSuccess = ConfigurationStatus_Rejected;
  16137. }
  16138. }
  16139. }
  16140. else
  16141. {
  16142. isSuccess = ConfigurationStatus_Rejected;
  16143. }
  16144. }
  16145. if(strcmp(key, "MinimumStatusDuration") == 0)
  16146. {
  16147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16148. {
  16149. check_ascii = value[0];
  16150. if( (check_ascii < 48) || (check_ascii > 57) )
  16151. {
  16152. isSuccess = ConfigurationStatus_Rejected;
  16153. }
  16154. else
  16155. {
  16156. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16157. {
  16158. isSuccess = ConfigurationStatus_Rejected;
  16159. }
  16160. else
  16161. {
  16162. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16164. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16165. isSuccess = ConfigurationStatus_Accepted;
  16166. }
  16167. }
  16168. }
  16169. else
  16170. {
  16171. isSuccess = ConfigurationStatus_Rejected;
  16172. }
  16173. }
  16174. if(strcmp(key, "NumberOfConnectors") == 0)
  16175. {
  16176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16177. {
  16178. check_ascii = value[0];
  16179. if( (check_ascii < 48) || (check_ascii > 57) )
  16180. {
  16181. isSuccess = ConfigurationStatus_Rejected;
  16182. }
  16183. else
  16184. {
  16185. //Charger.ResetRetries = Integer.parseInt(value);
  16186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16187. isSuccess = ConfigurationStatus_Accepted;
  16188. }
  16189. }
  16190. else
  16191. {
  16192. isSuccess = ConfigurationStatus_Rejected;
  16193. }
  16194. }
  16195. if(strcmp(key, "ResetRetries") == 0)
  16196. {
  16197. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16198. {
  16199. check_ascii = value[0];
  16200. if( (check_ascii < 48) || (check_ascii > 57) )
  16201. {
  16202. isSuccess = ConfigurationStatus_Rejected;
  16203. }
  16204. else
  16205. {
  16206. //Charger.ResetRetries = Integer.parseInt(value);
  16207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16208. isSuccess = ConfigurationStatus_Accepted;
  16209. }
  16210. }
  16211. else
  16212. {
  16213. isSuccess = ConfigurationStatus_Rejected;
  16214. }
  16215. }
  16216. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16217. {
  16218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16219. {
  16220. strcpy(str, (const char*)value);
  16221. for(int i = 0; str[i]; i++)
  16222. {
  16223. str[i] = tolower(str[i]);
  16224. }
  16225. if(strcmp(str, "notapplicable")== 0)
  16226. {
  16227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16228. isSuccess = ConfigurationStatus_Accepted;
  16229. }
  16230. else if(strcmp(str, "unknown")== 0)
  16231. {
  16232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16233. isSuccess = ConfigurationStatus_Accepted;
  16234. }
  16235. else if(strcmp(str, "rst")== 0)
  16236. {
  16237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16238. isSuccess = ConfigurationStatus_Accepted;
  16239. }
  16240. else if(strcmp(str, "rts")== 0)
  16241. {
  16242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16243. isSuccess = ConfigurationStatus_Accepted;
  16244. }
  16245. else if(strcmp(str, "srt")== 0)
  16246. {
  16247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16248. isSuccess = ConfigurationStatus_Accepted;
  16249. }
  16250. else if(strcmp(str, "str")== 0)
  16251. {
  16252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16253. isSuccess = ConfigurationStatus_Accepted;
  16254. }
  16255. else if(strcmp(str, "trs")== 0)
  16256. {
  16257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16258. isSuccess = ConfigurationStatus_Accepted;
  16259. }
  16260. else if(strcmp(str, "tsr")== 0)
  16261. {
  16262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16263. isSuccess = ConfigurationStatus_Accepted;
  16264. }
  16265. else
  16266. {
  16267. isSuccess = ConfigurationStatus_Rejected;
  16268. }
  16269. }
  16270. else
  16271. {
  16272. isSuccess = ConfigurationStatus_Rejected;
  16273. }
  16274. }
  16275. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16276. {
  16277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16278. {
  16279. check_ascii = value[0];
  16280. if( (check_ascii < 48) || (check_ascii > 57) )
  16281. {
  16282. isSuccess = ConfigurationStatus_Rejected;
  16283. }
  16284. else
  16285. {
  16286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16287. isSuccess = ConfigurationStatus_Accepted;
  16288. }
  16289. }
  16290. else
  16291. {
  16292. isSuccess = ConfigurationStatus_Rejected;
  16293. }
  16294. }
  16295. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16296. {
  16297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16298. {
  16299. strcpy(str, (const char*)value);
  16300. for(int i = 0; str[i]; i++)
  16301. {
  16302. str[i] = tolower(str[i]);
  16303. }
  16304. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16306. isSuccess = ConfigurationStatus_Accepted;
  16307. }
  16308. else
  16309. {
  16310. isSuccess = ConfigurationStatus_Rejected;
  16311. }
  16312. }
  16313. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16314. {
  16315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16316. {
  16317. strcpy(str, (const char*)value);
  16318. for(int i = 0; str[i]; i++)
  16319. {
  16320. str[i] = tolower(str[i]);
  16321. }
  16322. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16324. isSuccess = ConfigurationStatus_Accepted;
  16325. }
  16326. else
  16327. {
  16328. isSuccess = ConfigurationStatus_Rejected;
  16329. }
  16330. }
  16331. if(strcmp(key, "StopTxnAlignedData") == 0)
  16332. {
  16333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16334. {
  16335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16336. isSuccess = ConfigurationStatus_Accepted;
  16337. }
  16338. else
  16339. {
  16340. isSuccess = ConfigurationStatus_Rejected;
  16341. }
  16342. }
  16343. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16344. {
  16345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16346. {
  16347. check_ascii = value[0];
  16348. if( (check_ascii < 48) || (check_ascii > 57) )
  16349. {
  16350. isSuccess = ConfigurationStatus_Rejected;
  16351. }
  16352. else
  16353. {
  16354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16355. isSuccess = ConfigurationStatus_Accepted;
  16356. }
  16357. }
  16358. else
  16359. {
  16360. isSuccess = ConfigurationStatus_Rejected;
  16361. }
  16362. }
  16363. if(strcmp(key, "StopTxnSampledData") == 0)
  16364. {
  16365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16366. {
  16367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16368. isSuccess = ConfigurationStatus_Accepted;
  16369. }
  16370. else
  16371. {
  16372. isSuccess = ConfigurationStatus_Rejected;
  16373. }
  16374. }
  16375. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16376. {
  16377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16378. {
  16379. check_ascii = value[0];
  16380. if( (check_ascii < 48) || (check_ascii > 57) )
  16381. {
  16382. isSuccess = ConfigurationStatus_Rejected;
  16383. }
  16384. else
  16385. {
  16386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16387. isSuccess = ConfigurationStatus_Accepted;
  16388. }
  16389. }
  16390. else
  16391. {
  16392. isSuccess = ConfigurationStatus_Rejected;
  16393. }
  16394. }
  16395. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16396. {
  16397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16398. {
  16399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16400. isSuccess = ConfigurationStatus_Accepted;
  16401. }
  16402. else
  16403. {
  16404. isSuccess = ConfigurationStatus_Rejected;
  16405. }
  16406. }
  16407. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16408. {
  16409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16410. {
  16411. check_ascii = value[0];
  16412. if( (check_ascii < 48) || (check_ascii > 57) )
  16413. {
  16414. isSuccess = ConfigurationStatus_Rejected;
  16415. }
  16416. else
  16417. {
  16418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16419. isSuccess = ConfigurationStatus_Accepted;
  16420. }
  16421. }
  16422. else
  16423. {
  16424. isSuccess = ConfigurationStatus_Rejected;
  16425. }
  16426. }
  16427. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16428. {
  16429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16430. {
  16431. check_ascii = value[0];
  16432. if( (check_ascii < 48) || (check_ascii > 57) )
  16433. {
  16434. isSuccess = ConfigurationStatus_Rejected;
  16435. }
  16436. else
  16437. {
  16438. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16440. TransactionMessageAttemptsValue = atoi(value);
  16441. isSuccess = ConfigurationStatus_Accepted;
  16442. }
  16443. }
  16444. else
  16445. {
  16446. isSuccess = ConfigurationStatus_Rejected;
  16447. }
  16448. }
  16449. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16450. {
  16451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16452. {
  16453. check_ascii = value[0];
  16454. if( (check_ascii < 48) || (check_ascii > 57) )
  16455. {
  16456. isSuccess = ConfigurationStatus_Rejected;
  16457. }
  16458. else
  16459. {
  16460. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16462. TransactionMessageRetryIntervalValue = atoi(value);
  16463. isSuccess = ConfigurationStatus_Accepted;
  16464. }
  16465. }
  16466. else
  16467. {
  16468. isSuccess = ConfigurationStatus_Rejected;
  16469. }
  16470. }
  16471. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16472. {
  16473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16474. {
  16475. strcpy(str, (const char*)value);
  16476. for(int i = 0; str[i]; i++)
  16477. {
  16478. str[i] = tolower(str[i]);
  16479. }
  16480. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16482. isSuccess = ConfigurationStatus_Accepted;
  16483. }
  16484. else
  16485. {
  16486. isSuccess = ConfigurationStatus_Rejected;
  16487. }
  16488. }
  16489. if(strcmp(key, "WebSocketPingInterval") == 0)
  16490. {
  16491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16492. {
  16493. check_ascii = value[0];
  16494. if( (check_ascii < 48) || (check_ascii > 57) )
  16495. {
  16496. isSuccess = ConfigurationStatus_Rejected;
  16497. }
  16498. else
  16499. {
  16500. if((atoi(value) == 0) || (atoi(value) >= 10))
  16501. {
  16502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16503. isSuccess = ConfigurationStatus_Accepted;
  16504. }
  16505. else
  16506. isSuccess = ConfigurationStatus_Rejected;
  16507. }
  16508. }
  16509. else
  16510. {
  16511. isSuccess = ConfigurationStatus_Rejected;
  16512. }
  16513. }
  16514. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16515. {
  16516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16517. {
  16518. strcpy(str, (const char*)value);
  16519. for(int i = 0; str[i]; i++)
  16520. {
  16521. str[i] = tolower(str[i]);
  16522. }
  16523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16524. isSuccess = ConfigurationStatus_Accepted;
  16525. }
  16526. else
  16527. {
  16528. isSuccess = ConfigurationStatus_Rejected;
  16529. }
  16530. }
  16531. if(strcmp(key, "AuthorizationKey") == 0)
  16532. {
  16533. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16534. {
  16535. strcpy(str, (const char*)value);
  16536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16537. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16538. isSuccess = ConfigurationStatus_Accepted;
  16539. }
  16540. else
  16541. {
  16542. isSuccess = ConfigurationStatus_Rejected;
  16543. }
  16544. }
  16545. if(strcmp(key, "SecurityProfile") == 0)
  16546. {
  16547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16548. {
  16549. check_ascii = value[0];
  16550. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16551. {
  16552. isSuccess = ConfigurationStatus_Rejected;
  16553. }
  16554. else if(check_ascii == 0x33)
  16555. {
  16556. isSuccess = NotSupported;
  16557. }
  16558. else
  16559. {
  16560. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16561. {
  16562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16563. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16564. isSuccess = ConfigurationStatus_Accepted;
  16565. }
  16566. else
  16567. isSuccess = ConfigurationStatus_Rejected;
  16568. }
  16569. }
  16570. else
  16571. {
  16572. isSuccess = ConfigurationStatus_Rejected;
  16573. }
  16574. }
  16575. if(strcmp(key, "DefaultPrice") == 0)
  16576. {
  16577. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16578. {
  16579. strcpy(str, (const char*)value);
  16580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16581. isSuccess = ConfigurationStatus_Accepted;
  16582. }
  16583. else
  16584. {
  16585. isSuccess = ConfigurationStatus_Rejected;
  16586. }
  16587. }
  16588. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16589. {
  16590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16591. {
  16592. strcpy(str, (const char*)value);
  16593. for(int i = 0; str[i]; i++)
  16594. {
  16595. str[i] = tolower(str[i]);
  16596. }
  16597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16598. isSuccess = ConfigurationStatus_Accepted;
  16599. }
  16600. else
  16601. {
  16602. isSuccess = ConfigurationStatus_Rejected;
  16603. }
  16604. }
  16605. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16606. {
  16607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16608. {
  16609. strcpy(str, (const char*)value);
  16610. for(int i = 0; str[i]; i++)
  16611. {
  16612. str[i] = tolower(str[i]);
  16613. }
  16614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16615. isSuccess = ConfigurationStatus_Accepted;
  16616. }
  16617. else
  16618. {
  16619. isSuccess = ConfigurationStatus_Rejected;
  16620. }
  16621. }
  16622. if(strcmp(key, "TimeOffset") == 0)
  16623. {
  16624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16625. {
  16626. strcpy(str, (const char*)value);
  16627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16628. isSuccess = ConfigurationStatus_Accepted;
  16629. }
  16630. else
  16631. {
  16632. isSuccess = ConfigurationStatus_Rejected;
  16633. }
  16634. }
  16635. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16636. {
  16637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16638. {
  16639. strcpy(str, (const char*)value);
  16640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16641. isSuccess = ConfigurationStatus_Accepted;
  16642. }
  16643. else
  16644. {
  16645. isSuccess = ConfigurationStatus_Rejected;
  16646. }
  16647. }
  16648. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16649. {
  16650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16651. {
  16652. strcpy(str, (const char*)value);
  16653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16654. isSuccess = ConfigurationStatus_Accepted;
  16655. }
  16656. else
  16657. {
  16658. isSuccess = ConfigurationStatus_Rejected;
  16659. }
  16660. }
  16661. if(strcmp(key, "SystemUptimeSec") == 0)
  16662. {
  16663. isSuccess = NotSupported;
  16664. }
  16665. if(strcmp(key, "FreeVend") == 0)
  16666. {
  16667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16668. {
  16669. strcpy(str, (const char*)value);
  16670. for(int i = 0; str[i]; i++)
  16671. {
  16672. str[i] = tolower(str[i]);
  16673. }
  16674. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16676. isSuccess = ConfigurationStatus_Accepted;
  16677. }
  16678. else
  16679. {
  16680. isSuccess = ConfigurationStatus_Rejected;
  16681. }
  16682. }
  16683. if(strcmp(key, "OcppServer") == 0)
  16684. {
  16685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16686. {
  16687. strcpy(str, (const char*)value);
  16688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16689. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16690. isSuccess = ConfigurationStatus_Accepted;
  16691. }
  16692. else
  16693. {
  16694. isSuccess = ConfigurationStatus_Rejected;
  16695. }
  16696. }
  16697. if(strcmp(key, "MaintainServer") == 0)
  16698. {
  16699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16700. {
  16701. strcpy(str, (const char*)value);
  16702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16703. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16704. isSuccess = ConfigurationStatus_Accepted;
  16705. }
  16706. else
  16707. {
  16708. isSuccess = ConfigurationStatus_Rejected;
  16709. }
  16710. }
  16711. #if 0
  16712. //For OCPP Test Case
  16713. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16714. {
  16715. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16716. {
  16717. strcpy(str, (const char*)value);
  16718. for(int i = 0; str[i]; i++)
  16719. {
  16720. str[i] = tolower(str[i]);
  16721. }
  16722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16723. isSuccess = ConfigurationStatus_Accepted;
  16724. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16725. }
  16726. else
  16727. {
  16728. isSuccess = ConfigurationStatus_Rejected;
  16729. }
  16730. }
  16731. #endif
  16732. #if 1
  16733. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16734. {
  16735. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16736. {
  16737. strcpy(str, (const char*)value);
  16738. for(int i = 0; str[i]; i++)
  16739. {
  16740. str[i] = tolower(str[i]);
  16741. }
  16742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16743. isSuccess = ConfigurationStatus_Accepted;
  16744. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16745. }
  16746. else
  16747. {
  16748. isSuccess = ConfigurationStatus_Rejected;
  16749. }
  16750. }
  16751. #endif
  16752. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16753. {
  16754. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16755. {
  16756. check_ascii = value[0];
  16757. if( (check_ascii < 48) || (check_ascii > 57) )
  16758. {
  16759. isSuccess = ConfigurationStatus_Rejected;
  16760. }
  16761. else
  16762. {
  16763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16764. isSuccess = ConfigurationStatus_Accepted;
  16765. }
  16766. }
  16767. else
  16768. {
  16769. isSuccess = ConfigurationStatus_Rejected;
  16770. }
  16771. }
  16772. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16773. {
  16774. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16775. {
  16776. check_ascii = value[0];
  16777. if( (check_ascii < 48) || (check_ascii > 57) )
  16778. {
  16779. isSuccess = ConfigurationStatus_Rejected;
  16780. }
  16781. else
  16782. {
  16783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16784. isSuccess = ConfigurationStatus_Accepted;
  16785. }
  16786. }
  16787. else
  16788. {
  16789. isSuccess = ConfigurationStatus_Rejected;
  16790. }
  16791. }
  16792. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16793. {
  16794. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16795. {
  16796. strcpy(str, (const char*)value);
  16797. for(int i = 0; str[i]; i++)
  16798. {
  16799. str[i] = tolower(str[i]);
  16800. }
  16801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16802. isSuccess = ConfigurationStatus_Accepted;
  16803. }
  16804. else
  16805. {
  16806. isSuccess = ConfigurationStatus_Rejected;
  16807. }
  16808. }
  16809. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16810. {
  16811. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16812. {
  16813. check_ascii = value[0];
  16814. if( (check_ascii < 48) || (check_ascii > 57) )
  16815. {
  16816. isSuccess = ConfigurationStatus_Rejected;
  16817. }
  16818. else
  16819. {
  16820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16821. isSuccess = ConfigurationStatus_Accepted;
  16822. }
  16823. }
  16824. else
  16825. {
  16826. isSuccess = ConfigurationStatus_Rejected;
  16827. }
  16828. }
  16829. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16830. {
  16831. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16832. {
  16833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16834. isSuccess = ConfigurationStatus_Accepted;
  16835. }
  16836. else
  16837. {
  16838. isSuccess = ConfigurationStatus_Rejected;
  16839. }
  16840. }
  16841. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16842. {
  16843. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16844. {
  16845. check_ascii = value[0];
  16846. if( (check_ascii < 48) || (check_ascii > 57) )
  16847. {
  16848. isSuccess = ConfigurationStatus_Rejected;
  16849. }
  16850. else
  16851. {
  16852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16853. isSuccess = ConfigurationStatus_Accepted;
  16854. }
  16855. }
  16856. else
  16857. {
  16858. isSuccess = ConfigurationStatus_Rejected;
  16859. }
  16860. }
  16861. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16862. {
  16863. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16864. {
  16865. strcpy(str, (const char*)value);
  16866. for(int i = 0; str[i]; i++)
  16867. {
  16868. str[i] = tolower(str[i]);
  16869. }
  16870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16871. isSuccess = ConfigurationStatus_Accepted;
  16872. }
  16873. else
  16874. {
  16875. isSuccess = ConfigurationStatus_Rejected;
  16876. }
  16877. }
  16878. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16879. {
  16880. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16881. {
  16882. check_ascii = value[0];
  16883. if( (check_ascii < 48) || (check_ascii > 57) )
  16884. {
  16885. isSuccess = ConfigurationStatus_Rejected;
  16886. }
  16887. else
  16888. {
  16889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16890. isSuccess = ConfigurationStatus_Accepted;
  16891. }
  16892. }
  16893. else
  16894. {
  16895. isSuccess = ConfigurationStatus_Rejected;
  16896. }
  16897. }
  16898. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16899. return isSuccess;
  16900. }
  16901. int TransactionMessageAttemptsGet(void)
  16902. {
  16903. return TransactionMessageAttemptsValue;
  16904. }
  16905. int FirstHeartBeatResponse(void)
  16906. {
  16907. return FirstHeartBeat;
  16908. }
  16909. int TransactionMessageRetryIntervalGet(void)
  16910. {
  16911. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16912. }
  16913. int ReadHttpStatus(int sock)
  16914. {
  16915. //char c;
  16916. char buff[1024]="",*ptr=buff+1;
  16917. int bytes_received, status;
  16918. DEBUG_INFO("Begin Response ..\n");
  16919. while((bytes_received = recv(sock, ptr, 1, 0))){
  16920. if(bytes_received==-1){
  16921. perror("ReadHttpStatus");
  16922. exit(1);
  16923. }
  16924. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16925. ptr++;
  16926. }
  16927. *ptr=0;
  16928. ptr=buff+1;
  16929. sscanf(ptr,"%*s %d ", &status);
  16930. DEBUG_INFO("%s\n",ptr);
  16931. DEBUG_INFO("status=%d\n",status);
  16932. DEBUG_INFO("End Response ..\n");
  16933. return (bytes_received>0)?status:0;
  16934. }
  16935. //the only filed that it parsed is 'Content-Length'
  16936. int ParseHeader(int sock)
  16937. {
  16938. //char c;
  16939. char buff[1024]="",*ptr=buff+4;
  16940. int bytes_received;
  16941. DEBUG_INFO("Begin HEADER ..\n");
  16942. while((bytes_received = recv(sock, ptr, 1, 0))){
  16943. if(bytes_received==-1){
  16944. perror("Parse Header");
  16945. exit(1);
  16946. }
  16947. if(
  16948. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16949. (ptr[-1]=='\r') && (*ptr=='\n' )
  16950. ) break;
  16951. ptr++;
  16952. }
  16953. *ptr=0;
  16954. ptr=buff+4;
  16955. //printf("%s",ptr);
  16956. if(bytes_received){
  16957. ptr=strstr(ptr,"Content-Length:");
  16958. if(ptr){
  16959. sscanf(ptr,"%*s %d",&bytes_received);
  16960. }else
  16961. bytes_received=-1; //unknown size
  16962. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16963. }
  16964. DEBUG_INFO("End HEADER ..\n");
  16965. return bytes_received ;
  16966. }
  16967. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16968. {
  16969. int result = TRUE;
  16970. char rmFileCmd[100]={0};
  16971. char FilePath[100]={0};
  16972. char ftpbuf[200];
  16973. int systemresult;
  16974. sprintf(FilePath,"/mnt/%s",filename);
  16975. system("ping 8.8.8.8 &");
  16976. if((access(FilePath,F_OK))!=-1)
  16977. {
  16978. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16979. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16980. system(rmFileCmd);
  16981. }
  16982. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16983. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16984. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16985. systemresult = system(ftpbuf);
  16986. if(systemresult != 0)
  16987. {
  16988. DEBUG_INFO("http DownLoad error!\n");
  16989. result = FALSE;
  16990. }
  16991. system("pkill ping");
  16992. return result;
  16993. }
  16994. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16995. {
  16996. int result = TRUE;
  16997. char rmFileCmd[100]={0};
  16998. char FilePath[100]={0};
  16999. char ftpbuf[200];
  17000. int systemresult;
  17001. sprintf(FilePath,"/mnt/%s",filename);
  17002. system("ping 8.8.8.8 &");
  17003. if((access(FilePath,F_OK))!=-1)
  17004. {
  17005. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17006. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17007. system(rmFileCmd);
  17008. }
  17009. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17010. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17011. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17012. systemresult = system(ftpbuf);
  17013. if(systemresult != 0)
  17014. {
  17015. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17016. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17017. systemresult = system(ftpbuf);
  17018. if(systemresult != 0)
  17019. {
  17020. DEBUG_WARN("wget error!\n");
  17021. result = FALSE;
  17022. }
  17023. }
  17024. system("pkill ping");
  17025. return result;
  17026. }
  17027. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17028. {
  17029. char rmFileCmd[100]={0};
  17030. char FilePath[100]={0};
  17031. char buf[512];
  17032. int systemresult = 0;
  17033. //DEBUG_INFO("filename=%s\n",filename);
  17034. //DEBUG_INFO("url=%s\n",url);
  17035. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17036. if((access(FilePath,F_OK))!=-1)
  17037. {
  17038. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17039. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17040. system(rmFileCmd);
  17041. }
  17042. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17043. if(fp == NULL)
  17044. {
  17045. DEBUG_INFO("log is NULL\n");
  17046. return FALSE;
  17047. }
  17048. else
  17049. {
  17050. fprintf(fp, "%s\n", url);
  17051. fprintf(fp, "%s\n", filename);
  17052. fclose(fp);
  17053. }
  17054. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17055. if(phpFP == NULL)
  17056. {
  17057. DEBUG_INFO("PHP upload fail.\n");
  17058. return FALSE;
  17059. }
  17060. else
  17061. {
  17062. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17063. {
  17064. if(strstr(buf, "result") != NULL)
  17065. {
  17066. sscanf(buf, "result: %d", &systemresult);
  17067. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17068. }
  17069. }
  17070. pclose(phpFP);
  17071. }
  17072. if(systemresult != 1)
  17073. {
  17074. DEBUG_INFO("HTTP upload error!\n");
  17075. return FALSE;
  17076. }
  17077. return TRUE;
  17078. }
  17079. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17080. {
  17081. int result = FALSE;
  17082. char ftpbuf[200];
  17083. int systemresult;
  17084. /*
  17085. // Domaind name transfer to IP address
  17086. struct hostent* server;
  17087. char *IPbuffer;
  17088. server = gethostbyname(location);
  17089. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17090. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17091. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17092. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17093. systemresult = system(ftpbuf);
  17094. if(systemresult != 0)
  17095. {
  17096. DEBUG_INFO("ftpput error!\n");
  17097. }
  17098. else
  17099. {
  17100. result = TRUE;
  17101. DEBUG_INFO("ftpput OK!\n");
  17102. }
  17103. return result;
  17104. }
  17105. int GetOcppServerURL()
  17106. {
  17107. int result = FALSE;
  17108. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17109. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17110. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17111. struct yuarel url;
  17112. char urlStr[512];
  17113. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17114. {
  17115. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17116. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17117. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17118. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17119. if(yuarel_parse(&url, urlStr) != -1)
  17120. {
  17121. sprintf(OcppProtocol, "%s", url.scheme);
  17122. sprintf(OcppHost, "%s", url.host);
  17123. if(url.path == NULL)
  17124. OcppTempPath[0] = '\0';
  17125. else
  17126. {
  17127. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17128. {
  17129. sprintf(OcppTempPath, "%s/", url.path);
  17130. }
  17131. else
  17132. {
  17133. sprintf(OcppTempPath, "%s", url.path);
  17134. }
  17135. }
  17136. if(url.port == 0)
  17137. {
  17138. if(strcmp(OcppProtocol, "wss") == 0)
  17139. OcppPort = 443;
  17140. else
  17141. OcppPort = 80;
  17142. }
  17143. else
  17144. OcppPort = url.port;
  17145. result = TRUE;
  17146. }
  17147. }
  17148. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17149. {
  17150. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17151. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17152. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17153. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17154. if(yuarel_parse(&url, urlStr) != -1)
  17155. {
  17156. sprintf(OcppProtocol, "%s", url.scheme);
  17157. sprintf(OcppHost, "%s", url.host);
  17158. if(url.path == NULL)
  17159. OcppTempPath[0] = '\0';
  17160. else
  17161. sprintf(OcppTempPath, "%s", url.path);
  17162. if(url.port == 0)
  17163. {
  17164. if(strcmp(OcppProtocol, "wss") == 0)
  17165. OcppPort = 443;
  17166. else
  17167. OcppPort = 80;
  17168. }
  17169. else
  17170. OcppPort = url.port;
  17171. result = TRUE;
  17172. }
  17173. }
  17174. else
  17175. {
  17176. strcpy(OcppHost,"");
  17177. }
  17178. return result;
  17179. }
  17180. int GetOcppPath()
  17181. {
  17182. int result = FALSE;
  17183. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17184. {
  17185. if(OcppTempPath == NULL)
  17186. {
  17187. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17188. }
  17189. else
  17190. {
  17191. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17192. }
  17193. result = TRUE;
  17194. goto End;
  17195. }
  17196. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17197. {
  17198. if(OcppTempPath == NULL)
  17199. {
  17200. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17201. }
  17202. else
  17203. {
  17204. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17205. }
  17206. result = TRUE;
  17207. goto End;
  17208. }
  17209. else
  17210. {
  17211. strcpy(OcppPath,"");
  17212. }
  17213. End:
  17214. return result;
  17215. }
  17216. int GetOcppPort()
  17217. {
  17218. return OcppPort;
  17219. }
  17220. int GetOcppConnStatus(void)
  17221. {
  17222. return ShmOCPP16Data->OcppConnStatus;
  17223. }
  17224. void SetOcppConnStatus(uint8_t status)
  17225. {
  17226. ShmOCPP16Data->OcppConnStatus = status;
  17227. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17228. }
  17229. int GetHeartBeatWithNOResponse(void)
  17230. {
  17231. return HeartBeatWithNOResponse;
  17232. }
  17233. void SetHeartBeatWithNOResponse(void)
  17234. {
  17235. HeartBeatWithNOResponse = 0;
  17236. }
  17237. void GetStartTransactionIdTag(int gun_index)
  17238. {
  17239. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17240. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17241. }
  17242. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17243. {
  17244. char ch;
  17245. FILE *fptr1;
  17246. int temptransactionId;
  17247. char str[100]={0};
  17248. temptransactionId = 0;
  17249. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17250. {
  17251. DEBUG_INFO("IdTag is empty.\n");
  17252. return temptransactionId;
  17253. }
  17254. /*------ Read the file ----------------*/
  17255. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17256. if (!fptr1)
  17257. {
  17258. DEBUG_INFO("QueueTransactionId file open error.\n");
  17259. //printf(" File not found or unable to open the input file!!\n");
  17260. return temptransactionId;
  17261. }
  17262. ch=fgetc(fptr1);
  17263. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17264. rewind(fptr1);
  17265. if(ch!=EOF)
  17266. {
  17267. // printf("%c",ch);
  17268. while (fgets(str, 100, fptr1) != NULL)
  17269. {
  17270. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17271. if(str[0]=='\0')
  17272. {
  17273. break;
  17274. }
  17275. char *revbuf[8] = {0}; // Variable store string split
  17276. int num = 0;// Quantity after string split
  17277. DEBUG_INFO("Transaction queue data= %s\n", str);
  17278. splitstring(str,",",revbuf,&num); // String split
  17279. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17280. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17281. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17282. DEBUG_INFO("------------------------------\n");
  17283. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17284. {
  17285. if(isStopTransaction)
  17286. {
  17287. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17288. {
  17289. temptransactionId = atoi(revbuf[2]);
  17290. //break;
  17291. }
  17292. }
  17293. else
  17294. {
  17295. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17296. {
  17297. temptransactionId = atoi(revbuf[2]);
  17298. //break;
  17299. }
  17300. }
  17301. }
  17302. }
  17303. }
  17304. else
  17305. DEBUG_INFO("EOF\n");
  17306. fclose(fptr1);
  17307. /*------- End of reading ---------------*/
  17308. return temptransactionId;
  17309. }
  17310. void SetTransactionIdZero(int transactionId)
  17311. {
  17312. char ch;
  17313. FILE *fptr1, *fptr2;
  17314. int temptransactionId = 0;
  17315. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17316. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17317. if (!fptr1)
  17318. {
  17319. //printf(" File not found or unable to open the input file!!\n");
  17320. return ;
  17321. }
  17322. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17323. if (!fptr2)
  17324. {
  17325. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17326. fclose(fptr1);
  17327. return ;
  17328. }
  17329. ch=fgetc(fptr1);
  17330. rewind(fptr1);
  17331. if(ch!=EOF)
  17332. {
  17333. // copy all contents to the temporary file except the specific line
  17334. while (fgets(str, 100, fptr1) != NULL)
  17335. {
  17336. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17337. if(str[0]=='\0')
  17338. {
  17339. break;
  17340. }
  17341. char *revbuf[8] = {0};
  17342. int num = 0;
  17343. strcpy(strtemp, str);
  17344. splitstring(str,",",revbuf,&num);
  17345. if(revbuf[2][0] != '\0')
  17346. {
  17347. temptransactionId = atoi(revbuf[2]);
  17348. if(transactionId != temptransactionId)
  17349. {
  17350. fprintf(fptr2, "%s\n", strtemp);
  17351. }
  17352. }
  17353. }
  17354. }
  17355. fclose(fptr1);
  17356. fclose(fptr2);
  17357. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17358. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17359. /*------ Read the file ----------------*/
  17360. }
  17361. int InternetDisconnect(void)
  17362. {
  17363. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17364. }
  17365. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17366. void storeTempStopTransaction(int gun_index)
  17367. {
  17368. char guid[37]={0};
  17369. int tempIndex = 0;
  17370. char TempStopTransaction[256];
  17371. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17372. DEBUG_INFO("storeTempStopTransaction...\n");
  17373. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17374. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17375. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17376. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17378. {
  17379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17380. {
  17381. tempIndex = ((gun_index==2) ? 1: 0);
  17382. }
  17383. else
  17384. {
  17385. tempIndex = gun_index;
  17386. }
  17387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17388. {
  17389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17390. {
  17391. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17392. }
  17393. }// END OF CHAdeMO_QUANTITY
  17394. }
  17395. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17396. {
  17397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17398. {
  17399. tempIndex = ((gun_index==2) ? 1: 0);
  17400. }
  17401. else
  17402. {
  17403. tempIndex = gun_index;
  17404. }
  17405. for (int index = 0; index < CCS_QUANTITY; index++)
  17406. {
  17407. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17408. {
  17409. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17410. }
  17411. }// END OF CCS_QUANTITY
  17412. }
  17413. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17414. {
  17415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17416. {
  17417. tempIndex = ((gun_index==2) ? 1: 0);
  17418. }
  17419. else
  17420. {
  17421. tempIndex = gun_index;
  17422. }
  17423. for (int index = 0; index < GB_QUANTITY; index++)
  17424. {
  17425. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17426. {
  17427. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17428. }
  17429. }// END OF GB_QUANTITY
  17430. }
  17431. else if(gunType[gun_index] == GUN_TYPE_DO)
  17432. {
  17433. tempIndex = gun_index;
  17434. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17435. {
  17436. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17437. {
  17438. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17439. }
  17440. }
  17441. }
  17442. else
  17443. {
  17444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17445. {
  17446. tempIndex = 2;
  17447. }
  17448. else
  17449. {
  17450. tempIndex = gun_index;
  17451. }
  17452. for (int index = 0; index < AC_QUANTITY; index++)
  17453. {
  17454. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17455. {
  17456. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17457. }
  17458. }// END OF AC_QUANTITY
  17459. }
  17460. //Stop Transaction Time
  17461. struct timeval tmnow;
  17462. struct tm *tm;
  17463. char buf[28];//, usec_buf[6];
  17464. gettimeofday(&tmnow, NULL);
  17465. time_t t;
  17466. t = time(NULL);
  17467. /*UTC time and date*/
  17468. tm = gmtime(&t);
  17469. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17470. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17471. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17473. random_uuid(guid);
  17474. /***********************************transactionData******************************************************/
  17475. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17477. //=================================
  17478. //1. Transaction_Begin
  17479. //=================================
  17480. //============================== Energy.Active.Import.Interval ===========================================
  17481. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17482. {
  17483. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17486. 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*/]);
  17487. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17488. 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))
  17489. {
  17490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17491. }
  17492. else
  17493. {
  17494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17495. }
  17496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17498. }
  17499. //=================================
  17500. //2. Transaction_End
  17501. //=================================
  17502. //2.1====================================== Current.Import L1 ==============================================
  17503. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17504. {
  17505. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17506. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17507. {
  17508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17509. {
  17510. tempIndex = ((gun_index==2) ? 1: 0);
  17511. }
  17512. else
  17513. {
  17514. tempIndex = gun_index;
  17515. }
  17516. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17517. {
  17518. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17519. {
  17520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17521. }
  17522. }// End of for CHAdeMO_QUANTITY
  17523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17524. }
  17525. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17526. {
  17527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17528. {
  17529. tempIndex = ((gun_index==2) ? 1: 0);
  17530. }
  17531. else
  17532. {
  17533. tempIndex = gun_index;
  17534. }
  17535. for (int index = 0; index < CCS_QUANTITY; index++)
  17536. {
  17537. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17538. {
  17539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17540. }
  17541. }// End of for CCS_QUANTITY
  17542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17543. }
  17544. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17545. {
  17546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17547. {
  17548. tempIndex = ((gun_index==2) ? 1: 0);
  17549. }
  17550. else
  17551. {
  17552. tempIndex = gun_index;
  17553. }
  17554. for (int index = 0; index < GB_QUANTITY; index++)
  17555. {
  17556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17557. {
  17558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17559. }
  17560. }// End of for GB_QUANTITY
  17561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17562. }
  17563. else if(gunType[gun_index] == GUN_TYPE_DO)
  17564. {
  17565. tempIndex = gun_index;
  17566. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17567. {
  17568. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17569. {
  17570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17571. }
  17572. }
  17573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17574. }
  17575. else
  17576. {
  17577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17578. {
  17579. tempIndex = 2;
  17580. }
  17581. else
  17582. {
  17583. tempIndex = gun_index;
  17584. }
  17585. for (int index = 0; index < AC_QUANTITY; index++)
  17586. {
  17587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17588. {
  17589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17590. }
  17591. }// End of for AC_QUANTITY
  17592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17593. }
  17594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17597. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17600. }
  17601. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17602. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17603. {
  17604. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17605. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17606. {
  17607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17608. {
  17609. tempIndex = ((gun_index==2) ? 1: 0);
  17610. }
  17611. else
  17612. {
  17613. tempIndex = gun_index;
  17614. }
  17615. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17616. {
  17617. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17618. {
  17619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17620. }
  17621. }// END OF CHAdeMO_QUANTITY
  17622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17623. }
  17624. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17625. {
  17626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17627. {
  17628. tempIndex = ((gun_index==2) ? 1: 0);
  17629. }
  17630. else
  17631. {
  17632. tempIndex = gun_index;
  17633. }
  17634. for (int index = 0; index < CCS_QUANTITY; index++)
  17635. {
  17636. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17637. {
  17638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17639. }
  17640. }// END OF CCS_QUANTITY
  17641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17642. }
  17643. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17644. {
  17645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17646. {
  17647. tempIndex = ((gun_index==2) ? 1: 0);
  17648. }
  17649. else
  17650. {
  17651. tempIndex = gun_index;
  17652. }
  17653. for (int index = 0; index < GB_QUANTITY; index++)
  17654. {
  17655. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17656. {
  17657. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17658. }
  17659. }// END OF GB_QUANTITY
  17660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17661. }
  17662. else if(gunType[gun_index] == GUN_TYPE_DO)
  17663. {
  17664. tempIndex = gun_index;
  17665. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17666. {
  17667. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17668. {
  17669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17670. }
  17671. }
  17672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17673. }
  17674. else
  17675. {
  17676. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17677. {
  17678. tempIndex = 2;
  17679. }
  17680. else
  17681. {
  17682. tempIndex = gun_index;
  17683. }
  17684. for (int index = 0; index < AC_QUANTITY; index++)
  17685. {
  17686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17687. {
  17688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17689. }
  17690. }// END OF AC_QUANTITY
  17691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17692. }
  17693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17696. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17699. }
  17700. //2.3====================================== Power.Active.Import =========================================
  17701. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17702. {
  17703. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17704. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17705. {
  17706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17707. {
  17708. tempIndex = ((gun_index==2) ? 1: 0);
  17709. }
  17710. else
  17711. {
  17712. tempIndex = gun_index;
  17713. }
  17714. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17715. {
  17716. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17717. {
  17718. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17719. }
  17720. } // End for CHAdeMO_QUANTITY
  17721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17722. }
  17723. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17724. {
  17725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17726. {
  17727. tempIndex = ((gun_index==2) ? 1: 0);
  17728. }
  17729. else
  17730. {
  17731. tempIndex = gun_index;
  17732. }
  17733. for (int index = 0; index < CCS_QUANTITY; index++)
  17734. {
  17735. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17736. {
  17737. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17738. }
  17739. } // END for CCS_QUANTITY
  17740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17741. }
  17742. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17743. {
  17744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17745. {
  17746. tempIndex = ((gun_index==2) ? 1: 0);
  17747. }
  17748. else
  17749. {
  17750. tempIndex = gun_index;
  17751. }
  17752. for (int index = 0; index < GB_QUANTITY; index++)
  17753. {
  17754. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17755. {
  17756. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17757. }
  17758. }// END for GB_QUANTITY
  17759. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17760. }
  17761. else if(gunType[gun_index] == GUN_TYPE_DO)
  17762. {
  17763. tempIndex = gun_index;
  17764. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17765. {
  17766. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17767. {
  17768. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17769. }
  17770. }
  17771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17772. }
  17773. else
  17774. {
  17775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17776. {
  17777. tempIndex = 2;
  17778. }
  17779. else
  17780. {
  17781. tempIndex = gun_index;
  17782. }
  17783. for (int index = 0; index < AC_QUANTITY; index++)
  17784. {
  17785. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17786. {
  17787. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17788. }
  17789. } // END for AC_QUANTITY
  17790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17791. }
  17792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17795. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17798. }
  17799. //2.4====================================== Voltage L1 ====================================================
  17800. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17801. {
  17802. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17803. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17804. {
  17805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17806. {
  17807. tempIndex = ((gun_index==2) ? 1: 0);
  17808. }
  17809. else
  17810. {
  17811. tempIndex = gun_index;
  17812. }
  17813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17814. {
  17815. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17816. {
  17817. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17818. }
  17819. } // END OF FOR CHAdeMO_QUANTITY
  17820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17821. }
  17822. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17823. {
  17824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17825. {
  17826. tempIndex = ((gun_index==2) ? 1: 0);
  17827. }
  17828. else
  17829. {
  17830. tempIndex = gun_index;
  17831. }
  17832. for (int index = 0; index < CCS_QUANTITY; index++)
  17833. {
  17834. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17835. {
  17836. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17837. }
  17838. } // END OF FOR CCS_QUANTITY
  17839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17840. }
  17841. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17842. {
  17843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17844. {
  17845. tempIndex = ((gun_index==2) ? 1: 0);
  17846. }
  17847. else
  17848. {
  17849. tempIndex = gun_index;
  17850. }
  17851. for (int index = 0; index < GB_QUANTITY; index++)
  17852. {
  17853. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17854. {
  17855. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17856. }
  17857. } // END OF FOR GB_QUANTITY
  17858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17859. }
  17860. else if(gunType[gun_index] == GUN_TYPE_DO)
  17861. {
  17862. tempIndex = gun_index;
  17863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17864. {
  17865. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17866. {
  17867. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17868. }
  17869. }
  17870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17871. }
  17872. else
  17873. {
  17874. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17875. {
  17876. tempIndex = 2;
  17877. }
  17878. else
  17879. {
  17880. tempIndex = gun_index;
  17881. }
  17882. for (int index = 0; index < AC_QUANTITY; index++)
  17883. {
  17884. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17885. {
  17886. 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
  17887. }
  17888. } // END OF FOR AC_QUANTITY
  17889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17890. }
  17891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17894. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17897. }
  17898. //2.5============================================== End SoC =========================================================
  17899. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17900. {
  17901. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17902. 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))
  17903. {
  17904. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17905. {
  17906. tempIndex = ((gun_index==2) ? 1: 0);
  17907. }
  17908. else
  17909. {
  17910. tempIndex = gun_index;
  17911. }
  17912. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17913. {
  17914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17915. {
  17916. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17917. {
  17918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17919. }
  17920. }
  17921. }
  17922. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17923. {
  17924. for (int index = 0; index < CCS_QUANTITY; index++)
  17925. {
  17926. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17927. {
  17928. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17929. }
  17930. }
  17931. }
  17932. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17933. {
  17934. for (int index = 0; index < GB_QUANTITY; index++)
  17935. {
  17936. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17937. {
  17938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17939. }
  17940. }
  17941. }
  17942. else if(gunType[gun_index] == GUN_TYPE_DO)
  17943. {
  17944. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17945. {
  17946. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17947. {
  17948. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17949. }
  17950. }
  17951. }
  17952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17958. } // END FOR DC CASE
  17959. }
  17960. //2.6====================================== Current.Import L2 ==============================================
  17961. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17962. {
  17963. // AC 3 phase L2 current
  17964. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17965. {
  17966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17967. {
  17968. tempIndex = 2;
  17969. }
  17970. else
  17971. {
  17972. tempIndex = gun_index;
  17973. }
  17974. for (int index = 0; index < AC_QUANTITY; index++)
  17975. {
  17976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17977. {
  17978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17979. }
  17980. }// End of for AC_QUANTITY
  17981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17982. }
  17983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17988. }
  17989. //2.7====================================== Current.Import L3 ==============================================
  17990. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17991. {
  17992. // AC 3 phase L3 current
  17993. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17994. {
  17995. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17996. {
  17997. tempIndex = 2;
  17998. }
  17999. else
  18000. {
  18001. tempIndex = gun_index;
  18002. }
  18003. for (int index = 0; index < AC_QUANTITY; index++)
  18004. {
  18005. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18006. {
  18007. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18008. }
  18009. }// End of for AC_QUANTITY
  18010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18011. }
  18012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18017. }
  18018. //2.9====================================== Voltage L2 ====================================================
  18019. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18020. {
  18021. // AC 3 phase L2 volatge
  18022. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18023. {
  18024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18025. {
  18026. tempIndex = 2;
  18027. }
  18028. else
  18029. {
  18030. tempIndex = gun_index;
  18031. }
  18032. for (int index = 0; index < AC_QUANTITY; index++)
  18033. {
  18034. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18035. {
  18036. 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
  18037. }
  18038. } // END OF FOR AC_QUANTITY
  18039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18040. }
  18041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18046. }
  18047. //2.10====================================== Voltage L3 ====================================================
  18048. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18049. {
  18050. // AC 3 phase L3 volatge
  18051. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18052. {
  18053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18054. {
  18055. tempIndex = 2;
  18056. }
  18057. else
  18058. {
  18059. tempIndex = gun_index;
  18060. }
  18061. for (int index = 0; index < AC_QUANTITY; index++)
  18062. {
  18063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18064. {
  18065. 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
  18066. }
  18067. } // END OF FOR AC_QUANTITY
  18068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18069. }
  18070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18075. }
  18076. //====================== Start SoC ================================
  18077. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18078. {
  18079. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18080. 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))
  18081. {
  18082. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18083. {
  18084. tempIndex = ((gun_index==2) ? 1: 0);
  18085. }
  18086. else
  18087. {
  18088. tempIndex = gun_index;
  18089. }
  18090. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18091. {
  18092. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18093. {
  18094. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18095. {
  18096. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18097. }
  18098. }
  18099. }
  18100. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18101. {
  18102. for (int index = 0; index < CCS_QUANTITY; index++)
  18103. {
  18104. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18105. {
  18106. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18107. }
  18108. }
  18109. }
  18110. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18111. {
  18112. for (int index = 0; index < GB_QUANTITY; index++)
  18113. {
  18114. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18115. {
  18116. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18117. }
  18118. }
  18119. }
  18120. else if(gunType[gun_index] == GUN_TYPE_DO)
  18121. {
  18122. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18123. {
  18124. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18125. {
  18126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18127. }
  18128. }
  18129. }
  18130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18136. } // END FOR DC CASE
  18137. }
  18138. //======================================== Message create ==============================================
  18139. json_object *StopTransaction = json_object_new_object();
  18140. json_object *transactionDatas = json_object_new_array();
  18141. json_object *sampledValues = json_object_new_array();
  18142. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18143. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18144. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18145. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18146. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18147. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18148. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18149. {
  18150. json_object *transactionData = json_object_new_object();
  18151. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18152. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18153. {
  18154. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18155. {
  18156. json_object *sampledValue = json_object_new_object();
  18157. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18158. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18159. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18160. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18161. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18162. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18163. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18164. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18165. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18166. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18167. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18168. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18169. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18170. json_object_array_add(sampledValues, sampledValue);
  18171. }
  18172. }
  18173. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18174. json_object_array_add(transactionDatas, transactionData);
  18175. }
  18176. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18177. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18178. ,MESSAGE_TYPE_CALL
  18179. ,guid
  18180. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18181. json_object_put(StopTransaction);
  18182. // Check File "TempStopTransaction" Exist
  18183. if((access(TempStopTransaction,F_OK))!=-1)
  18184. {
  18185. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18186. fclose(fopen(TempStopTransaction, "w"));
  18187. }
  18188. else
  18189. {
  18190. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18191. FILE *log = fopen(TempStopTransaction, "w+");
  18192. if(log == NULL)
  18193. {
  18194. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18195. return ;
  18196. }
  18197. else
  18198. {
  18199. fclose(log);
  18200. }
  18201. }
  18202. //Add TempStopTransaction | Update TempStopTransaction
  18203. // open file for writing
  18204. FILE *outfile;
  18205. outfile = fopen (TempStopTransaction, "a");
  18206. //DEBUG_INFO("data = %s\n", queuedata);
  18207. fputs(queuedata, outfile);
  18208. fputs("\n", outfile);
  18209. fclose (outfile);
  18210. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18211. OCPP_updatePeriodEnergy(gun_index);
  18212. }
  18213. void checkTempStopTransaction(int gun_index)
  18214. {
  18215. FILE *fptr1;
  18216. char ch;
  18217. char str[QUEUE_MESSAGE_LENGTH]={0};
  18218. char guid[37]={0};
  18219. char tempdata[65]={0};
  18220. char connectorStr[2]={0};
  18221. char TempStopTransaction[256];
  18222. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18223. fptr1 = fopen(TempStopTransaction, "r");
  18224. //TempStopTransaction格式: 槍號,StopTransaction封包
  18225. if (!fptr1)
  18226. {
  18227. //printf(" File not found or unable to open the input file!!\n");
  18228. return ;
  18229. }
  18230. ch=fgetc(fptr1);
  18231. //printf(" Now the content of the file %s is : \n",fname);
  18232. rewind(fptr1);
  18233. if(ch!=EOF)
  18234. {
  18235. // copy all contents to the temporary file except the specific line
  18236. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18237. {
  18238. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18239. if(str[0]=='\0')
  18240. {
  18241. break;
  18242. }
  18243. //TempStopTransaction格式: 槍號,StopTransaction封包
  18244. strncpy(connectorStr, str, 1);
  18245. if(atoi(connectorStr) != (gun_index+1))
  18246. {
  18247. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18248. fclose(fptr1);
  18249. return ;
  18250. }
  18251. //random_uuid(guid);
  18252. strncpy(guid, str+6, 36); //copy guid
  18253. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18254. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18255. {
  18256. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18257. }
  18258. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18259. OCPP_insert_transaction_msg(NO, str);
  18260. memset(str,0,ARRAY_SIZE(str));
  18261. }
  18262. }
  18263. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18264. fclose(fptr1);
  18265. remove(TempStopTransaction); // remove the original file
  18266. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18267. }
  18268. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18269. {
  18270. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18271. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18272. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18273. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18274. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18275. }
  18276. int GetWebSocketPingInterval(void)
  18277. {
  18278. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18279. }
  18280. int GetServerSign(void)
  18281. {
  18282. return server_sign;
  18283. }
  18284. uint8_t GetOcppSecurityProfile()
  18285. {
  18286. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18287. }
  18288. void GetOcppChargerBoxId(uint8_t *data)
  18289. {
  18290. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18291. }
  18292. void GetOcppSecurityPassword(uint8_t *data)
  18293. {
  18294. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18295. }
  18296. void SetOcppVersion(uint8_t *version)
  18297. {
  18298. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18299. DEBUG_INFO("ocpp version: %s\n", version);
  18300. if(strstr((char*)version, "ocpp1.6") != NULL)
  18301. {
  18302. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18303. }
  18304. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18305. {
  18306. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18307. system("pkill OcppBackend");
  18308. }
  18309. }
  18310. void SetServerSign(int value)
  18311. {
  18312. server_sign = value;
  18313. }
  18314. int GetBootNotificationInterval(void)
  18315. {
  18316. return BootNotificationInterval;
  18317. }
  18318. int GetInternetConn(void)
  18319. {
  18320. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18321. }
  18322. int GetBackendConnectionTimeout(void)
  18323. {
  18324. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18325. }
  18326. int isConnectorInitMode(int gun_index)
  18327. {
  18328. int tempIndex = 0;
  18329. int result = TRUE;
  18330. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18331. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18332. {
  18333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18334. {
  18335. tempIndex = ((gun_index==2) ? 1: 0);
  18336. }
  18337. else
  18338. {
  18339. tempIndex = gun_index;
  18340. }
  18341. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18342. {
  18343. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18344. {
  18345. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18346. } //end of the same index
  18347. }//end of for CHAdeMO_QUANTITY
  18348. }
  18349. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18350. {
  18351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18352. {
  18353. tempIndex = ((gun_index==2) ? 1: 0);
  18354. }
  18355. else
  18356. {
  18357. tempIndex = gun_index;
  18358. }
  18359. for (int index = 0; index < CCS_QUANTITY; index++)
  18360. {
  18361. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18362. {
  18363. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18364. } //end of the same index
  18365. } // end of for CCS_QUANTITY
  18366. }
  18367. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18368. {
  18369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18370. {
  18371. tempIndex = ((gun_index==2) ? 1: 0);
  18372. }
  18373. else
  18374. {
  18375. tempIndex = gun_index;
  18376. }
  18377. for (int index = 0; index < GB_QUANTITY; index++)
  18378. {
  18379. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18380. {
  18381. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18382. } //end of the same index
  18383. } // end of for GB_QUANTITY
  18384. }
  18385. else if(gunType[gun_index] == GUN_TYPE_DO)
  18386. {
  18387. tempIndex = gun_index;
  18388. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18389. {
  18390. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18391. {
  18392. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18393. } //end of the same index
  18394. }
  18395. }
  18396. else
  18397. {
  18398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18399. {
  18400. tempIndex = 2;
  18401. }
  18402. else
  18403. {
  18404. tempIndex = gun_index;
  18405. }
  18406. for (int index = 0; index < AC_QUANTITY; index++)
  18407. {
  18408. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18409. {
  18410. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18411. }//end of the same index
  18412. }//end of for AC_QUANTITY
  18413. }
  18414. return result;
  18415. }
  18416. void refreshProcDogTimer()
  18417. {
  18418. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18419. }
  18420. void InitialSystemValue(void)
  18421. {
  18422. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18423. locallistVersion=0;
  18424. BootNotificationInterval = 0;
  18425. authorizeRetryTimes = 0;
  18426. GunStatusInterval = 10;
  18427. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18428. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18429. //Hear Beat
  18430. HeartBeatWithNOResponse = 0;
  18431. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18432. FirstHeartBeat = 0;
  18433. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18434. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18435. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18436. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18437. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18438. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18439. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18440. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18441. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18442. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18443. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18444. //Status && ConnectorPlugIn Setting
  18445. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18446. {
  18447. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18448. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18449. }
  18450. for (int index = 0; index < CCS_QUANTITY; index++)
  18451. {
  18452. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18453. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18454. }
  18455. for (int index = 0; index < GB_QUANTITY; index++)
  18456. {
  18457. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18458. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18459. }
  18460. for (int index = 0; index < AC_QUANTITY; index++)
  18461. {
  18462. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18463. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18464. }
  18465. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18466. {
  18467. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18468. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18469. }
  18470. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18471. {
  18472. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18473. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18474. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18475. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18476. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18477. }
  18478. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18479. refreshStartTimer(&clientTime.Heartbeat);
  18480. sleep(1);
  18481. }
  18482. void LWS_Send(char *str)
  18483. {
  18484. //=====================================================
  18485. // Check InternetConn 0: disconnected, 1: connected
  18486. //====================================================
  18487. if(GetOcppConnStatus() == 0)
  18488. {
  18489. DEBUG_INFO("offline now !!!\n");
  18490. return;
  18491. }
  18492. // Only disable isWebsocketSendable operation initiated by charger
  18493. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18494. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18495. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18496. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18497. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18498. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18499. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18500. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18501. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18502. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18503. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18504. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18505. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18506. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18507. {
  18508. isWebsocketSendable = 0;
  18509. }
  18510. pthread_mutex_lock(&lock_send);
  18511. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18512. sprintf((char *)SendBuffer, "%s", str);
  18513. SendBufLen = strlen(str);
  18514. pthread_mutex_unlock(&lock_send);
  18515. lws_callback_on_writable(wsi_client);
  18516. //lws_service(context, 0);
  18517. //sleep(1);
  18518. }
  18519. void LWS_SendNow(char *str)
  18520. {
  18521. //=====================================================
  18522. // Check InternetConn 0: disconnected, 1: connected
  18523. //====================================================
  18524. if(GetOcppConnStatus() == 0)
  18525. {
  18526. DEBUG_INFO("offline now !!!\n");
  18527. return;
  18528. }
  18529. // Only disable isWebsocketSendable operation initiated by charger
  18530. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18531. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18532. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18533. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18534. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18535. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18536. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18537. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18538. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18539. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18540. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18541. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18542. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18543. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18544. {
  18545. isWebsocketSendable = 0;
  18546. }
  18547. pthread_mutex_lock(&lock_send);
  18548. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18549. sprintf((char *)SendBuffer, "%s", str);
  18550. SendBufLen = strlen(str);
  18551. pthread_mutex_unlock(&lock_send);
  18552. lws_callback_on_writable(wsi_client);
  18553. lws_service(context, 0);
  18554. //sleep(1);
  18555. }