MessageHandler.c 931 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //============================================
  80. // OCPP MeterValue request flag
  81. //============================================
  82. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  83. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  84. //=============================================
  85. // OCPP HeartBeat Response Not Receive Counts
  86. //============================================
  87. static int HeartBeatWithNOResponse = 0;
  88. extern sqlite3 *db;
  89. int TransactionMessageAttemptsGet(void);
  90. int TransactionMessageRetryIntervalGet(void);
  91. int GetOcppConnStatus(void);
  92. void SetOcppConnStatus(uint8_t status);
  93. int setKeyValue(char *key, char *value);
  94. void OCPP_get_TableAuthlocalAllData(void);
  95. void processUnkownKey(void);
  96. struct InterLock
  97. {
  98. unsigned char isGetDiagnosticGoing:1;
  99. unsigned char isUpdateFirmwareGoing:1;
  100. }interLock;
  101. struct ClientTime
  102. {
  103. struct timespec Heartbeat;
  104. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  105. struct timespec StartTransaction;
  106. struct timespec StopTransaction;
  107. struct timespec MeterValues[CONNECTOR_QUANTITY];
  108. struct timespec RemoteStartWait;
  109. struct timespec TcciQueryDeduct;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4,
  123. unsigned char :3; //bit5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // TTIA routine
  363. //=========================================
  364. int sendTTIAInfo(uint8_t gun_index)
  365. {
  366. static int sn = 0;
  367. int result = FAIL;
  368. struct hostent *server;
  369. int udp_socket_fd;
  370. struct sockaddr_in dest_addr = {0};
  371. uint8_t tx_buf[80] = {0};
  372. uint8_t logBuf[256]= {0};
  373. uint8_t tx_len, tempIndex, socStart, socEnd;
  374. uint16_t PresentChargedEnergy;
  375. struct tm tmStart, tmEnd;
  376. DEBUG_INFO("sendTTIAInfo...\n");
  377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  378. {
  379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  380. {
  381. tempIndex = ((gun_index==2) ? 1: 0);
  382. }
  383. else
  384. {
  385. tempIndex = gun_index;
  386. }
  387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  388. {
  389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  390. {
  391. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  392. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  393. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  394. }
  395. }
  396. }
  397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  398. {
  399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  400. {
  401. tempIndex = ((gun_index==2) ? 1: 0);
  402. }
  403. else
  404. {
  405. tempIndex = gun_index;
  406. }
  407. for (int index = 0; index < CCS_QUANTITY; index++)
  408. {
  409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  410. {
  411. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  412. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  413. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  414. }
  415. }
  416. }
  417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  418. {
  419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  420. {
  421. tempIndex = ((gun_index==2) ? 1: 0);
  422. }
  423. else
  424. {
  425. tempIndex = gun_index;
  426. }
  427. for (int index = 0; index < GB_QUANTITY; index++)
  428. {
  429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  430. {
  431. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  432. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  433. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  434. }
  435. }
  436. }
  437. else if(gunType[gun_index] == GUN_TYPE_DO)
  438. {
  439. tempIndex = gun_index;
  440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  453. {
  454. tempIndex = 2;
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < AC_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }// END
  469. }
  470. // Message assembly
  471. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  472. tx_buf[4] = 0x02; // Protocol Version
  473. tx_buf[5] = 0xb0; // Message ID
  474. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  475. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  476. tx_buf[8] = 0x00; // CarID low byte
  477. tx_buf[9] = 0x00; // CarID high byte
  478. tx_buf[10] = 0x00; // ID Storage
  479. tx_buf[11] = 0x00; // Driver lowest byte
  480. tx_buf[12] = 0x00; // Driver 2nd byte
  481. tx_buf[13] = 0x00; // Driver 3rd byte
  482. tx_buf[14] = 0x00; // Driver highest byte
  483. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  484. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  485. tx_buf[17] = 0x00; // Reserve
  486. tx_buf[18] = 60 & 0xff; // Payload length low byte
  487. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  488. // EVSE provider
  489. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  490. // EVSE provider
  491. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  492. // EVSE id
  493. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  494. // Connector id
  495. tx_buf[37] = gun_index;
  496. // EVSE station
  497. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  498. // Vehicle SN
  499. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  500. // Mileage
  501. tx_buf[61] = 0x00; // lowest byte
  502. tx_buf[62] = 0x00; // 2nd byte
  503. tx_buf[63] = 0x00; // highest byte
  504. // Start date time 6 bytes
  505. 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))
  506. {
  507. struct tm *tmTarget;
  508. struct timeb tbTarget;
  509. tmStart.tm_year -= 1900;
  510. tmStart.tm_mon -= 1;
  511. tmStart.tm_gmtoff = 0;
  512. tbTarget.time = mktime(&tmStart);
  513. tbTarget.timezone = 0;
  514. tbTarget.time += (8*3600);
  515. tmTarget = gmtime(&tbTarget.time);
  516. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  517. tx_buf[65] = (tmTarget->tm_mon+1);
  518. tx_buf[66] = tmTarget->tm_mday;
  519. tx_buf[67] = tmTarget->tm_hour;
  520. tx_buf[68] = tmTarget->tm_min;
  521. tx_buf[69] = tmTarget->tm_sec;
  522. }
  523. // Stop date time 6 bytes
  524. 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))
  525. {
  526. struct tm *tmTarget;
  527. struct timeb tbTarget;
  528. tmEnd.tm_year -= 1900;
  529. tmEnd.tm_mon -= 1;
  530. tmEnd.tm_gmtoff = 0;
  531. tbTarget.time = mktime(&tmEnd);
  532. tbTarget.timezone = 0;
  533. tbTarget.time += (8*3600);
  534. tmTarget = gmtime(&tbTarget.time);
  535. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  536. tx_buf[71] = (tmTarget->tm_mon+1);
  537. tx_buf[72] = tmTarget->tm_mday;
  538. tx_buf[73] = tmTarget->tm_hour;
  539. tx_buf[74] = tmTarget->tm_min;
  540. tx_buf[75] = tmTarget->tm_sec;
  541. }
  542. // Session energy 2 bytes
  543. tx_buf[76] = PresentChargedEnergy & 0xff;
  544. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  545. // Start SOC 1 byte
  546. tx_buf[78] = socStart;
  547. // Stop SOC 1 byte
  548. tx_buf[79] = socEnd;
  549. // Open socket
  550. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  551. if(udp_socket_fd == -1)
  552. {
  553. DEBUG_ERROR("UDP socket create failed!\n");
  554. }
  555. else
  556. {
  557. // Get server DNS entry
  558. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  559. if (server == NULL)
  560. {
  561. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  562. }
  563. else
  564. {
  565. // Build the server's Internet address
  566. bzero((char *) &dest_addr, sizeof(dest_addr));
  567. dest_addr.sin_family = AF_INET;
  568. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  569. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  570. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  571. {
  572. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  573. {
  574. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  575. }
  576. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  577. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  578. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  579. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  580. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  581. DEBUG_TTIA_INFO("---------- Header ----------\n");
  582. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  583. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  584. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  585. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  586. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  587. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  588. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  589. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  590. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  591. DEBUG_TTIA_INFO("Len: 0x3C\n");
  592. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  593. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  594. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  595. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  596. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  597. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  598. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  599. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  600. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  603. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  604. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  605. DEBUG_TTIA_INFO("=========================================\n");
  606. sn++;
  607. result = PASS;
  608. }
  609. else
  610. {
  611. DEBUG_ERROR("UDP sent out fail.\n");
  612. }
  613. }
  614. }
  615. return result;
  616. }
  617. //=========================================
  618. // Save configuration
  619. //=========================================
  620. int runShellCmd(const char*cmd)
  621. {
  622. int result = FAIL;
  623. char buf[256];
  624. FILE *fp;
  625. fp = popen(cmd, "r");
  626. if(fp != NULL)
  627. {
  628. while(fgets(buf, sizeof(buf), fp) != NULL)
  629. {
  630. DEBUG_INFO("%s\n", buf);
  631. }
  632. result = PASS;
  633. }
  634. pclose(fp);
  635. return result;
  636. }
  637. int StoreUsrConfigData(struct SysConfigData *UsrData)
  638. {
  639. int result = PASS;
  640. int fd,wrd;
  641. unsigned int i,Chk;
  642. unsigned char *ptr, *BufTmp;
  643. int MtdBlockSize = 0x300000;
  644. Chk=0;
  645. ptr=(unsigned char *)UsrData;
  646. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  647. {
  648. memset(BufTmp,0,MtdBlockSize);
  649. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  650. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  651. Chk+=*(BufTmp+i);
  652. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  653. // Output configuration to file.
  654. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  655. if (fd < 0)
  656. {
  657. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  658. free(BufTmp);
  659. return 0;
  660. }
  661. wrd=write(fd, BufTmp, MtdBlockSize);
  662. close(fd);
  663. if(wrd<MtdBlockSize)
  664. {
  665. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  666. free(BufTmp);
  667. return 0;
  668. }
  669. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  670. DEBUG_INFO("Erase /dev/mtd10.\n");
  671. runShellCmd("flash_erase /dev/mtd10 0 0");
  672. DEBUG_INFO("Write /dev/mtd10.\n");
  673. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  674. DEBUG_INFO("Erase /dev/mtd11.\n");
  675. runShellCmd("flash_erase /dev/mtd11 0 0");
  676. DEBUG_INFO("Write /dev/mtd11.\n");
  677. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  678. system("rm -f /mnt/EvseConfig.bin");
  679. DEBUG_INFO("EvseConfig write to flash OK\n");
  680. }
  681. else
  682. {
  683. DEBUG_ERROR("alloc BlockSize NG\r\n");
  684. result = FAIL;
  685. }
  686. if(BufTmp!=NULL)
  687. free(BufTmp);
  688. return result;
  689. }
  690. //=========================================
  691. // Sqlite3 related function
  692. //=========================================
  693. static int selectSqlCount = 0;
  694. static int callback(void *data, int argc, char **argv, char **azColName){
  695. int i;
  696. //printf("%s: ", (const char*)data);
  697. selectSqlCount = argc;
  698. for(i = 0; i<argc; i++){
  699. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  700. }
  701. //printf("\n");
  702. return 0;
  703. }
  704. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  705. //int i;
  706. //printf("%s:\n", (const char*)data);
  707. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  708. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  709. return 0;
  710. }
  711. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  712. //printf("%s:\n", (const char*)data);
  713. //idTag
  714. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. //parentIdTag
  717. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  718. //expir_date
  719. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  720. //status
  721. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  722. //version
  723. if(columenCount > 5)
  724. idTagQuery.listVersionInt = atoi(columnValue[5]);
  725. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  726. return 0;
  727. }
  728. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  729. {
  730. // localversion = argv[5] ? atoi(argv[5]) : 0;
  731. // printf("localversion=%d\n", localversion);
  732. return 0;
  733. }
  734. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  735. {
  736. for (int i = 0; i < n_columns; i++)
  737. {
  738. DEBUG_INFO("%s\t", col_values[i]);
  739. }
  740. DEBUG_INFO("\n");
  741. return 0;
  742. }
  743. int OCPP_cleanLocalCache()
  744. {
  745. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  746. char *errMsg = 0;
  747. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  748. if (SQLITE_OK != rc)
  749. {
  750. DEBUG_INFO("SQL error: %s\n",errMsg);
  751. return FALSE;
  752. }
  753. return TRUE;
  754. }
  755. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  756. {
  757. int isSuccess = TRUE;
  758. int ret = 0;
  759. //const char* data = "Callback function called";
  760. char sql[300];
  761. char zErrMsg[200];
  762. memset(sql, 0, 300);
  763. memset(zErrMsg, 0, 200);
  764. 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);
  765. //* Execute SQL statement */
  766. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  767. if( ret != SQLITE_OK )
  768. {
  769. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  770. isSuccess = FALSE;
  771. }
  772. return isSuccess;
  773. }
  774. void OCPP_getIdTagFromLocalCache(char idTag[])
  775. {
  776. int rc = 0;
  777. char sql[100];
  778. char zErrMsg[100];
  779. memset(sql, 0, 100);
  780. memset(zErrMsg, 0, 100);
  781. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  782. memset(&idTagQuery, 0, sizeof(idTagQuery));
  783. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  784. /* Execute SQL statement */
  785. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  786. if( rc != SQLITE_OK )
  787. {
  788. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  789. }
  790. }
  791. void OCPP_getListVerion()
  792. {
  793. int rc = 0;
  794. // const char* data = "Callback function called";
  795. char sql[100];
  796. char zErrMsg[100];
  797. memset(sql, 0, 100);
  798. memset(zErrMsg, 0, 100);
  799. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  800. /* Execute SQL statement */
  801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  802. if( rc != SQLITE_OK )
  803. {
  804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  805. }
  806. }
  807. void OCPP_get_TableAuthlocalAllData(void)
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. sprintf(sql,"select * from ocpp_auth_local ");
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. //return ver;
  822. }
  823. int OCPP_cleanLocalList()
  824. {
  825. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  826. char *errMsg = 0;
  827. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  828. if (SQLITE_OK != rc)
  829. {
  830. DEBUG_INFO("%s\n",errMsg);
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  836. {
  837. int isSuccess = FALSE;
  838. int ret = 0;
  839. //const char* data = "Callback function called";
  840. char sql[300];
  841. char zErrMsg[200];
  842. memset(sql, 0, 300);
  843. memset(zErrMsg, 0, 200);
  844. 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);
  845. //* Execute SQL statement */
  846. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  847. if( ret != SQLITE_OK )
  848. {
  849. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  850. return isSuccess;
  851. }
  852. memset(sql, 0, 300);
  853. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  854. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  855. if( ret != SQLITE_OK )
  856. {
  857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  858. return isSuccess;
  859. }
  860. isSuccess = TRUE;
  861. return isSuccess;
  862. }
  863. void OCPP_getIdTagFromLocalList(char idTag[])
  864. {
  865. int rc = 0;
  866. // const char* data = "Callback function called";
  867. char sql[100];
  868. char zErrMsg[100];
  869. memset(sql, 0, 100);
  870. memset(zErrMsg, 0, 100);
  871. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  872. memset(&idTagQuery, 0, sizeof(idTagQuery));
  873. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  875. /* Execute SQL statement */
  876. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  877. if( rc != SQLITE_OK )
  878. {
  879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  880. }
  881. //return ver;
  882. }
  883. void OCPP_deleteIdTagFromLocalList(char idTag[])
  884. {
  885. //int ver = 0;
  886. //int isSuccess = FALSE;
  887. int rc = 0;
  888. char sql[100];
  889. char zErrMsg[100];
  890. memset(sql, 0, 100);
  891. memset(zErrMsg, 0, 100);
  892. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  893. //* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. int getCurrentYear()
  901. {
  902. int result = 0;
  903. time_t CurrentTime;
  904. struct tm *tm;
  905. CurrentTime = time(NULL);
  906. tm=localtime(&CurrentTime);
  907. result = (tm->tm_year + 1900);
  908. return result;
  909. }
  910. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  911. {
  912. int result = PASS;
  913. char* errMsg = NULL;
  914. char sqlStr[8192];
  915. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  920. }
  921. 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));
  922. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  926. }
  927. return result;
  928. }
  929. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  930. {
  931. int isSuccess = TRUE;
  932. int tempIndex;
  933. json_object *EnergyDataTransfer = json_object_new_object();
  934. json_object *periodEnergys = json_object_new_object();
  935. char sql[1024];
  936. char zErrMsg[200];
  937. memset(sql, 0, ARRAY_SIZE(sql));
  938. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  940. {
  941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  942. {
  943. tempIndex = ((gun_index==2) ? 1: 0);
  944. }
  945. else
  946. {
  947. tempIndex = gun_index;
  948. }
  949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  952. {
  953. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  954. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  955. {
  956. uint8_t period[3];
  957. sprintf((char*)period, "%d", idxPeriod);
  958. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  959. }
  960. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  961. } //end of the same index
  962. }//end of for CHAdeMO_QUANTITY
  963. }
  964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  965. {
  966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  967. {
  968. tempIndex = ((gun_index==2) ? 1: 0);
  969. }
  970. else
  971. {
  972. tempIndex = gun_index;
  973. }
  974. for (int index = 0; index < CCS_QUANTITY; index++)
  975. {
  976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  977. {
  978. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  979. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  980. {
  981. uint8_t period[3];
  982. sprintf((char*)period, "%d", idxPeriod);
  983. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  984. }
  985. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  986. } //end of the same index
  987. } // end of for CCS_QUANTITY
  988. }
  989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  990. {
  991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  992. {
  993. tempIndex = ((gun_index==2) ? 1: 0);
  994. }
  995. else
  996. {
  997. tempIndex = gun_index;
  998. }
  999. for (int index = 0; index < GB_QUANTITY; index++)
  1000. {
  1001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1002. {
  1003. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1004. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1005. {
  1006. uint8_t period[3];
  1007. sprintf((char*)period, "%d", idxPeriod);
  1008. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1009. }
  1010. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1011. } //end of the same index
  1012. } // end of for GB_QUANTITY
  1013. }
  1014. else if(gunType[gun_index] == GUN_TYPE_DO)
  1015. {
  1016. tempIndex = gun_index;
  1017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1018. {
  1019. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1020. {
  1021. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1022. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1023. {
  1024. uint8_t period[3];
  1025. sprintf((char*)period, "%d", idxPeriod);
  1026. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1027. }
  1028. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1029. } //end of the same index
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. tempIndex = 2;
  1037. }
  1038. else
  1039. {
  1040. tempIndex = gun_index;
  1041. }
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1045. {
  1046. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1047. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1048. {
  1049. uint8_t period[3];
  1050. sprintf((char*)period, "%d", idxPeriod);
  1051. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1052. }
  1053. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1054. }//end of the same index
  1055. }//end of for AC_QUANTITY
  1056. }
  1057. 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));
  1058. json_object_put(EnergyDataTransfer);
  1059. //* Execute SQL statement */
  1060. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1061. {
  1062. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1066. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1067. {
  1068. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1069. isSuccess = FALSE;
  1070. }
  1071. return isSuccess;
  1072. }
  1073. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1074. {
  1075. int isSuccess = TRUE;
  1076. char sql[512];
  1077. char zErrMsg[200];
  1078. int rows, cols;
  1079. char **resultData;
  1080. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1081. /* Execute SQL statement */
  1082. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1083. {
  1084. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1085. isSuccess = FALSE;
  1086. }
  1087. else
  1088. {
  1089. if((rows > 0) && (atoi(resultData[4]) > 0))
  1090. {
  1091. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("There is not match transaction data.\n");
  1096. isSuccess = FALSE;
  1097. }
  1098. }
  1099. return isSuccess;
  1100. }
  1101. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1107. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1108. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1109. {
  1110. result = FAIL;
  1111. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1112. }
  1113. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1114. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1115. {
  1116. result = FAIL;
  1117. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1118. }
  1119. return result;
  1120. }
  1121. int OCPP_update_deduct_info(int txId, char *creditNo)
  1122. {
  1123. int result = PASS;
  1124. char* errMsg = NULL;
  1125. char sqlStr[8192];
  1126. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1127. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1128. {
  1129. result = FAIL;
  1130. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1131. }
  1132. return result;
  1133. }
  1134. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1135. {
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1138. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1139. atoi(columnValue[1]),
  1140. columnValue[2],
  1141. atoi(columnValue[3])==1?"true":"false",
  1142. atoi(columnValue[4])==1?"true":"false",
  1143. columnValue[5],
  1144. columnValue[9]);
  1145. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1146. return 0;
  1147. }
  1148. void OCPP_query_deduct_info()
  1149. {
  1150. int rc = 0;
  1151. char sql[100];
  1152. char zErrMsg[100];
  1153. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1154. /* Execute SQL statement */
  1155. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1156. if( rc != SQLITE_OK )
  1157. {
  1158. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1159. }
  1160. }
  1161. //==========================================
  1162. // Check time passed since today
  1163. //==========================================
  1164. long long DiffTimebWithNow(struct timeb ST)
  1165. {
  1166. //return milli-second
  1167. struct timeb ET;
  1168. long long StartTime,StopTime;
  1169. ftime(&ET);
  1170. StartTime=(long long)ST.time;
  1171. StopTime=(long long)ET.time;
  1172. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1173. }
  1174. int getTimePassSinceToday(uint8_t gun_index)
  1175. {
  1176. int result = -1;
  1177. static time_t lastTime[4];
  1178. time_t t;
  1179. struct tm *tmStartToday;
  1180. struct timeb tbStartToday;
  1181. t=time(NULL);
  1182. if(difftime(t, lastTime[gun_index])>0)
  1183. {
  1184. tmStartToday=localtime(&t);
  1185. tmStartToday->tm_hour = 0;
  1186. tmStartToday->tm_min = 0;
  1187. tmStartToday->tm_sec = 0;
  1188. tbStartToday.time = mktime(tmStartToday);
  1189. tbStartToday.millitm = 0;
  1190. result = DiffTimebWithNow(tbStartToday)/1000;
  1191. lastTime[gun_index] = t;
  1192. }
  1193. return result;
  1194. }
  1195. void getNowDatetime(uint8_t *data)
  1196. {
  1197. time_t t = time(NULL);
  1198. struct tm tm = *localtime(&t);
  1199. 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);
  1200. }
  1201. int syncDateTimeRTC(uint8_t *data)
  1202. {
  1203. struct ParsingResult
  1204. {
  1205. int result;
  1206. int scanedElement;
  1207. int year;
  1208. int month;
  1209. int mday;
  1210. int hour;
  1211. int min;
  1212. int sec;
  1213. int tz_hour;
  1214. int tz_min;
  1215. float minSec;
  1216. }result;
  1217. struct tm tmOrg;
  1218. struct tm *tmTarget;
  1219. struct timeb tbTarget;
  1220. char buf[128];
  1221. memset(&result, 0x00, sizeof(struct ParsingResult));
  1222. result.result = PASS;
  1223. if(strstr((char*)data, ".") != NULL)
  1224. {
  1225. // Original data with mini second
  1226. if(strstr((char*)data, "Z") != NULL)
  1227. {
  1228. // Original data with Z
  1229. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1230. &result.year,
  1231. &result.month,
  1232. &result.mday,
  1233. &result.hour,
  1234. &result.min,
  1235. &result.sec,
  1236. &result.minSec);
  1237. }
  1238. else
  1239. {
  1240. // Original data without Z
  1241. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1242. &result.year,
  1243. &result.month,
  1244. &result.mday,
  1245. &result.hour,
  1246. &result.min,
  1247. &result.sec,
  1248. &result.minSec,
  1249. &result.tz_hour,
  1250. &result.tz_min);
  1251. }
  1252. }
  1253. else
  1254. {
  1255. // Original data without mini second
  1256. if(strstr((char*)data, "Z") != NULL)
  1257. {
  1258. // Original data with Z
  1259. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1260. &result.year,
  1261. &result.month,
  1262. &result.mday,
  1263. &result.hour,
  1264. &result.min,
  1265. &result.sec);
  1266. }
  1267. else
  1268. {
  1269. // Original data without Z
  1270. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1271. &result.year,
  1272. &result.month,
  1273. &result.mday,
  1274. &result.hour,
  1275. &result.min,
  1276. &result.sec,
  1277. &result.tz_hour,
  1278. &result.tz_min);
  1279. }
  1280. }
  1281. tmOrg.tm_year = result.year - 1900;
  1282. tmOrg.tm_mon = result.month - 1;
  1283. tmOrg.tm_mday = result.mday;
  1284. tmOrg.tm_hour = result.hour;
  1285. tmOrg.tm_min = result.min;
  1286. tmOrg.tm_sec = result.sec;
  1287. tmOrg.tm_gmtoff = 0;
  1288. tbTarget.time = mktime(&tmOrg);
  1289. tbTarget.timezone = 0;
  1290. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1291. tmTarget = gmtime(&tbTarget.time);
  1292. 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);
  1293. //DEBUG_INFO(" org date time: %s\n", data);
  1294. //DEBUG_INFO("parse date time: %s\n", buf);
  1295. system(buf);
  1296. system("/sbin/hwclock -w --systohc");
  1297. if(result.scanedElement < 6)
  1298. result.result = FAIL;
  1299. return result.result;
  1300. }
  1301. //==========================================
  1302. // GetCompositeSchedule logic related function
  1303. //==========================================
  1304. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1305. {
  1306. //return milli-second
  1307. unsigned int StartTime,StopTime;
  1308. StartTime=(unsigned int)ST.time;
  1309. StopTime=(unsigned int)ET.time;
  1310. return (StopTime-StartTime);
  1311. }
  1312. int DiffTimebWithNowSec(struct timeb ST)
  1313. {
  1314. //return milli-second
  1315. struct timeb ET;
  1316. unsigned int StartTime,StopTime;
  1317. ftime(&ET);
  1318. StartTime=(unsigned int)ST.time;
  1319. StopTime=(unsigned int)ET.time;
  1320. return (StopTime-StartTime);
  1321. }
  1322. int getStartStop(uint8_t *start, uint8_t *stop)
  1323. {
  1324. int result = -1;
  1325. struct tm tmStart;
  1326. struct timeb tbStart;
  1327. struct tm tmStop;
  1328. struct timeb tbStop;
  1329. 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) &&
  1330. (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))
  1331. {
  1332. //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);
  1333. //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);
  1334. tmStart.tm_year -= 1900;
  1335. tmStart.tm_mon -= 1;
  1336. tbStart.time = mktime(&tmStart);
  1337. tbStart.millitm = 0;
  1338. tmStop.tm_year -= 1900;
  1339. tmStop.tm_mon -= 1;
  1340. tbStop.time = mktime(&tmStop);
  1341. tbStop.millitm = 0;
  1342. result = DiffTimebSec(tbStart, tbStop);
  1343. //DEBUG_INFO("getStartStop(): %d\n", result);
  1344. }
  1345. else
  1346. {
  1347. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1348. }
  1349. return result;
  1350. }
  1351. int isOvertNow(uint8_t *start)
  1352. {
  1353. int result = NO;
  1354. struct ParsingResult
  1355. {
  1356. int result;
  1357. int scanedElement;
  1358. int year;
  1359. int month;
  1360. int mday;
  1361. int hour;
  1362. int min;
  1363. int sec;
  1364. int tz_hour;
  1365. int tz_min;
  1366. float minSec;
  1367. }parsingResult;
  1368. struct tm tmStart;
  1369. struct timeb tbStart;
  1370. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1371. if(strstr((char*)start, ".") != NULL)
  1372. {
  1373. // Original data with mini second
  1374. if(strstr((char*)start, "Z") != NULL)
  1375. {
  1376. // Original data with Z
  1377. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1378. &parsingResult.year,
  1379. &parsingResult.month,
  1380. &parsingResult.mday,
  1381. &parsingResult.hour,
  1382. &parsingResult.min,
  1383. &parsingResult.sec,
  1384. &parsingResult.minSec);
  1385. }
  1386. else
  1387. {
  1388. // Original data without Z
  1389. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1390. &parsingResult.year,
  1391. &parsingResult.month,
  1392. &parsingResult.mday,
  1393. &parsingResult.hour,
  1394. &parsingResult.min,
  1395. &parsingResult.sec,
  1396. &parsingResult.minSec,
  1397. &parsingResult.tz_hour,
  1398. &parsingResult.tz_min);
  1399. }
  1400. }
  1401. else
  1402. {
  1403. // Original data without mini second
  1404. if(strstr((char*)start, "Z") != NULL)
  1405. {
  1406. // Original data with Z
  1407. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1408. &parsingResult.year,
  1409. &parsingResult.month,
  1410. &parsingResult.mday,
  1411. &parsingResult.hour,
  1412. &parsingResult.min,
  1413. &parsingResult.sec);
  1414. }
  1415. else
  1416. {
  1417. // Original data without Z
  1418. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1419. &parsingResult.year,
  1420. &parsingResult.month,
  1421. &parsingResult.mday,
  1422. &parsingResult.hour,
  1423. &parsingResult.min,
  1424. &parsingResult.sec,
  1425. &parsingResult.tz_hour,
  1426. &parsingResult.tz_min);
  1427. }
  1428. }
  1429. if(parsingResult.scanedElement >= 6)
  1430. {
  1431. tmStart.tm_year = parsingResult.year - 1900;
  1432. tmStart.tm_mon = parsingResult.month - 1;
  1433. tmStart.tm_mday = parsingResult.mday;
  1434. tmStart.tm_hour = parsingResult.hour;
  1435. tmStart.tm_min = parsingResult.min;
  1436. tmStart.tm_sec = parsingResult.sec;
  1437. tmStart.tm_gmtoff = 0;
  1438. tbStart.time = mktime(&tmStart);
  1439. tbStart.timezone = 0;
  1440. tbStart.millitm = 0;
  1441. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1442. if(DiffTimebWithNowSec(tbStart) <= 0)
  1443. result = NO;
  1444. else
  1445. result = YES;
  1446. }
  1447. else
  1448. {
  1449. DEBUG_WARN("Start date parsing error.\n");
  1450. }
  1451. return result;
  1452. }
  1453. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1454. {
  1455. int result = -1;
  1456. struct tm tmStart;
  1457. struct timeb tbStart;
  1458. struct tm tmStop;
  1459. struct timeb tbStop;
  1460. 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) &&
  1461. (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))
  1462. {
  1463. tmStart.tm_year -= 1900;
  1464. tmStart.tm_mon -= 1;
  1465. tbStart.time = mktime(&tmStart);
  1466. tbStart.millitm = 0;
  1467. tmStop.tm_year -= 1900;
  1468. tmStop.tm_mon -= 1;
  1469. tbStop.time = mktime(&tmStop);
  1470. tbStop.millitm = 0;
  1471. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1472. }
  1473. return result;
  1474. }
  1475. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1476. {
  1477. FILE *fp;
  1478. char profileFileName[128];
  1479. char *line = NULL;
  1480. size_t len = 0;
  1481. time_t CurrentTime;
  1482. struct tm *tmComposite;
  1483. struct StructChargingProfile maxProfile;
  1484. uint8_t limitMax=0;
  1485. int compositePeriodIdx = 0;
  1486. CurrentTime = time(NULL);
  1487. tmComposite=localtime(&CurrentTime);
  1488. 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);
  1489. if(isUnitA)
  1490. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1491. else
  1492. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1493. compositeProfile->ChargingSchedule.Duration = durationReq;
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1497. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1498. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1499. }
  1500. compositeProfile->ChargingProfileId = 0;
  1501. compositeProfile->StackLevel = 99 ;
  1502. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1503. maxProfile.ChargingProfileId = -1;
  1504. maxProfile.ChargingSchedule.Duration = -1;
  1505. system("rm -f /tmp/*.json");
  1506. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1507. // Search max profile
  1508. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1509. if((access(profileFileName, F_OK))!=-1)
  1510. {
  1511. fp = fopen(profileFileName, "r");
  1512. while(getline(&line, &len, fp) != -1)
  1513. {
  1514. json_object *obj = NULL;
  1515. obj = json_tokener_parse(line);
  1516. if(is_error(obj))
  1517. {
  1518. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1519. }
  1520. else
  1521. {
  1522. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1523. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1524. )
  1525. {
  1526. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1527. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1528. )
  1529. {
  1530. struct tm tmFrom, tmTo;
  1531. struct timeb tbFrom, tbTo;
  1532. 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) &&
  1533. (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))
  1534. {
  1535. tmFrom.tm_year -= 1900;
  1536. tmFrom.tm_mon -= 1;
  1537. tbFrom.time = mktime(&tmFrom);
  1538. tmTo.tm_year -= 1900;
  1539. tmTo.tm_mon -= 1;
  1540. tbTo.time = mktime(&tmTo);
  1541. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1542. {
  1543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1544. {
  1545. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1546. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1547. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1548. }
  1549. maxProfile.ChargingProfileId = -1;
  1550. maxProfile.StackLevel = -1;
  1551. if(maxProfile.ChargingProfileId == -1)
  1552. DEBUG_INFO("MaxProfile found.\n");
  1553. else
  1554. DEBUG_INFO("MaxProfile updated.\n");
  1555. // Required item
  1556. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1557. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1558. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1559. if(isUnitA)
  1560. {
  1561. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1562. 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++)
  1563. {
  1564. 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"));
  1565. 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?
  1566. 3:
  1567. 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")));
  1568. 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")));
  1569. }
  1570. }
  1571. else
  1572. {
  1573. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1574. 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++)
  1575. {
  1576. 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"));
  1577. 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?
  1578. 3:
  1579. 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")));
  1580. 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));
  1581. }
  1582. }
  1583. // Optional item
  1584. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1585. {
  1586. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1587. }
  1588. else
  1589. {
  1590. sprintf((char*)maxProfile.ValidFrom, " ");
  1591. }
  1592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1593. {
  1594. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1595. }
  1596. else
  1597. {
  1598. sprintf((char*)maxProfile.ValidTo, " ");
  1599. }
  1600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1601. {
  1602. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1603. }
  1604. else
  1605. {
  1606. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1607. }
  1608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1609. {
  1610. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1611. }
  1612. else
  1613. {
  1614. maxProfile.TransactionId = -1;
  1615. }
  1616. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1617. {
  1618. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1619. }
  1620. else
  1621. {
  1622. maxProfile.ChargingSchedule.Duration = 86400;
  1623. }
  1624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1625. {
  1626. 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")));
  1627. }
  1628. else
  1629. {
  1630. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1631. }
  1632. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1633. {
  1634. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1635. }
  1636. else
  1637. {
  1638. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1639. }
  1640. }
  1641. }
  1642. }
  1643. else
  1644. {
  1645. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1646. {
  1647. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1648. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1649. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1650. }
  1651. maxProfile.ChargingProfileId = -1;
  1652. maxProfile.StackLevel = -1;
  1653. if(maxProfile.ChargingProfileId == -1)
  1654. DEBUG_INFO("MaxProfile found.\n");
  1655. else
  1656. DEBUG_INFO("MaxProfile updated.\n");
  1657. // Required item
  1658. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1659. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1660. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1661. if(isUnitA)
  1662. {
  1663. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1664. 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++)
  1665. {
  1666. 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"));
  1667. 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?
  1668. 3:
  1669. 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")));
  1670. 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")));
  1671. }
  1672. }
  1673. else
  1674. {
  1675. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1676. 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++)
  1677. {
  1678. 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"));
  1679. 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?
  1680. 3:
  1681. 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")));
  1682. 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));
  1683. }
  1684. }
  1685. // Optional item
  1686. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1687. {
  1688. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1689. }
  1690. else
  1691. {
  1692. sprintf((char*)maxProfile.ValidFrom, " ");
  1693. }
  1694. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1695. {
  1696. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1697. }
  1698. else
  1699. {
  1700. sprintf((char*)maxProfile.ValidTo, " ");
  1701. }
  1702. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1703. {
  1704. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1705. }
  1706. else
  1707. {
  1708. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1709. }
  1710. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1711. {
  1712. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1713. }
  1714. else
  1715. {
  1716. maxProfile.TransactionId = -1;
  1717. }
  1718. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1719. {
  1720. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1721. }
  1722. else
  1723. {
  1724. maxProfile.ChargingSchedule.Duration = 86400;
  1725. }
  1726. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1727. {
  1728. 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")));
  1729. }
  1730. else
  1731. {
  1732. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1733. }
  1734. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1735. {
  1736. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1737. }
  1738. else
  1739. {
  1740. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1741. }
  1742. }
  1743. }
  1744. }
  1745. json_object_put(obj);
  1746. }
  1747. fclose(fp);
  1748. /*
  1749. if(maxProfile.ChargingProfileId !=-1)
  1750. {
  1751. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1752. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1753. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1754. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1755. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1756. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1757. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1758. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1759. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1760. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1761. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1762. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1763. {
  1764. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1765. {
  1766. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1767. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1768. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1769. }
  1770. }
  1771. }
  1772. else
  1773. DEBUG_INFO("MaxProfile not found.\n");
  1774. DEBUG_INFO("------------------------------------\n");*/
  1775. }
  1776. if(maxProfile.ChargingProfileId != -1)
  1777. {
  1778. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1779. {
  1780. if(maxProfile.ChargingSchedule.Duration != -1)
  1781. {
  1782. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1783. 0:
  1784. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1785. }
  1786. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1787. {
  1788. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1789. {
  1790. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1791. 0:
  1792. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1793. if(idxPeriod > 0)
  1794. {
  1795. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1796. {
  1797. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1798. }
  1799. }
  1800. }
  1801. }
  1802. }
  1803. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1804. {
  1805. if(maxProfile.ChargingSchedule.Duration != -1)
  1806. {
  1807. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1808. }
  1809. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1810. {
  1811. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1812. {
  1813. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1814. if(idxPeriod > 0)
  1815. {
  1816. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1817. {
  1818. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. else
  1825. {
  1826. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1827. {
  1828. if(maxProfile.ChargingSchedule.Duration != -1)
  1829. {
  1830. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1831. 0:
  1832. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1833. }
  1834. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1835. {
  1836. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1837. {
  1838. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1839. 0:
  1840. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1841. if(idxPeriod > 0)
  1842. {
  1843. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1844. {
  1845. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. else
  1852. {
  1853. if(maxProfile.ChargingSchedule.Duration != -1)
  1854. {
  1855. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1856. 0:
  1857. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1858. }
  1859. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1860. {
  1861. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1862. {
  1863. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1864. 0:
  1865. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1866. if(idxPeriod > 0)
  1867. {
  1868. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1869. {
  1870. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. /*
  1878. DEBUG_INFO("MaxProfile after align.\n");
  1879. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1880. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1881. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1882. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1883. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1884. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1885. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1886. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1887. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1888. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1889. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1890. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1891. {
  1892. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1893. {
  1894. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1895. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1896. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1897. }
  1898. }
  1899. DEBUG_INFO("------------------------------------\n");*/
  1900. }
  1901. // Find each profile period quantity
  1902. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1903. {
  1904. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1905. limitMax = idx+1;
  1906. }
  1907. if(maxProfile.ChargingProfileId != -1)
  1908. {
  1909. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1910. {
  1911. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1912. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1913. (maxProfile.ChargingSchedule.Duration > 0))
  1914. {
  1915. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1916. {
  1917. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1918. compositePeriodIdx++;
  1919. }
  1920. else
  1921. {
  1922. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1923. }
  1924. }
  1925. }
  1926. }
  1927. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1928. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1929. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1930. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1931. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1932. {
  1933. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1934. {
  1935. compositeProfile->ChargingProfileId = 1;
  1936. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1937. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1938. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1939. }
  1940. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1941. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1942. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1943. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1944. }
  1945. if(line)
  1946. free(line);
  1947. }
  1948. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1949. {
  1950. FILE *fp;
  1951. char profileFileName[128];
  1952. char *line = NULL;
  1953. size_t len = 0;
  1954. time_t CurrentTime;
  1955. struct tm *tmComposite;
  1956. struct StructChargingProfile maxProfile;
  1957. struct StructChargingProfile defaultTxProfile;
  1958. struct StructChargingProfile txProfile;
  1959. struct StructChargingSchedulePeriod tmpPeriod;
  1960. uint8_t limitMax=0;
  1961. uint8_t limitDef=0;
  1962. uint8_t limitTx=0;
  1963. int compositePeriodIdx = 0;
  1964. CurrentTime = time(NULL);
  1965. tmComposite=localtime(&CurrentTime);
  1966. 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);
  1967. if(isUnitA)
  1968. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1969. else
  1970. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1971. compositeProfile->ChargingSchedule.Duration = durationReq;
  1972. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1973. {
  1974. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1975. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1976. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1977. }
  1978. compositeProfile->ChargingProfileId = 0;
  1979. compositeProfile->StackLevel = 99 ;
  1980. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1981. maxProfile.ChargingProfileId = -1;
  1982. defaultTxProfile.ChargingProfileId = -1;
  1983. txProfile.ChargingProfileId = -1;
  1984. maxProfile.ChargingSchedule.Duration = -1;
  1985. defaultTxProfile.ChargingSchedule.Duration = -1;
  1986. txProfile.ChargingSchedule.Duration = -1;
  1987. system("rm -f /tmp/*.json");
  1988. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1989. /*
  1990. * Search valid charging profile
  1991. */
  1992. //DEBUG_INFO("====================================\n");
  1993. // Search tx profile
  1994. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1995. if((access(profileFileName, F_OK))!=-1)
  1996. {
  1997. fp = fopen(profileFileName, "r");
  1998. while(getline(&line, &len, fp) != -1)
  1999. {
  2000. json_object *obj = NULL;
  2001. obj = json_tokener_parse(line);
  2002. if(is_error(obj))
  2003. {
  2004. DEBUG_ERROR("Parse txProfile from file error.\n");
  2005. }
  2006. else
  2007. {
  2008. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2009. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2010. )
  2011. {
  2012. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2013. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2014. )
  2015. {
  2016. struct tm tmFrom, tmTo;
  2017. struct timeb tbFrom, tbTo;
  2018. 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) &&
  2019. (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))
  2020. {
  2021. tmFrom.tm_year -= 1900;
  2022. tmFrom.tm_mon -= 1;
  2023. tbFrom.time = mktime(&tmFrom);
  2024. tmTo.tm_year -= 1900;
  2025. tmTo.tm_mon -= 1;
  2026. tbTo.time = mktime(&tmTo);
  2027. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2028. {
  2029. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2030. {
  2031. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2032. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2033. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2034. }
  2035. txProfile.ChargingProfileId = -1;
  2036. txProfile.StackLevel = -1;
  2037. if(txProfile.ChargingProfileId == -1)
  2038. DEBUG_INFO("TxProfile found.\n");
  2039. else
  2040. DEBUG_INFO("TxProfile updated.\n");
  2041. // Required item
  2042. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2043. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2044. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2045. if(isUnitA)
  2046. {
  2047. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2048. 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++)
  2049. {
  2050. 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"));
  2051. 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?
  2052. 3:
  2053. 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")));
  2054. 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")));
  2055. }
  2056. }
  2057. else
  2058. {
  2059. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2060. 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++)
  2061. {
  2062. 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"));
  2063. 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?
  2064. 3:
  2065. 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")));
  2066. 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));
  2067. }
  2068. }
  2069. // Optional item
  2070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2071. {
  2072. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2073. }
  2074. else
  2075. {
  2076. sprintf((char*)txProfile.ValidFrom, " ");
  2077. }
  2078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2079. {
  2080. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2081. }
  2082. else
  2083. {
  2084. sprintf((char*)txProfile.ValidTo, " ");
  2085. }
  2086. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2087. {
  2088. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)txProfile.RecurrencyKind, " ");
  2093. }
  2094. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2095. {
  2096. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2097. }
  2098. else
  2099. {
  2100. txProfile.TransactionId = -1;
  2101. }
  2102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2103. {
  2104. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2105. }
  2106. else
  2107. {
  2108. txProfile.ChargingSchedule.Duration = 86400;
  2109. }
  2110. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2111. {
  2112. 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")));
  2113. }
  2114. else
  2115. {
  2116. 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));
  2117. }
  2118. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2119. {
  2120. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2121. }
  2122. else
  2123. {
  2124. txProfile.ChargingSchedule.MinChargingRate = -1;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. else
  2130. {
  2131. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2132. {
  2133. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2134. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2135. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2136. }
  2137. txProfile.ChargingProfileId = -1;
  2138. txProfile.StackLevel = -1;
  2139. if(txProfile.ChargingProfileId == -1)
  2140. DEBUG_INFO("TxProfile found.\n");
  2141. else
  2142. DEBUG_INFO("TxProfile updated.\n");
  2143. // Required item
  2144. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2145. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2146. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2147. if(isUnitA)
  2148. {
  2149. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2150. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2151. {
  2152. 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"));
  2153. 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?
  2154. 3:
  2155. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2156. 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")));
  2157. }
  2158. }
  2159. else
  2160. {
  2161. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2162. 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++)
  2163. {
  2164. 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"));
  2165. 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?
  2166. 3:
  2167. 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")));
  2168. 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));
  2169. }
  2170. }
  2171. // Optional item
  2172. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2173. {
  2174. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2175. }
  2176. else
  2177. {
  2178. sprintf((char*)txProfile.ValidFrom, " ");
  2179. }
  2180. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2181. {
  2182. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2183. }
  2184. else
  2185. {
  2186. sprintf((char*)txProfile.ValidTo, " ");
  2187. }
  2188. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2189. {
  2190. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2191. }
  2192. else
  2193. {
  2194. sprintf((char*)txProfile.RecurrencyKind, " ");
  2195. }
  2196. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2197. {
  2198. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2199. }
  2200. else
  2201. {
  2202. txProfile.TransactionId = -1;
  2203. }
  2204. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2205. {
  2206. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2207. }
  2208. else
  2209. {
  2210. txProfile.ChargingSchedule.Duration = 86400;
  2211. }
  2212. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2213. {
  2214. 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")));
  2215. }
  2216. else
  2217. {
  2218. 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));
  2219. }
  2220. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2221. {
  2222. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2223. }
  2224. else
  2225. {
  2226. txProfile.ChargingSchedule.MinChargingRate = -1;
  2227. }
  2228. }
  2229. }
  2230. }
  2231. json_object_put(obj);
  2232. }
  2233. fclose(fp);
  2234. /*
  2235. if(txProfile.ChargingProfileId != -1)
  2236. {
  2237. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2238. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2239. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2240. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2241. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2242. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2243. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2244. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2245. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2246. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2247. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2248. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2249. {
  2250. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2251. {
  2252. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2253. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2254. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2255. }
  2256. }
  2257. }
  2258. else
  2259. DEBUG_INFO("TxProfile not found.\n");*/
  2260. }
  2261. // Search default tx profile
  2262. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2263. if((access(profileFileName, F_OK))==-1)
  2264. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2265. if((access(profileFileName, F_OK))!=-1)
  2266. {
  2267. fp = fopen(profileFileName, "r");
  2268. while(getline(&line, &len, fp) != -1)
  2269. {
  2270. json_object *obj = NULL;
  2271. obj = json_tokener_parse(line);
  2272. if(is_error(obj))
  2273. {
  2274. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2275. }
  2276. else
  2277. {
  2278. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2279. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2280. )
  2281. {
  2282. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2283. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2284. )
  2285. {
  2286. struct tm tmFrom, tmTo;
  2287. struct timeb tbFrom, tbTo;
  2288. 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) &&
  2289. (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))
  2290. {
  2291. tmFrom.tm_year -= 1900;
  2292. tmFrom.tm_mon -= 1;
  2293. tbFrom.time = mktime(&tmFrom);
  2294. tmTo.tm_year -= 1900;
  2295. tmTo.tm_mon -= 1;
  2296. tbTo.time = mktime(&tmTo);
  2297. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2298. {
  2299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2300. {
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2302. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2303. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2304. }
  2305. defaultTxProfile.ChargingProfileId = -1;
  2306. defaultTxProfile.StackLevel = -1;
  2307. if(defaultTxProfile.ChargingProfileId == -1)
  2308. DEBUG_INFO("TxDefaultProfile found.\n");
  2309. else
  2310. DEBUG_INFO("TxDefaultProfile updated.\n");
  2311. // Required item
  2312. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2313. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2314. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2315. if(isUnitA)
  2316. {
  2317. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2318. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2319. {
  2320. 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"));
  2321. 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?
  2322. 3:
  2323. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2324. 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")));
  2325. }
  2326. }
  2327. else
  2328. {
  2329. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2330. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2331. {
  2332. 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"));
  2333. 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?
  2334. 3:
  2335. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2336. 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));
  2337. }
  2338. }
  2339. // Optional item
  2340. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2341. {
  2342. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2343. }
  2344. else
  2345. {
  2346. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2347. }
  2348. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2349. {
  2350. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2351. }
  2352. else
  2353. {
  2354. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2355. }
  2356. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2357. {
  2358. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2359. }
  2360. else
  2361. {
  2362. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2363. }
  2364. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2365. {
  2366. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2367. }
  2368. else
  2369. {
  2370. defaultTxProfile.TransactionId = -1;
  2371. }
  2372. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2373. {
  2374. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2375. }
  2376. else
  2377. {
  2378. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2379. }
  2380. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2381. {
  2382. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2383. }
  2384. else
  2385. {
  2386. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2387. }
  2388. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2389. {
  2390. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2391. }
  2392. else
  2393. {
  2394. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2395. }
  2396. }
  2397. }
  2398. }
  2399. else
  2400. {
  2401. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2402. {
  2403. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2404. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2405. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2406. }
  2407. defaultTxProfile.ChargingProfileId = -1;
  2408. defaultTxProfile.StackLevel = -1;
  2409. if(defaultTxProfile.ChargingProfileId == -1)
  2410. DEBUG_INFO("TxDefaultProfile found.\n");
  2411. else
  2412. DEBUG_INFO("TxDefaultProfile updated.\n");
  2413. // Required item
  2414. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2415. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2416. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2417. if(isUnitA)
  2418. {
  2419. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2420. 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++)
  2421. {
  2422. 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"));
  2423. 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?
  2424. 3:
  2425. 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")));
  2426. 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")));
  2427. }
  2428. }
  2429. else
  2430. {
  2431. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2432. 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++)
  2433. {
  2434. 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"));
  2435. 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?
  2436. 3:
  2437. 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")));
  2438. 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));
  2439. }
  2440. }
  2441. // Optional item
  2442. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2443. {
  2444. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2445. }
  2446. else
  2447. {
  2448. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2449. }
  2450. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2451. {
  2452. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2453. }
  2454. else
  2455. {
  2456. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2457. }
  2458. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2459. {
  2460. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2461. }
  2462. else
  2463. {
  2464. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2465. }
  2466. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2467. {
  2468. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2469. }
  2470. else
  2471. {
  2472. defaultTxProfile.TransactionId = -1;
  2473. }
  2474. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2475. {
  2476. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2477. }
  2478. else
  2479. {
  2480. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2481. }
  2482. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2483. {
  2484. 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")));
  2485. }
  2486. else
  2487. {
  2488. 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));
  2489. }
  2490. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2491. {
  2492. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2493. }
  2494. else
  2495. {
  2496. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2497. }
  2498. }
  2499. }
  2500. }
  2501. json_object_put(obj);
  2502. }
  2503. fclose(fp);
  2504. /*
  2505. if(defaultTxProfile.ChargingProfileId != -1)
  2506. {
  2507. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2508. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2509. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2510. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2511. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2512. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2513. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2514. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2515. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2516. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2517. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2518. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2519. {
  2520. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2521. {
  2522. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2523. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2524. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2525. }
  2526. }
  2527. }
  2528. else
  2529. DEBUG_INFO("TxDefaultProfile not found.\n");
  2530. DEBUG_INFO("------------------------------------\n");*/
  2531. }
  2532. // Search max profile
  2533. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2534. if((access(profileFileName, F_OK))!=-1)
  2535. {
  2536. fp = fopen(profileFileName, "r");
  2537. while(getline(&line, &len, fp) != -1)
  2538. {
  2539. json_object *obj = NULL;
  2540. obj = json_tokener_parse(line);
  2541. if(is_error(obj))
  2542. {
  2543. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2544. }
  2545. else
  2546. {
  2547. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2548. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2549. )
  2550. {
  2551. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2552. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2553. )
  2554. {
  2555. struct tm tmFrom, tmTo;
  2556. struct timeb tbFrom, tbTo;
  2557. 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) &&
  2558. (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))
  2559. {
  2560. tmFrom.tm_year -= 1900;
  2561. tmFrom.tm_mon -= 1;
  2562. tbFrom.time = mktime(&tmFrom);
  2563. tmTo.tm_year -= 1900;
  2564. tmTo.tm_mon -= 1;
  2565. tbTo.time = mktime(&tmTo);
  2566. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2567. {
  2568. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2569. {
  2570. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2573. }
  2574. maxProfile.ChargingProfileId = -1;
  2575. maxProfile.StackLevel = -1;
  2576. if(maxProfile.ChargingProfileId == -1)
  2577. DEBUG_INFO("MaxProfile found.\n");
  2578. else
  2579. DEBUG_INFO("MaxProfile updated.\n");
  2580. // Required item
  2581. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2582. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2583. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2584. if(isUnitA)
  2585. {
  2586. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2587. 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++)
  2588. {
  2589. 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"));
  2590. 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?
  2591. 3:
  2592. 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")));
  2593. 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")));
  2594. }
  2595. }
  2596. else
  2597. {
  2598. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2599. 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++)
  2600. {
  2601. 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"));
  2602. 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?
  2603. 3:
  2604. 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")));
  2605. 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));
  2606. }
  2607. }
  2608. // Optional item
  2609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2610. {
  2611. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2612. }
  2613. else
  2614. {
  2615. sprintf((char*)maxProfile.ValidFrom, " ");
  2616. }
  2617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2618. {
  2619. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2620. }
  2621. else
  2622. {
  2623. sprintf((char*)maxProfile.ValidTo, " ");
  2624. }
  2625. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2626. {
  2627. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2628. }
  2629. else
  2630. {
  2631. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2632. }
  2633. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2634. {
  2635. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2636. }
  2637. else
  2638. {
  2639. maxProfile.TransactionId = -1;
  2640. }
  2641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2642. {
  2643. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2644. }
  2645. else
  2646. {
  2647. maxProfile.ChargingSchedule.Duration = 86400;
  2648. }
  2649. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2650. {
  2651. 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")));
  2652. }
  2653. else
  2654. {
  2655. 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));
  2656. }
  2657. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2658. {
  2659. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2660. }
  2661. else
  2662. {
  2663. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2664. }
  2665. }
  2666. }
  2667. }
  2668. else
  2669. {
  2670. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2671. {
  2672. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2673. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2674. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2675. }
  2676. maxProfile.ChargingProfileId = -1;
  2677. maxProfile.StackLevel = -1;
  2678. if(maxProfile.ChargingProfileId == -1)
  2679. DEBUG_INFO("MaxProfile found.\n");
  2680. else
  2681. DEBUG_INFO("MaxProfile updated.\n");
  2682. // Required item
  2683. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2684. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2685. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2686. if(isUnitA)
  2687. {
  2688. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2689. 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++)
  2690. {
  2691. 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"));
  2692. 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?
  2693. 3:
  2694. 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")));
  2695. 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")));
  2696. }
  2697. }
  2698. else
  2699. {
  2700. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2701. 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++)
  2702. {
  2703. 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"));
  2704. 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?
  2705. 3:
  2706. 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")));
  2707. 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));
  2708. }
  2709. }
  2710. // Optional item
  2711. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2712. {
  2713. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2714. }
  2715. else
  2716. {
  2717. sprintf((char*)maxProfile.ValidFrom, " ");
  2718. }
  2719. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2720. {
  2721. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2722. }
  2723. else
  2724. {
  2725. sprintf((char*)maxProfile.ValidTo, " ");
  2726. }
  2727. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2728. {
  2729. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2730. }
  2731. else
  2732. {
  2733. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2734. }
  2735. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2736. {
  2737. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2738. }
  2739. else
  2740. {
  2741. maxProfile.TransactionId = -1;
  2742. }
  2743. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2744. {
  2745. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2746. }
  2747. else
  2748. {
  2749. maxProfile.ChargingSchedule.Duration = 86400;
  2750. }
  2751. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2752. {
  2753. 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")));
  2754. }
  2755. else
  2756. {
  2757. 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));
  2758. }
  2759. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2760. {
  2761. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2762. }
  2763. else
  2764. {
  2765. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2766. }
  2767. }
  2768. }
  2769. }
  2770. json_object_put(obj);
  2771. }
  2772. fclose(fp);
  2773. /*
  2774. if(maxProfile.ChargingProfileId !=-1)
  2775. {
  2776. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2777. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2778. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2779. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2780. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2781. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2782. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2783. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2784. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2785. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2786. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2787. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2788. {
  2789. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2790. {
  2791. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2792. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2793. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2794. }
  2795. }
  2796. }
  2797. else
  2798. DEBUG_INFO("MaxProfile not found.\n");
  2799. DEBUG_INFO("------------------------------------\n");*/
  2800. }
  2801. /*
  2802. * Align found profile start schedule & periods
  2803. */
  2804. //DEBUG_INFO("====================================\n");
  2805. /*
  2806. // For local test usage, force modify found profile start schedule info
  2807. 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);
  2808. 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);
  2809. 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);
  2810. */
  2811. if(txProfile.ChargingProfileId != -1)
  2812. {
  2813. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2814. {
  2815. if(txProfile.ChargingSchedule.Duration != -1)
  2816. {
  2817. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2818. 0:
  2819. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2820. }
  2821. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2822. {
  2823. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2824. {
  2825. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2826. 0:
  2827. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2828. if(idxPeriod > 0)
  2829. {
  2830. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2831. {
  2832. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2833. }
  2834. }
  2835. }
  2836. }
  2837. }
  2838. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2839. {
  2840. if(txProfile.ChargingSchedule.Duration != -1)
  2841. {
  2842. 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?
  2843. 0:
  2844. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2845. }
  2846. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2847. {
  2848. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2849. {
  2850. 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?
  2851. 0:
  2852. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2853. if(idxPeriod > 0)
  2854. {
  2855. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2856. {
  2857. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2858. }
  2859. }
  2860. }
  2861. }
  2862. }
  2863. else
  2864. {
  2865. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2866. {
  2867. if(txProfile.ChargingSchedule.Duration != -1)
  2868. {
  2869. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2870. 0:
  2871. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2872. }
  2873. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2874. {
  2875. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2876. {
  2877. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2878. 0:
  2879. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2880. if(idxPeriod > 0)
  2881. {
  2882. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2883. {
  2884. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2885. }
  2886. }
  2887. }
  2888. }
  2889. }
  2890. else
  2891. {
  2892. if(txProfile.ChargingSchedule.Duration != -1)
  2893. {
  2894. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2895. 0:
  2896. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2897. }
  2898. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2899. {
  2900. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2901. {
  2902. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2903. 0:
  2904. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2905. if(idxPeriod > 0)
  2906. {
  2907. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2908. {
  2909. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. /*
  2917. DEBUG_INFO("txProfile after align.\n");
  2918. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2919. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2920. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2921. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2922. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2923. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2924. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2925. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2926. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2927. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2928. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2929. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2930. {
  2931. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2932. {
  2933. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2934. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2935. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2936. }
  2937. }*/
  2938. }
  2939. if(defaultTxProfile.ChargingProfileId != -1)
  2940. {
  2941. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2942. {
  2943. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2944. {
  2945. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2946. 0:
  2947. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2948. }
  2949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2950. {
  2951. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2952. {
  2953. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2954. 0:
  2955. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2956. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2957. {
  2958. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2959. }
  2960. if(idxPeriod > 0)
  2961. {
  2962. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2963. {
  2964. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2965. }
  2966. }
  2967. }
  2968. }
  2969. }
  2970. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2971. {
  2972. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2973. {
  2974. 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?
  2975. 0:
  2976. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2977. }
  2978. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2979. {
  2980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2981. {
  2982. 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?
  2983. 0:
  2984. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2985. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2986. {
  2987. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2988. }
  2989. if(idxPeriod > 0)
  2990. {
  2991. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2992. {
  2993. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2994. }
  2995. }
  2996. }
  2997. }
  2998. }
  2999. else
  3000. {
  3001. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3002. {
  3003. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3004. {
  3005. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3006. 0:
  3007. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3008. }
  3009. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3010. {
  3011. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3012. {
  3013. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3014. 0:
  3015. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3016. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3017. {
  3018. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3019. }
  3020. if(idxPeriod > 0)
  3021. {
  3022. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3023. {
  3024. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3025. }
  3026. }
  3027. }
  3028. }
  3029. }
  3030. else
  3031. {
  3032. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3033. {
  3034. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3035. 0:
  3036. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3037. }
  3038. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3039. {
  3040. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3041. {
  3042. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3043. 0:
  3044. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3045. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3046. {
  3047. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3048. }
  3049. if(idxPeriod > 0)
  3050. {
  3051. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3052. {
  3053. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3054. }
  3055. }
  3056. }
  3057. }
  3058. }
  3059. }
  3060. /*
  3061. DEBUG_INFO("defaultTxProfile after align.\n");
  3062. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3063. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3064. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3065. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3066. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3067. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3068. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3069. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3070. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3071. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3072. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3073. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3074. {
  3075. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3076. {
  3077. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3078. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3079. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3080. }
  3081. }
  3082. DEBUG_INFO("------------------------------------\n");*/
  3083. }
  3084. if(maxProfile.ChargingProfileId != -1)
  3085. {
  3086. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3087. {
  3088. if(maxProfile.ChargingSchedule.Duration != -1)
  3089. {
  3090. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3091. 0:
  3092. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3093. }
  3094. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3095. {
  3096. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3097. {
  3098. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3099. 0:
  3100. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3101. if(idxPeriod > 0)
  3102. {
  3103. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3104. {
  3105. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3106. }
  3107. }
  3108. }
  3109. }
  3110. }
  3111. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3112. {
  3113. if(maxProfile.ChargingSchedule.Duration != -1)
  3114. {
  3115. 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?
  3116. 0:
  3117. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3118. }
  3119. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3120. {
  3121. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3122. {
  3123. 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?
  3124. 0:
  3125. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3126. if(idxPeriod > 0)
  3127. {
  3128. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3129. {
  3130. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. else
  3137. {
  3138. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3139. {
  3140. if(maxProfile.ChargingSchedule.Duration != -1)
  3141. {
  3142. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3143. 0:
  3144. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3145. }
  3146. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3147. {
  3148. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3149. {
  3150. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3151. 0:
  3152. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3153. if(idxPeriod > 0)
  3154. {
  3155. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3156. {
  3157. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3158. }
  3159. }
  3160. }
  3161. }
  3162. }
  3163. else
  3164. {
  3165. if(maxProfile.ChargingSchedule.Duration != -1)
  3166. {
  3167. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3168. 0:
  3169. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3170. }
  3171. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3172. {
  3173. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3174. {
  3175. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3176. 0:
  3177. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3178. if(idxPeriod > 0)
  3179. {
  3180. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3181. {
  3182. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3183. }
  3184. }
  3185. }
  3186. }
  3187. }
  3188. }
  3189. /*
  3190. DEBUG_INFO("MaxProfile after align.\n");
  3191. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3192. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3193. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3194. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3195. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3196. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3197. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3198. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3199. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3200. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3201. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3202. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3203. {
  3204. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3205. {
  3206. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3207. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3208. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3209. }
  3210. }
  3211. DEBUG_INFO("------------------------------------\n");*/
  3212. }
  3213. /*
  3214. * Merge to conposite schedule
  3215. */
  3216. //DEBUG_INFO("====================================\n");
  3217. // Find each profile period quantity
  3218. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3219. {
  3220. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3221. limitMax = idx+1;
  3222. }
  3223. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3224. {
  3225. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3226. limitDef = idx+1;
  3227. }
  3228. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3229. {
  3230. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3231. limitTx = idx+1;
  3232. }
  3233. // TxProfile found, composite schedule based on it
  3234. if(txProfile.ChargingProfileId != -1)
  3235. {
  3236. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3237. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3238. {
  3239. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3240. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3241. (txProfile.ChargingSchedule.Duration > 0))
  3242. {
  3243. if(maxProfile.ChargingProfileId != -1)
  3244. {
  3245. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3246. {
  3247. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3248. {
  3249. if((maxProfile.ChargingSchedule.Duration > 0))
  3250. {
  3251. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3252. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3253. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3254. }
  3255. else
  3256. {
  3257. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3258. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3259. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3260. }
  3261. }
  3262. if(idxMaxPeriod == (limitMax-1))
  3263. {
  3264. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3265. {
  3266. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3267. {
  3268. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3269. compositePeriodIdx++;
  3270. }
  3271. else
  3272. {
  3273. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3274. }
  3275. }
  3276. }
  3277. }
  3278. }
  3279. else
  3280. {
  3281. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3282. {
  3283. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3284. compositePeriodIdx++;
  3285. }
  3286. else
  3287. {
  3288. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3289. }
  3290. }
  3291. }
  3292. if(idxTxPeriod == (limitTx-1))
  3293. {
  3294. if(defaultTxProfile.ChargingProfileId != -1)
  3295. {
  3296. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3297. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3298. {
  3299. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3300. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3301. (defaultTxProfile.ChargingSchedule.Duration>0))
  3302. {
  3303. if(maxProfile.ChargingProfileId != -1)
  3304. {
  3305. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3306. {
  3307. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3308. {
  3309. if((maxProfile.ChargingSchedule.Duration > 0))
  3310. {
  3311. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3312. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3313. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3314. }
  3315. else
  3316. {
  3317. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3318. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3319. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3320. }
  3321. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3322. {
  3323. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3324. {
  3325. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3326. compositePeriodIdx++;
  3327. }
  3328. else
  3329. {
  3330. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3331. }
  3332. }
  3333. // Delete duplicate period
  3334. if(compositePeriodIdx > 1)
  3335. {
  3336. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3337. {
  3338. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3339. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3340. compositePeriodIdx -= 1;
  3341. }
  3342. }
  3343. }
  3344. else
  3345. {
  3346. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3347. {
  3348. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3349. compositePeriodIdx++;
  3350. }
  3351. else
  3352. {
  3353. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3354. }
  3355. break;
  3356. }
  3357. }
  3358. }
  3359. else
  3360. {
  3361. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3362. {
  3363. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3364. compositePeriodIdx++;
  3365. }
  3366. else
  3367. {
  3368. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3369. }
  3370. }
  3371. }
  3372. }
  3373. }
  3374. }
  3375. }
  3376. }
  3377. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3378. else if(defaultTxProfile.ChargingProfileId != -1)
  3379. {
  3380. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3381. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3382. {
  3383. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3384. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3385. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3386. {
  3387. if(maxProfile.ChargingProfileId != -1)
  3388. {
  3389. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3390. {
  3391. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3392. {
  3393. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3394. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3395. if((maxProfile.ChargingSchedule.Duration > 0))
  3396. {
  3397. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3398. }
  3399. else
  3400. {
  3401. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3402. }
  3403. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3404. {
  3405. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3406. {
  3407. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3408. compositePeriodIdx++;
  3409. }
  3410. else
  3411. {
  3412. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3413. }
  3414. }
  3415. // Delete duplicate period
  3416. if(compositePeriodIdx > 1)
  3417. {
  3418. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3419. {
  3420. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3421. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3422. compositePeriodIdx -= 1;
  3423. }
  3424. }
  3425. }
  3426. else
  3427. {
  3428. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3429. {
  3430. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3431. compositePeriodIdx++;
  3432. }
  3433. else
  3434. {
  3435. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3436. }
  3437. break;
  3438. }
  3439. }
  3440. }
  3441. else
  3442. {
  3443. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3444. {
  3445. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3446. compositePeriodIdx++;
  3447. }
  3448. else
  3449. {
  3450. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3451. }
  3452. }
  3453. }
  3454. }
  3455. }
  3456. // Fill other period by MaxProfile
  3457. if(maxProfile.ChargingProfileId != -1)
  3458. {
  3459. if(compositePeriodIdx==0)
  3460. {
  3461. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3462. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3463. {
  3464. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3465. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3466. (maxProfile.ChargingSchedule.Duration > 0))
  3467. {
  3468. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3469. {
  3470. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3471. compositePeriodIdx++;
  3472. }
  3473. else
  3474. {
  3475. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3476. }
  3477. }
  3478. }
  3479. }
  3480. else
  3481. {
  3482. int lastCompositePeriodIdx = compositePeriodIdx;
  3483. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3484. {
  3485. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3486. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3487. (maxProfile.ChargingSchedule.Duration > 0))
  3488. {
  3489. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3490. {
  3491. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3492. {
  3493. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3494. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3495. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3496. }
  3497. else
  3498. {
  3499. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3500. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3501. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3502. }
  3503. }
  3504. if(tmpPeriod.Limit != -1)
  3505. {
  3506. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3507. {
  3508. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3509. {
  3510. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3511. compositePeriodIdx++;
  3512. }
  3513. else
  3514. {
  3515. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3516. }
  3517. }
  3518. // Delete duplicate period
  3519. if(compositePeriodIdx > 1)
  3520. {
  3521. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3522. {
  3523. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3524. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3525. compositePeriodIdx -= 1;
  3526. }
  3527. }
  3528. }
  3529. }
  3530. }
  3531. }
  3532. }
  3533. compositeProfile->ChargingSchedule.Duration = durationReq;
  3534. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3535. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3536. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3537. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3538. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3539. {
  3540. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3541. {
  3542. compositeProfile->ChargingProfileId = 1;
  3543. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3544. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3545. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3546. }
  3547. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3548. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3549. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3550. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3551. }
  3552. if(line)
  3553. free(line);
  3554. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3555. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3556. }
  3557. //==========================================
  3558. // Init all share memory
  3559. //==========================================
  3560. int InitShareMemory()
  3561. {
  3562. int result = PASS;
  3563. int MeterSMId;
  3564. //creat ShmSysConfigAndInfo
  3565. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3566. {
  3567. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3568. result = FAIL;
  3569. }
  3570. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3571. {
  3572. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3573. result = FAIL;
  3574. }
  3575. else
  3576. {}
  3577. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3578. {
  3579. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3580. result = FAIL;
  3581. }
  3582. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3583. {
  3584. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3585. result = FAIL;
  3586. }
  3587. else
  3588. {}
  3589. //creat ShmPsuData
  3590. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3591. {
  3592. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3593. result = FAIL;
  3594. }
  3595. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3596. {
  3597. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3598. result = FAIL;
  3599. }
  3600. else
  3601. {}
  3602. //creat ShmOCPP16Data
  3603. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3604. {
  3605. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3606. result = FAIL;
  3607. }
  3608. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3609. {
  3610. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3611. result = FAIL;
  3612. }
  3613. else
  3614. {}
  3615. /****************************** For Initial Settings************************************************/
  3616. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3617. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3618. // allocate Configuration memory address
  3619. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3620. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3621. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3622. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3623. //offline MeterValue Interval
  3624. TempMeterValueInterval = 0;
  3625. return result;
  3626. }
  3627. int ProcessShareMemory()
  3628. {
  3629. int result = PASS;
  3630. if(InitShareMemory() == FAIL)
  3631. {
  3632. DEBUG_ERROR("InitShareMemory NG\n");
  3633. if(ShmStatusCodeData!=NULL)
  3634. {
  3635. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3636. }
  3637. result = FAIL;
  3638. }
  3639. // Model name parsing
  3640. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3641. {
  3642. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3643. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3644. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3645. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3646. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3647. ) // 'D' means DC
  3648. {
  3649. // DO series
  3650. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3651. {
  3652. SystemInitial += 1;
  3653. gunTotalNumber += 1;
  3654. gunType[gun_index] = GUN_TYPE_DO;
  3655. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3656. {
  3657. case Gun_Type_Chademo:
  3658. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3659. break;
  3660. case Gun_Type_CCS_2:
  3661. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3662. break;
  3663. case Gun_Type_GB:
  3664. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3665. break;
  3666. case Gun_Type_AC:
  3667. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3668. break;
  3669. default:
  3670. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3671. break;
  3672. }
  3673. }
  3674. }
  3675. else
  3676. {
  3677. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3678. {
  3679. SystemInitial += 1;
  3680. gunTotalNumber += 1;
  3681. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3682. {
  3683. case Gun_Type_Chademo:
  3684. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3685. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3686. break;
  3687. case Gun_Type_CCS_2:
  3688. gunType[gun_index] = GUN_TYPE_CCS;
  3689. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3690. break;
  3691. case Gun_Type_GB:
  3692. gunType[gun_index] = GUN_TYPE_GBT;
  3693. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3694. break;
  3695. case Gun_Type_AC:
  3696. gunType[gun_index] = GUN_TYPE_AC;
  3697. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3698. break;
  3699. default:
  3700. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3701. break;
  3702. }
  3703. }
  3704. }
  3705. }
  3706. else
  3707. {
  3708. DEBUG_ERROR("Model name parsing fail.\n");
  3709. result = FAIL;
  3710. }
  3711. if(result != PASS)sleep(5);
  3712. return result;
  3713. }
  3714. void checkRemoteStart(uint8_t connectorIdInt)
  3715. {
  3716. uint8_t tempIndex;
  3717. int result = PASS;
  3718. char cmdBuf[512];
  3719. //check Transaction active
  3720. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3721. {
  3722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3723. {
  3724. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3725. }
  3726. else
  3727. {
  3728. tempIndex = connectorIdInt -1;
  3729. }
  3730. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3731. {
  3732. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3733. {
  3734. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3735. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3736. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3737. {
  3738. //Reserved
  3739. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3740. }
  3741. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3742. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3743. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3744. {
  3745. //Reserved
  3746. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3747. result = FAIL;
  3748. goto end;
  3749. }
  3750. else
  3751. {
  3752. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3753. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3754. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3755. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3756. {
  3757. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3758. result = FAIL;
  3759. goto end;
  3760. }
  3761. }//END FOR ELSE
  3762. }
  3763. }// END FOR CHAdeMO_QUANTITY
  3764. }
  3765. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3766. {
  3767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3768. {
  3769. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3770. }
  3771. else
  3772. {
  3773. tempIndex = connectorIdInt -1;
  3774. }
  3775. for (int index = 0; index < CCS_QUANTITY; index++)
  3776. {
  3777. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3778. {
  3779. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3780. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3781. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3782. {
  3783. //Reserved
  3784. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3785. }
  3786. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3787. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3788. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3789. {
  3790. //Reserved
  3791. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3792. result = FAIL;
  3793. goto end;
  3794. }
  3795. else
  3796. {
  3797. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3798. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3799. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3800. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3801. {
  3802. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3803. result = FAIL;
  3804. goto end;
  3805. }
  3806. }// END FOR ELSE
  3807. }
  3808. }// END FOR CCS_QUANTITY
  3809. }
  3810. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3811. {
  3812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3813. {
  3814. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3815. }
  3816. else
  3817. {
  3818. tempIndex = connectorIdInt -1;
  3819. }
  3820. for (int index = 0; index < GB_QUANTITY; index++)
  3821. {
  3822. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3823. {
  3824. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3825. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3826. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3827. {
  3828. //Reserved
  3829. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3830. }
  3831. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3832. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3833. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3834. {
  3835. //Reserved
  3836. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3837. result = FAIL;
  3838. goto end;
  3839. }
  3840. else
  3841. {
  3842. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3843. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3844. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3845. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3846. {
  3847. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3848. result = FAIL;
  3849. goto end;
  3850. }
  3851. }// END FOR ELSE
  3852. }
  3853. } // END FOR GB_QUANTITY
  3854. }
  3855. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3856. {
  3857. tempIndex = connectorIdInt -1;
  3858. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3859. {
  3860. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3861. {
  3862. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3863. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3864. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3865. {
  3866. //Reserved
  3867. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3868. }
  3869. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3870. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3871. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3872. {
  3873. //Reserved
  3874. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3875. result = FAIL;
  3876. goto end;
  3877. }
  3878. else
  3879. {
  3880. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3881. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3882. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3883. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3884. {
  3885. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3886. result = FAIL;
  3887. goto end;
  3888. }
  3889. }// END FOR ELSE
  3890. }
  3891. } // END FOR GB_QUANTITY
  3892. }
  3893. else
  3894. {
  3895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3896. {
  3897. tempIndex = 2;
  3898. }
  3899. else
  3900. {
  3901. tempIndex = connectorIdInt -1;
  3902. }
  3903. for (int index = 0; index < AC_QUANTITY; index++)
  3904. {
  3905. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3906. {
  3907. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3908. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3909. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3910. {
  3911. //Reserved
  3912. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3913. }
  3914. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3915. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3916. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3917. {
  3918. //Reserved
  3919. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3920. result = FAIL;
  3921. goto end;
  3922. }
  3923. else
  3924. {
  3925. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3926. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3927. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3928. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3929. {
  3930. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3931. result = FAIL;
  3932. goto end;
  3933. }
  3934. }//END FOR ELSE
  3935. }
  3936. }// END FOR AC_QUANTITY
  3937. }
  3938. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3939. {
  3940. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3941. {
  3942. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3943. {
  3944. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3945. system(cmdBuf);
  3946. }
  3947. }
  3948. else
  3949. {
  3950. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3951. result = FAIL;
  3952. }
  3953. }
  3954. end:
  3955. if(result == PASS)
  3956. {
  3957. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3958. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3959. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3960. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3961. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3962. }
  3963. }
  3964. void CheckSystemValue(void)
  3965. {
  3966. char filenmae[100]={0};
  3967. char str[100]={0};
  3968. int tempIndex = 0;
  3969. //===============================
  3970. // send Heartbeat
  3971. //===============================
  3972. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3973. {
  3974. //parameter for test
  3975. sendHeartbeatRequest(0);
  3976. //===========================
  3977. // Reset Waiting Time
  3978. //===========================
  3979. HeartBeatWithNOResponse += 1;
  3980. }
  3981. //===============================
  3982. // Credit deduct report
  3983. //===============================
  3984. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  3985. {
  3986. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  3987. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  3988. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  3989. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  3990. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  3991. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  3992. }
  3993. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3994. {
  3995. OCPP_query_deduct_info();
  3996. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3997. }
  3998. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3999. {
  4000. // ClockAlign MeterValue
  4001. 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))
  4002. {
  4003. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4004. {
  4005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4006. {
  4007. tempIndex = ((gun_index==2) ? 1: 0);
  4008. }
  4009. else
  4010. {
  4011. tempIndex = gun_index;
  4012. }
  4013. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4014. {
  4015. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4016. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4017. {
  4018. reqClockAlignMeter[gun_index] = 1;
  4019. }
  4020. }// End for CHAdeMO
  4021. }
  4022. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4023. {
  4024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4025. {
  4026. tempIndex = ((gun_index==2) ? 1: 0);
  4027. }
  4028. else
  4029. {
  4030. tempIndex = gun_index;
  4031. }
  4032. for (int index = 0; index < CCS_QUANTITY; index++)
  4033. {
  4034. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4035. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4036. {
  4037. reqClockAlignMeter[gun_index] = 1;
  4038. }
  4039. } // End for CCS
  4040. }
  4041. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4042. {
  4043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4044. {
  4045. tempIndex = ((gun_index==2) ? 1: 0);
  4046. }
  4047. else
  4048. {
  4049. tempIndex = gun_index;
  4050. }
  4051. for (int index = 0; index < GB_QUANTITY; index++)
  4052. {
  4053. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4054. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4055. {
  4056. reqClockAlignMeter[gun_index] = 1;
  4057. }
  4058. }// End for GB
  4059. }
  4060. else if(gunType[gun_index] == GUN_TYPE_DO)
  4061. {
  4062. tempIndex = gun_index;
  4063. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4064. {
  4065. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4066. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4067. {
  4068. reqClockAlignMeter[gun_index] = 1;
  4069. }
  4070. }
  4071. }
  4072. else
  4073. {
  4074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4075. {
  4076. tempIndex = 2;
  4077. }
  4078. else
  4079. {
  4080. tempIndex = gun_index;
  4081. }
  4082. for (int index = 0; index < AC_QUANTITY; index++)
  4083. {
  4084. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4085. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4086. {
  4087. reqClockAlignMeter[gun_index] = 1;
  4088. }
  4089. }//End for AC
  4090. }
  4091. }
  4092. }
  4093. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4094. {
  4095. //==========================================
  4096. // Check remote start without connector id
  4097. //==========================================
  4098. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4099. {
  4100. int connectorIdInt = -1;
  4101. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4102. {
  4103. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4104. {
  4105. connectorIdInt = (gun_index+1);
  4106. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4107. checkRemoteStart(connectorIdInt);
  4108. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4109. break;
  4110. }
  4111. }
  4112. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4113. {
  4114. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4115. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4116. }
  4117. }
  4118. //==========================================
  4119. // csu trigger DataTransferReq
  4120. //==========================================
  4121. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4122. {
  4123. sendDataTransferRequest(gun_index);
  4124. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4125. }
  4126. //==========================================
  4127. // CSU Trigger Authorize Request
  4128. //==========================================
  4129. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4130. {
  4131. sendAuthorizeRequest(0);
  4132. authorizeRetryTimes = authorizeRetryTimes + 1;
  4133. if(authorizeRetryTimes < 3)
  4134. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4135. }
  4136. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4137. {
  4138. authorizeRetryTimes = 0;
  4139. SetOcppConnStatus(FALSE);
  4140. server_sign = FALSE;
  4141. }
  4142. 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))
  4143. {
  4144. sendAuthorizeRequest(0);
  4145. }
  4146. //==========================================
  4147. // Charger start transaction
  4148. //==========================================
  4149. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4150. {
  4151. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4152. sendStartTransactionRequest(gun_index);
  4153. refreshStartTimer(&clientTime.StartTransaction);
  4154. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4155. storeTempStopTransaction(gun_index);
  4156. }
  4157. //==========================================
  4158. // Charger stop transaction
  4159. //==========================================
  4160. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4161. {
  4162. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4163. sendStopTransactionRequest(gun_index);
  4164. OCPP_updatePeriodEnergy(gun_index);
  4165. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4166. refreshStartTimer(&clientTime.StopTransaction);
  4167. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4168. }
  4169. //==========================================
  4170. // Charger status report
  4171. //==========================================
  4172. //--- Check Mode Change ---//
  4173. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4174. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  4185. {
  4186. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4187. {
  4188. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4189. {
  4190. // Sent unplug message for California pricing logic
  4191. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4201. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4202. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4203. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4215. #if 1 // for TempStopTransaction
  4216. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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_CCS)
  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 < CCS_QUANTITY; index++)
  4236. {
  4237. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4238. {
  4239. 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]*/ )
  4240. {
  4241. // Sent unplug message for California pricing logic
  4242. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[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. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4252. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4253. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4254. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[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.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4266. #if 1 // for TempStopTransaction
  4267. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[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_GBT)
  4277. {
  4278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4279. {
  4280. tempIndex = ((gun_index==2) ? 1: 0);
  4281. }
  4282. else
  4283. {
  4284. tempIndex = gun_index;
  4285. }
  4286. for (int index = 0; index < GB_QUANTITY; index++)
  4287. {
  4288. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4289. {
  4290. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4291. {
  4292. // Sent unplug message for California pricing logic
  4293. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4294. {
  4295. uint8_t ts[20];
  4296. getNowDatetime(ts);
  4297. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4298. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4299. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4300. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4301. }
  4302. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4303. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4304. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4305. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4306. {
  4307. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4308. if((access(filenmae,F_OK))!=-1)
  4309. {
  4310. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4311. sprintf(str,"rm -f %s",filenmae);
  4312. system(str);
  4313. }
  4314. }
  4315. }
  4316. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4317. #if 1 // for TempStopTransaction
  4318. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4319. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4320. {
  4321. checkTempStopTransaction(gun_index);
  4322. }
  4323. #endif
  4324. }
  4325. }
  4326. }
  4327. else if(gunType[gun_index] == GUN_TYPE_DO)
  4328. {
  4329. tempIndex = gun_index;
  4330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4331. {
  4332. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4333. {
  4334. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4335. {
  4336. // Sent unplug message for California pricing logic
  4337. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  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. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4347. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4348. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4349. 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
  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.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4361. #if 1 // for TempStopTransaction
  4362. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4363. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4364. {
  4365. checkTempStopTransaction(gun_index);
  4366. }
  4367. #endif
  4368. }
  4369. }
  4370. }
  4371. else
  4372. {
  4373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4374. {
  4375. tempIndex = 2;
  4376. }
  4377. else
  4378. {
  4379. tempIndex = gun_index;
  4380. }
  4381. for (int index = 0; index < AC_QUANTITY; index++)
  4382. {
  4383. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4384. {
  4385. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4386. {
  4387. // Sent unplug message for California pricing logic
  4388. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4389. {
  4390. uint8_t ts[20];
  4391. getNowDatetime(ts);
  4392. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4393. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4394. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4395. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4396. }
  4397. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4398. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4399. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4400. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4401. {
  4402. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4403. if((access(filenmae,F_OK))!=-1)
  4404. {
  4405. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4406. sprintf(str,"rm -f %s",filenmae);
  4407. system(str);
  4408. }
  4409. }
  4410. }
  4411. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4412. #if 1 // for TempStopTransaction
  4413. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4414. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4415. {
  4416. checkTempStopTransaction(gun_index);
  4417. }
  4418. #endif
  4419. }
  4420. }// END
  4421. }
  4422. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4423. (
  4424. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4425. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4426. )
  4427. )
  4428. {
  4429. if(SystemInitial > 0)
  4430. SystemInitial -= 1;
  4431. sendStatusNotificationRequest(gun_index);
  4432. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4433. }
  4434. //==============================================
  4435. // CSU Trigger Smart Charging Profile
  4436. //==============================================
  4437. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4438. {
  4439. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4440. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4441. }
  4442. //==============================================
  4443. // Meter report
  4444. //==============================================
  4445. // Trigger MeterValue
  4446. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4447. {
  4448. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4449. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4450. }
  4451. // Clock-aligned Meter value
  4452. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4453. {
  4454. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4455. reqClockAlignMeter[gun_index] = 0;
  4456. }
  4457. // Sample period MeterValue
  4458. 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))))
  4459. {
  4460. //check Transaction active
  4461. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4462. {
  4463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4464. {
  4465. tempIndex = ((gun_index==2) ? 1: 0);
  4466. }
  4467. else
  4468. {
  4469. tempIndex = gun_index;
  4470. }
  4471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4472. {
  4473. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4474. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4475. {
  4476. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4477. {
  4478. reqSampleMeter[gun_index] = 1;
  4479. }
  4480. }
  4481. }// End for CHAdeMO
  4482. }
  4483. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4484. {
  4485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4486. {
  4487. tempIndex = ((gun_index==2) ? 1: 0);
  4488. }
  4489. else
  4490. {
  4491. tempIndex = gun_index;
  4492. }
  4493. for (int index = 0; index < CCS_QUANTITY; index++)
  4494. {
  4495. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4496. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4497. {
  4498. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4499. {
  4500. reqSampleMeter[gun_index] = 1;
  4501. }
  4502. }
  4503. } // End for CCS
  4504. }
  4505. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4506. {
  4507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4508. {
  4509. tempIndex = ((gun_index==2) ? 1: 0);
  4510. }
  4511. else
  4512. {
  4513. tempIndex = gun_index;
  4514. }
  4515. for (int index = 0; index < GB_QUANTITY; index++)
  4516. {
  4517. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4518. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4519. {
  4520. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4521. {
  4522. reqSampleMeter[gun_index] = 1;
  4523. }
  4524. }
  4525. }// End for GB
  4526. }
  4527. else if(gunType[gun_index] == GUN_TYPE_DO)
  4528. {
  4529. tempIndex = gun_index;
  4530. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4531. {
  4532. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4533. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4534. {
  4535. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4536. {
  4537. reqSampleMeter[gun_index] = 1;
  4538. }
  4539. }
  4540. }
  4541. }
  4542. else
  4543. {
  4544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4545. {
  4546. tempIndex = 2;
  4547. }
  4548. else
  4549. {
  4550. tempIndex = gun_index;
  4551. }
  4552. for (int index = 0; index < AC_QUANTITY; index++)
  4553. {
  4554. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4555. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4556. {
  4557. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4558. {
  4559. reqSampleMeter[gun_index] = 1;
  4560. }
  4561. }
  4562. }//End for AC
  4563. }
  4564. if(reqSampleMeter[gun_index] == 1)
  4565. {
  4566. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4567. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4568. storeTempStopTransaction(gun_index);
  4569. reqSampleMeter[gun_index] = 0;
  4570. }
  4571. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4572. }
  4573. //==============================================
  4574. // Check Connector reserved
  4575. //==============================================
  4576. //===============================
  4577. // Check if Reserve is expired
  4578. //===============================
  4579. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4580. {
  4581. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4582. {
  4583. DEBUG_INFO("reserve expired.\n");
  4584. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4585. }
  4586. }//END OF Check if Reserve is expired
  4587. //==========================================
  4588. // csu trigger FirmwareStatusNotificationReq
  4589. //==========================================
  4590. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4591. {
  4592. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4593. }
  4594. //==========================================
  4595. // csu trigger DiagnosticsStatusNotificationReq
  4596. //==========================================
  4597. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4598. {
  4599. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4600. }
  4601. //==========================================
  4602. // csu trigger CancelReservationConf
  4603. //==========================================
  4604. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4605. {
  4606. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4607. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4608. }
  4609. //==========================================
  4610. // csu trigger ChangeAvailabilityConf
  4611. //==========================================
  4612. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4613. {
  4614. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4615. }
  4616. //==========================================
  4617. // csu trigger UnlockConnectorConf
  4618. //==========================================
  4619. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4620. {
  4621. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4622. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4623. }
  4624. //==========================================
  4625. // csu trigger ReserveNowConf
  4626. //==========================================
  4627. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4628. {
  4629. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4630. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4631. }
  4632. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4633. {
  4634. sendSignCertificateRequest();
  4635. }
  4636. }
  4637. }
  4638. //==========================================
  4639. // send request routine
  4640. //==========================================
  4641. int sendAuthorizeRequest(int gun_index)
  4642. {
  4643. mtrace();
  4644. int result = FAIL;
  4645. char message[100]={0};
  4646. char guid[37];
  4647. char tempdata[65]={0};
  4648. DEBUG_INFO("sendAuthorizeRequest...\n");
  4649. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4650. //Local Authorize
  4651. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4652. {
  4653. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4654. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4655. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4656. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4657. result = PASS;
  4658. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4659. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4660. authorizeRetryTimes = 0;
  4661. return result;
  4662. }
  4663. 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))||
  4664. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4665. {
  4666. // Query from cache
  4667. DEBUG_INFO("Authorize from cache.\n");
  4668. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4669. // Query from list
  4670. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4671. {
  4672. DEBUG_INFO("Authorize from list.\n");
  4673. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4674. }
  4675. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4676. {
  4677. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4678. {
  4679. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4680. }
  4681. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4682. {
  4683. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4684. }
  4685. if(!GetOcppConnStatus())
  4686. {
  4687. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4688. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4689. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4690. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4691. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4692. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4693. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4694. authorizeRetryTimes = 0;
  4695. return result;
  4696. }
  4697. }
  4698. else
  4699. {
  4700. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4701. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4702. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4703. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4704. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4705. else
  4706. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4707. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4708. result = PASS;
  4709. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4710. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4711. authorizeRetryTimes = 0;
  4712. return result;
  4713. }
  4714. }
  4715. //initialize struct Authorize
  4716. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4717. //get data from shared memory
  4718. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4719. random_uuid(guid);
  4720. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4721. LWS_Send(message);
  4722. sprintf(tempdata, "Authorize,%d", gun_index);
  4723. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4724. {
  4725. result = PASS;
  4726. DEBUG_INFO("Authorize mapItem pass\n");
  4727. }
  4728. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4729. return result;
  4730. }
  4731. int sendBootNotificationRequest(void)
  4732. {
  4733. mtrace();
  4734. int result = FAIL;
  4735. char message[500]={0}, payload[700]={0};
  4736. char guid[37]={0};
  4737. char tempdata[65]={0};
  4738. // Fill BootNotification fields
  4739. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4740. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4741. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4742. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4743. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4744. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4745. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4746. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4747. ShmOCPP16Data->ChargeBoxId
  4748. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4749. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4750. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4751. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4752. ,ShmOCPP16Data->BootNotification.CpIccid
  4753. ,ShmOCPP16Data->BootNotification.CpImsi);
  4754. random_uuid(guid);
  4755. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4756. LWS_Send(message);
  4757. sprintf(tempdata, "BootNotification,0");
  4758. 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*/)
  4759. {
  4760. result = PASS;
  4761. }
  4762. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4763. strcpy(queuedata,message);
  4764. return result;
  4765. }
  4766. int sendDataTransferRequest(int gun_index)
  4767. {
  4768. mtrace();
  4769. char message[1000]={0};
  4770. char guid[37]={0};
  4771. char tempdata[65]={0};
  4772. int result = FAIL;
  4773. random_uuid(guid);
  4774. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4775. MESSAGE_TYPE_CALL,
  4776. guid,
  4777. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4778. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4779. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4780. LWS_Send(message);
  4781. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4782. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4783. {
  4784. result = PASS;
  4785. DEBUG_INFO("DataTransfer mapItem pass\n");
  4786. }
  4787. return result;
  4788. }
  4789. int sendDiagnosticsStatusNotificationRequest(char *status)
  4790. {
  4791. mtrace();
  4792. int result = FAIL;
  4793. char message[110]={0};
  4794. char guid[37]={0};
  4795. char tempdata[65]={0};
  4796. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4797. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4798. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4799. random_uuid(guid);
  4800. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4801. LWS_SendNow(message);
  4802. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4803. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4804. {
  4805. result = PASS;
  4806. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4807. }
  4808. //#ifdef SystemLogMessage
  4809. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4810. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4811. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4812. //#endif
  4813. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4814. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4815. //record status
  4816. if(strcmp(status,"Idle")==0)
  4817. {
  4818. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4819. }
  4820. else if(strcmp(status,"Uploaded")==0)
  4821. {
  4822. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4823. }
  4824. else if(strcmp(status,"UploadFailed")==0)
  4825. {
  4826. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4827. }
  4828. else if(strcmp(status,"Uploading")==0)
  4829. {
  4830. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4831. }
  4832. return result;
  4833. }
  4834. int sendFirmwareStatusNotificationRequest(char *status)
  4835. {
  4836. mtrace();
  4837. int result = FAIL;
  4838. char message[110]={0};
  4839. char guid[37]={0};
  4840. char tempdata[65]={0};
  4841. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4842. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4843. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4844. random_uuid(guid);
  4845. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4846. LWS_SendNow(message);
  4847. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4848. 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*/)
  4849. {
  4850. result = PASS;
  4851. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4852. }
  4853. //#ifdef SystemLogMessage
  4854. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4855. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4856. //#endif
  4857. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4858. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4859. //record status
  4860. if(strcmp(status,"Downloaded")==0)
  4861. {
  4862. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4863. }
  4864. else if(strcmp(status,"DownloadFailed")==0)
  4865. {
  4866. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4867. }
  4868. else if(strcmp(status,"Downloading")==0)
  4869. {
  4870. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4871. }
  4872. else if(strcmp(status,"Idle")==0)
  4873. {
  4874. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4875. }
  4876. else if(strcmp(status,"InstallationFailed")==0)
  4877. {
  4878. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4879. }
  4880. else if(strcmp(status,"Installing")==0)
  4881. {
  4882. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4883. }
  4884. else if(strcmp(status,"Installed")==0)
  4885. {
  4886. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4887. }
  4888. return result;
  4889. }
  4890. int sendHeartbeatRequest(int gun_index)
  4891. {
  4892. mtrace();
  4893. int result = FAIL;
  4894. char message[80]={0};
  4895. char guid[37]={0};
  4896. char tempdata[65]={0};
  4897. random_uuid(guid);
  4898. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4899. , MESSAGE_TYPE_CALL
  4900. , guid );
  4901. LWS_Send(message);
  4902. sprintf(tempdata, "Heartbeat,%d", 0);
  4903. 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*/)
  4904. {
  4905. result = PASS;
  4906. }
  4907. return result;
  4908. }
  4909. int sendStartTransactionRequest(int gun_index)
  4910. {
  4911. mtrace();
  4912. int result = FAIL;
  4913. char message[250]={0};
  4914. char guid[37]={0};
  4915. struct timeval tmnow;
  4916. struct tm *tm;
  4917. char buf[28];//, usec_buf[6];
  4918. char tempdata[65]={0};
  4919. int tempIndex = 0;
  4920. DEBUG_INFO("sendStartTransactionRequest...\n");
  4921. gettimeofday(&tmnow, NULL);
  4922. time_t t;
  4923. t = time(NULL);
  4924. /*UTC time and date*/
  4925. tm = gmtime(&t);
  4926. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4927. #if 0 // remove temporally
  4928. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4929. strcat(buf,".");
  4930. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4931. strcat(buf,usec_buf);
  4932. #endif
  4933. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4934. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4935. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4936. // clear StartTransaction Response
  4937. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4938. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4939. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4940. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4941. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4942. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4943. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4944. {
  4945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4946. {
  4947. tempIndex = ((gun_index==2) ? 1: 0);
  4948. }
  4949. else
  4950. {
  4951. tempIndex = gun_index;
  4952. }
  4953. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4954. {
  4955. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4956. {
  4957. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4958. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4959. }
  4960. }
  4961. }
  4962. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4963. {
  4964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4965. {
  4966. tempIndex = ((gun_index==2) ? 1: 0);
  4967. }
  4968. else
  4969. {
  4970. tempIndex = gun_index;
  4971. }
  4972. for (int index = 0; index < CCS_QUANTITY; index++)
  4973. {
  4974. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4975. {
  4976. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4977. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4978. }
  4979. }
  4980. }
  4981. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4982. {
  4983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4984. {
  4985. tempIndex = ((gun_index==2) ? 1: 0);
  4986. }
  4987. else
  4988. {
  4989. tempIndex = gun_index;
  4990. }
  4991. for (int index = 0; index < GB_QUANTITY; index++)
  4992. {
  4993. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4994. {
  4995. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4996. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4997. }
  4998. }
  4999. }
  5000. else if(gunType[gun_index] == GUN_TYPE_DO)
  5001. {
  5002. tempIndex = gun_index;
  5003. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5004. {
  5005. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5006. {
  5007. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5008. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5009. }
  5010. }
  5011. }
  5012. else
  5013. {
  5014. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5015. {
  5016. tempIndex = 2;
  5017. }
  5018. else
  5019. {
  5020. tempIndex = gun_index;
  5021. }
  5022. for (int index = 0; index < AC_QUANTITY; index++)
  5023. {
  5024. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5025. {
  5026. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5027. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5028. }
  5029. }
  5030. }
  5031. random_uuid(guid);
  5032. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5033. {
  5034. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5035. , gun_index +1
  5036. , MESSAGE_TYPE_CALL
  5037. , guid
  5038. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5039. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5040. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5041. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5042. }
  5043. else
  5044. {
  5045. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5046. , gun_index +1
  5047. , MESSAGE_TYPE_CALL
  5048. , guid
  5049. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5050. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5051. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5052. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5053. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5054. }
  5055. #if 1
  5056. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5057. 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*/)
  5058. {
  5059. result = PASS;
  5060. }
  5061. #endif
  5062. strcpy(queuedata, message);
  5063. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5064. OCPP_insert_transaction_msg(YES, queuedata);
  5065. return result;
  5066. }
  5067. int sendStatusNotificationRequest(int gun_index)
  5068. {
  5069. mtrace();
  5070. int result = FAIL;
  5071. char message[600]={0};
  5072. char guid[37];
  5073. int currentStatus = 0;
  5074. struct timeval tmnow;
  5075. struct tm *tm;
  5076. char buf[28];//, usec_buf[6];
  5077. char tempdata[65]={0};
  5078. int tempIndex = 0;
  5079. uint8_t isStateChanged = TRUE;
  5080. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5081. gettimeofday(&tmnow, NULL);
  5082. time_t t;
  5083. t = time(NULL);
  5084. /*UTC time and date*/
  5085. tm = gmtime(&t);
  5086. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5087. #if 0 // remove temporally
  5088. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5089. strcat(buf,".");
  5090. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5091. strcat(buf,usec_buf);
  5092. #endif
  5093. //printf("%s",buf);
  5094. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5095. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5096. // it's option
  5097. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5098. /*
  5099. enum _SYSTEM_STATUS
  5100. {
  5101. S_BOOTING = 0,
  5102. S_IDLE, = 1
  5103. S_AUTHORIZING, =2
  5104. S_REASSIGN_CHECK, =3
  5105. S_REASSIGN, =4
  5106. S_PRECHARGE, =5
  5107. S_PREPARING_FOR_EV, =6
  5108. S_PREPARING_FOR_EVSE, =7
  5109. S_CHARGING, =8
  5110. S_TERMINATING, =9
  5111. S_COMPLETE, =10
  5112. S_ALARM, =11
  5113. S_FAULT =12
  5114. }
  5115. */
  5116. //check Transaction active
  5117. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5118. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5119. {
  5120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5121. {
  5122. tempIndex = ((gun_index==2) ? 1: 0);
  5123. }
  5124. else
  5125. {
  5126. tempIndex = gun_index;
  5127. }
  5128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5129. {
  5130. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5131. {
  5132. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5133. {
  5134. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5135. {
  5136. currentStatus = Preparing; //OCPP Status: Preparing
  5137. }
  5138. else
  5139. {
  5140. currentStatus = Available; //OCPP Status: Available
  5141. }
  5142. }
  5143. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5144. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5145. ) //S_PRECHARGE
  5146. {
  5147. currentStatus = Preparing; //OCPP Status: Preparing
  5148. }
  5149. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5150. {
  5151. currentStatus = Charging; //OCPP Status: Charging
  5152. }
  5153. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5154. {
  5155. currentStatus = Finishing; //OCPP Status: Finishing
  5156. }
  5157. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5158. {
  5159. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5160. }
  5161. 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
  5162. {
  5163. currentStatus = Unavailable; //OCPP Status: Unavailable
  5164. }
  5165. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5166. {
  5167. currentStatus = Faulted; //OCPP Status: Faulted
  5168. }
  5169. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5170. {
  5171. currentStatus = Reserved; //OCPP Status: Reserved
  5172. }
  5173. } //end of the same index
  5174. }//end of for CHAdeMO_QUANTITY
  5175. }
  5176. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5177. {
  5178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5179. {
  5180. tempIndex = ((gun_index==2) ? 1: 0);
  5181. }
  5182. else
  5183. {
  5184. tempIndex = gun_index;
  5185. }
  5186. for (int index = 0; index < CCS_QUANTITY; index++)
  5187. {
  5188. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5189. {
  5190. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5191. {
  5192. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5193. {
  5194. currentStatus = Preparing; //OCPP Status: Preparing
  5195. }
  5196. else
  5197. {
  5198. currentStatus = Available; //OCPP Status: Available
  5199. }
  5200. }
  5201. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5202. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5203. ) //S_PRECHARGE
  5204. {
  5205. currentStatus = Preparing; //OCPP Status: Preparing
  5206. }
  5207. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5208. {
  5209. currentStatus = Charging; //OCPP Status: Charging
  5210. }
  5211. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5212. {
  5213. currentStatus = Finishing; //OCPP Status: Finishing
  5214. }
  5215. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5216. {
  5217. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5218. }
  5219. 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
  5220. {
  5221. currentStatus = Unavailable; //OCPP Status : Unavailable
  5222. }
  5223. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5224. {
  5225. currentStatus = Faulted; //OCPP Status: Faulted
  5226. }
  5227. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5228. {
  5229. currentStatus = Reserved; //OCPP Status: Reserved
  5230. }
  5231. } //end of the same index
  5232. } // end of for CCS_QUANTITY
  5233. }
  5234. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5235. {
  5236. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5237. {
  5238. tempIndex = ((gun_index==2) ? 1: 0);
  5239. }
  5240. else
  5241. {
  5242. tempIndex = gun_index;
  5243. }
  5244. for (int index = 0; index < GB_QUANTITY; index++)
  5245. {
  5246. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5247. {
  5248. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5249. {
  5250. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5251. {
  5252. currentStatus = Preparing; //OCPP Status: Preparing
  5253. }
  5254. else
  5255. {
  5256. currentStatus = Available; //OCPP Status: Available
  5257. }
  5258. }
  5259. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5260. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5261. ) //S_PRECHARGE
  5262. {
  5263. currentStatus = Preparing; //OCPP Status: Preparing
  5264. }
  5265. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5266. {
  5267. currentStatus = Charging; //OCPP Status: Charging
  5268. }
  5269. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5270. {
  5271. currentStatus = Finishing; //OCPP Status: Finishing
  5272. }
  5273. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5274. {
  5275. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5276. }
  5277. 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
  5278. {
  5279. currentStatus = Unavailable; //OCPP Status: Unavailable
  5280. }
  5281. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5282. {
  5283. currentStatus = Faulted; //OCPP Status: Faulted
  5284. }
  5285. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5286. {
  5287. currentStatus = Reserved; //OCPP Status: Reserved
  5288. }
  5289. } //end of the same index
  5290. } // end of for GB_QUANTITY
  5291. }
  5292. else if(gunType[gun_index] == GUN_TYPE_DO)
  5293. {
  5294. tempIndex = gun_index;
  5295. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5296. {
  5297. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5298. {
  5299. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5300. {
  5301. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5302. {
  5303. currentStatus = Preparing; //OCPP Status: Preparing
  5304. }
  5305. else
  5306. {
  5307. currentStatus = Available; //OCPP Status: Available
  5308. }
  5309. }
  5310. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5311. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5312. ) //S_PRECHARGE
  5313. {
  5314. currentStatus = Preparing; //OCPP Status: Preparing
  5315. }
  5316. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5317. {
  5318. currentStatus = Charging; //OCPP Status: Charging
  5319. }
  5320. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5321. {
  5322. currentStatus = Finishing; //OCPP Status: Finishing
  5323. }
  5324. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5325. {
  5326. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5327. }
  5328. 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
  5329. {
  5330. currentStatus = Unavailable; //OCPP Status: Unavailable
  5331. }
  5332. 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
  5333. {
  5334. currentStatus = Faulted; //OCPP Status: Faulted
  5335. }
  5336. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5337. {
  5338. currentStatus = Reserved; //OCPP Status: Reserved
  5339. }
  5340. } //end of the same index
  5341. }
  5342. }
  5343. else
  5344. {
  5345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5346. {
  5347. tempIndex = 2;
  5348. }
  5349. else
  5350. {
  5351. tempIndex = gun_index;
  5352. }
  5353. for (int index = 0; index < AC_QUANTITY; index++)
  5354. {
  5355. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5356. {
  5357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5358. {
  5359. 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))
  5360. {
  5361. currentStatus = Preparing; //OCPP Status: Preparing
  5362. }
  5363. else
  5364. {
  5365. currentStatus = Available; //OCPP Status: Available
  5366. }
  5367. }
  5368. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5369. {
  5370. currentStatus = Preparing; //OCPP Status: Preparing
  5371. }
  5372. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5373. {
  5374. currentStatus = Charging; //OCPP Status: Charging
  5375. }
  5376. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5377. {
  5378. currentStatus = Finishing; //OCPP Status: Finishing
  5379. }
  5380. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5381. {
  5382. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5383. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5384. else
  5385. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5386. }
  5387. 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
  5388. {
  5389. currentStatus = Unavailable; //OCPP Status: Unavailable
  5390. }
  5391. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5392. {
  5393. currentStatus = Faulted; //OCPP Status: Faulted
  5394. }
  5395. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5396. {
  5397. currentStatus = Reserved; //OCPP Status: Reserved
  5398. }
  5399. }//end of the same index
  5400. }//end of for AC_QUANTITY
  5401. }
  5402. //it's option
  5403. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5404. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5405. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5406. {
  5407. isStateChanged = FALSE;
  5408. }
  5409. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5410. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5411. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5412. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5413. random_uuid(guid);
  5414. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5415. , MESSAGE_TYPE_CALL
  5416. , guid
  5417. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5418. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5419. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5420. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5421. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5422. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5423. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5424. if((server_sign == TRUE) && isStateChanged)
  5425. {
  5426. LWS_Send(message);
  5427. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5428. 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*/)
  5429. {
  5430. //DEBUG_ERROR("statusNotification mapitem pass");
  5431. result = PASS;
  5432. }
  5433. }
  5434. else
  5435. {
  5436. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5437. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5438. result = PASS;
  5439. }
  5440. return result;
  5441. }
  5442. int sendStopTransactionRequest(int gun_index)
  5443. {
  5444. mtrace();
  5445. int result = FAIL;
  5446. //char message[1500]={0};
  5447. char guid[37]={0};
  5448. char tempdata[65]={0};
  5449. int tempIndex = 0;
  5450. char TempStopTransaction[256];
  5451. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5452. //int idx_sample=0;
  5453. DEBUG_INFO("sendStopTransactionRequest \n");
  5454. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5455. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5456. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5457. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5458. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5459. {
  5460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5461. {
  5462. tempIndex = ((gun_index==2) ? 1: 0);
  5463. }
  5464. else
  5465. {
  5466. tempIndex = gun_index;
  5467. }
  5468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5471. {
  5472. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5473. }
  5474. }// END OF CHAdeMO_QUANTITY
  5475. }
  5476. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5477. {
  5478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5479. {
  5480. tempIndex = ((gun_index==2) ? 1: 0);
  5481. }
  5482. else
  5483. {
  5484. tempIndex = gun_index;
  5485. }
  5486. for (int index = 0; index < CCS_QUANTITY; index++)
  5487. {
  5488. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5489. {
  5490. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5491. }
  5492. }// END OF CCS_QUANTITY
  5493. }
  5494. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5495. {
  5496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5497. {
  5498. tempIndex = ((gun_index==2) ? 1: 0);
  5499. }
  5500. else
  5501. {
  5502. tempIndex = gun_index;
  5503. }
  5504. for (int index = 0; index < GB_QUANTITY; index++)
  5505. {
  5506. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5507. {
  5508. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5509. }
  5510. }// END OF GB_QUANTITY
  5511. }
  5512. else if(gunType[gun_index] == GUN_TYPE_DO)
  5513. {
  5514. tempIndex = gun_index;
  5515. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5516. {
  5517. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5518. {
  5519. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5520. }
  5521. }// END OF GB_QUANTITY
  5522. }
  5523. else
  5524. {
  5525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5526. {
  5527. tempIndex = 2;
  5528. }
  5529. else
  5530. {
  5531. tempIndex = gun_index;
  5532. }
  5533. for (int index = 0; index < AC_QUANTITY; index++)
  5534. {
  5535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5536. {
  5537. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5538. }
  5539. }// END OF AC_QUANTITY
  5540. }
  5541. //====================================== Stop Transaction Time =====================================================
  5542. struct timeval tmnow;
  5543. struct tm *tm;
  5544. char buf[28];//, usec_buf[6];
  5545. gettimeofday(&tmnow, NULL);
  5546. time_t t;
  5547. t = time(NULL);
  5548. /*UTC time and date*/
  5549. tm = gmtime(&t);
  5550. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5552. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5553. random_uuid(guid);
  5554. /***********************************transactionData******************************************************/
  5555. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5557. //=================================
  5558. // Transaction_Begin
  5559. //=================================
  5560. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5561. {
  5562. //============================================ Energy.Active.Import.Interval ================================
  5563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5566. 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*/]);
  5567. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5568. 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))
  5569. {
  5570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5571. }
  5572. else
  5573. {
  5574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5575. }
  5576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5578. }
  5579. //=================================
  5580. // Transaction_End
  5581. //=================================
  5582. // ================================= Current.Import L1 ===============================================
  5583. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5584. {
  5585. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5586. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5587. {
  5588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5589. {
  5590. tempIndex = ((gun_index==2) ? 1: 0);
  5591. }
  5592. else
  5593. {
  5594. tempIndex = gun_index;
  5595. }
  5596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5597. {
  5598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5599. {
  5600. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5601. }
  5602. }// End of for CHAdeMO_QUANTITY
  5603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5604. }
  5605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5606. {
  5607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5608. {
  5609. tempIndex = ((gun_index==2) ? 1: 0);
  5610. }
  5611. else
  5612. {
  5613. tempIndex = gun_index;
  5614. }
  5615. for (int index = 0; index < CCS_QUANTITY; index++)
  5616. {
  5617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5618. {
  5619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5620. }
  5621. }// End of for CCS_QUANTITY
  5622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5623. }
  5624. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5625. {
  5626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5627. {
  5628. tempIndex = ((gun_index==2) ? 1: 0);
  5629. }
  5630. else
  5631. {
  5632. tempIndex = gun_index;
  5633. }
  5634. for (int index = 0; index < GB_QUANTITY; index++)
  5635. {
  5636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5637. {
  5638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5639. }
  5640. }// End of for GB_QUANTITY
  5641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5642. }
  5643. else if(gunType[gun_index] == GUN_TYPE_DO)
  5644. {
  5645. tempIndex = gun_index;
  5646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5647. {
  5648. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5649. {
  5650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5651. }
  5652. }
  5653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5654. }
  5655. else
  5656. {
  5657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5658. {
  5659. tempIndex = 2;
  5660. }
  5661. else
  5662. {
  5663. tempIndex = gun_index;
  5664. }
  5665. for (int index = 0; index < AC_QUANTITY; index++)
  5666. {
  5667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5668. {
  5669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5670. }
  5671. }// End of for AC_QUANTITY
  5672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5673. }
  5674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5679. }
  5680. // ================================= Energy.Active.Import.Interval ==============================================
  5681. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5682. {
  5683. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5684. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5685. {
  5686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5687. {
  5688. tempIndex = ((gun_index==2) ? 1: 0);
  5689. }
  5690. else
  5691. {
  5692. tempIndex = gun_index;
  5693. }
  5694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5695. {
  5696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5697. {
  5698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5699. }
  5700. }// END OF CHAdeMO_QUANTITY
  5701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5702. }
  5703. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5704. {
  5705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5706. {
  5707. tempIndex = ((gun_index==2) ? 1: 0);
  5708. }
  5709. else
  5710. {
  5711. tempIndex = gun_index;
  5712. }
  5713. for (int index = 0; index < CCS_QUANTITY; index++)
  5714. {
  5715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5716. {
  5717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5718. }
  5719. }// END OF CCS_QUANTITY
  5720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5721. }
  5722. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5723. {
  5724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5725. {
  5726. tempIndex = ((gun_index==2) ? 1: 0);
  5727. }
  5728. else
  5729. {
  5730. tempIndex = gun_index;
  5731. }
  5732. for (int index = 0; index < GB_QUANTITY; index++)
  5733. {
  5734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5735. {
  5736. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5737. }
  5738. }// END OF GB_QUANTITY
  5739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5740. }
  5741. else if(gunType[gun_index] == GUN_TYPE_DO)
  5742. {
  5743. tempIndex = gun_index;
  5744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5745. {
  5746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5747. {
  5748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5749. }
  5750. }
  5751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5752. }
  5753. else
  5754. {
  5755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5756. {
  5757. tempIndex = 2;
  5758. }
  5759. else
  5760. {
  5761. tempIndex = gun_index;
  5762. }
  5763. for (int index = 0; index < AC_QUANTITY; index++)
  5764. {
  5765. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5766. {
  5767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5768. }
  5769. }// END OF AC_QUANTITY
  5770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5771. }
  5772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5777. }
  5778. //=================================== Power.Active.Import ==================================================
  5779. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5780. {
  5781. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5782. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5783. {
  5784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5785. {
  5786. tempIndex = ((gun_index==2) ? 1: 0);
  5787. }
  5788. else
  5789. {
  5790. tempIndex = gun_index;
  5791. }
  5792. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5793. {
  5794. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5795. {
  5796. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5797. }
  5798. } // End for CHAdeMO_QUANTITY
  5799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5800. }
  5801. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5802. {
  5803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5804. {
  5805. tempIndex = ((gun_index==2) ? 1: 0);
  5806. }
  5807. else
  5808. {
  5809. tempIndex = gun_index;
  5810. }
  5811. for (int index = 0; index < CCS_QUANTITY; index++)
  5812. {
  5813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5814. {
  5815. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5816. }
  5817. } // END for CCS_QUANTITY
  5818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5819. }
  5820. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5821. {
  5822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5823. {
  5824. tempIndex = ((gun_index==2) ? 1: 0);
  5825. }
  5826. else
  5827. {
  5828. tempIndex = gun_index;
  5829. }
  5830. for (int index = 0; index < GB_QUANTITY; index++)
  5831. {
  5832. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5833. {
  5834. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5835. }
  5836. }// END for GB_QUANTITY
  5837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5838. }
  5839. else if(gunType[gun_index] == GUN_TYPE_DO)
  5840. {
  5841. tempIndex = gun_index;
  5842. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5843. {
  5844. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5845. {
  5846. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5847. }
  5848. }
  5849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5850. }
  5851. else
  5852. {
  5853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5854. {
  5855. tempIndex = 2;
  5856. }
  5857. else
  5858. {
  5859. tempIndex = gun_index;
  5860. }
  5861. for (int index = 0; index < AC_QUANTITY; index++)
  5862. {
  5863. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5864. {
  5865. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5866. }
  5867. } // END for AC_QUANTITY
  5868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5869. }
  5870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5875. }
  5876. //============================ Voltage L1 ====================================
  5877. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5878. {
  5879. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5880. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5881. {
  5882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5883. {
  5884. tempIndex = ((gun_index==2) ? 1: 0);
  5885. }
  5886. else
  5887. {
  5888. tempIndex = gun_index;
  5889. }
  5890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5891. {
  5892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5893. {
  5894. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5895. }
  5896. } // END OF FOR CHAdeMO_QUANTITY
  5897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5898. }
  5899. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5900. {
  5901. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5902. {
  5903. tempIndex = ((gun_index==2) ? 1: 0);
  5904. }
  5905. else
  5906. {
  5907. tempIndex = gun_index;
  5908. }
  5909. for (int index = 0; index < CCS_QUANTITY; index++)
  5910. {
  5911. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5912. {
  5913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5914. }
  5915. } // END OF FOR CCS_QUANTITY
  5916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5917. }
  5918. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5919. {
  5920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5921. {
  5922. tempIndex = ((gun_index==2) ? 1: 0);
  5923. }
  5924. else
  5925. {
  5926. tempIndex = gun_index;
  5927. }
  5928. for (int index = 0; index < GB_QUANTITY; index++)
  5929. {
  5930. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5931. {
  5932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5933. }
  5934. } // END OF FOR GB_QUANTITY
  5935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5936. }
  5937. else if(gunType[gun_index] == GUN_TYPE_DO)
  5938. {
  5939. tempIndex = gun_index;
  5940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5941. {
  5942. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5943. {
  5944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5945. }
  5946. }
  5947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5948. }
  5949. else
  5950. {
  5951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5952. {
  5953. tempIndex = 2;
  5954. }
  5955. else
  5956. {
  5957. tempIndex = gun_index;
  5958. }
  5959. for (int index = 0; index < AC_QUANTITY; index++)
  5960. {
  5961. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5962. {
  5963. 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
  5964. }
  5965. } // END OF FOR AC_QUANTITY
  5966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5967. }
  5968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5973. }
  5974. //====================== End SoC ================================
  5975. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5976. {
  5977. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5978. 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))
  5979. {
  5980. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5981. {
  5982. tempIndex = ((gun_index==2) ? 1: 0);
  5983. }
  5984. else
  5985. {
  5986. tempIndex = gun_index;
  5987. }
  5988. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5989. {
  5990. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5991. {
  5992. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5993. {
  5994. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5995. }
  5996. }
  5997. }
  5998. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5999. {
  6000. for (int index = 0; index < CCS_QUANTITY; index++)
  6001. {
  6002. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6003. {
  6004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6005. }
  6006. }
  6007. }
  6008. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6009. {
  6010. for (int index = 0; index < GB_QUANTITY; index++)
  6011. {
  6012. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6013. {
  6014. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6015. }
  6016. }
  6017. }
  6018. else if(gunType[gun_index] == GUN_TYPE_DO)
  6019. {
  6020. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6021. {
  6022. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6023. {
  6024. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6025. }
  6026. }
  6027. }
  6028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6029. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6034. } // END FOR DC CASE
  6035. }
  6036. // ================================= Current.Import L2 ===============================================
  6037. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6038. {
  6039. // AC 3 phse L2 current
  6040. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6041. {
  6042. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6043. {
  6044. tempIndex = 2;
  6045. }
  6046. else
  6047. {
  6048. tempIndex = gun_index;
  6049. }
  6050. for (int index = 0; index < AC_QUANTITY; index++)
  6051. {
  6052. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6053. {
  6054. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6055. }
  6056. }// End of for AC_QUANTITY
  6057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6058. }
  6059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6064. }
  6065. // ================================= Current.Import L3 ===============================================
  6066. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6067. {
  6068. // AC 3 phse L3 current
  6069. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6070. {
  6071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6072. {
  6073. tempIndex = 2;
  6074. }
  6075. else
  6076. {
  6077. tempIndex = gun_index;
  6078. }
  6079. for (int index = 0; index < AC_QUANTITY; index++)
  6080. {
  6081. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6082. {
  6083. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6084. }
  6085. }// End of for AC_QUANTITY
  6086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6087. }
  6088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6093. }
  6094. //============================ Voltage L2 ====================================
  6095. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6096. {
  6097. // AC 3 phse L2 voltage
  6098. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6099. {
  6100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6101. {
  6102. tempIndex = 2;
  6103. }
  6104. else
  6105. {
  6106. tempIndex = gun_index;
  6107. }
  6108. for (int index = 0; index < AC_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6111. {
  6112. 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
  6113. }
  6114. } // END OF FOR AC_QUANTITY
  6115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6116. }
  6117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6122. }
  6123. //============================ Voltage L3 ====================================
  6124. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6125. {
  6126. // AC 3 phse L3 voltage
  6127. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6128. {
  6129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6130. {
  6131. tempIndex = 2;
  6132. }
  6133. else
  6134. {
  6135. tempIndex = gun_index;
  6136. }
  6137. for (int index = 0; index < AC_QUANTITY; index++)
  6138. {
  6139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6140. {
  6141. 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
  6142. }
  6143. } // END OF FOR AC_QUANTITY
  6144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6145. }
  6146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6151. }
  6152. //====================== Start SoC ================================
  6153. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6154. {
  6155. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6156. 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))
  6157. {
  6158. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6159. {
  6160. tempIndex = ((gun_index==2) ? 1: 0);
  6161. }
  6162. else
  6163. {
  6164. tempIndex = gun_index;
  6165. }
  6166. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6167. {
  6168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6169. {
  6170. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6171. {
  6172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6173. }
  6174. }
  6175. }
  6176. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6177. {
  6178. for (int index = 0; index < CCS_QUANTITY; index++)
  6179. {
  6180. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6181. {
  6182. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6183. }
  6184. }
  6185. }
  6186. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6187. {
  6188. for (int index = 0; index < GB_QUANTITY; index++)
  6189. {
  6190. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6191. {
  6192. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6193. }
  6194. }
  6195. }
  6196. else if(gunType[gun_index] == GUN_TYPE_DO)
  6197. {
  6198. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6199. {
  6200. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6201. {
  6202. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6203. }
  6204. }
  6205. }
  6206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6212. } // END FOR DC CASE
  6213. }
  6214. //================================================ Message create ====================================================
  6215. json_object *StopTransaction = json_object_new_object();
  6216. json_object *transactionDatas = json_object_new_array();
  6217. json_object *sampledValues = json_object_new_array();
  6218. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6219. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6220. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6221. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6222. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6223. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6224. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6225. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6226. {
  6227. json_object *transactionData = json_object_new_object();
  6228. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6229. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6230. {
  6231. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6232. {
  6233. json_object *sampledValue = json_object_new_object();
  6234. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6235. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6236. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6237. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6238. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6239. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6240. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6241. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6242. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6243. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6244. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6245. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6246. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6247. json_object_array_add(sampledValues, sampledValue);
  6248. }
  6249. }
  6250. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6251. json_object_array_add(transactionDatas, transactionData);
  6252. }
  6253. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6254. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6255. ,MESSAGE_TYPE_CALL
  6256. ,guid
  6257. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6258. json_object_put(StopTransaction);
  6259. #if 1 // for TempStopTransaction
  6260. //Delete TempStopTransaction
  6261. if((access(TempStopTransaction,F_OK))!=-1)
  6262. {
  6263. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6264. }
  6265. #endif
  6266. #if 1
  6267. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6268. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6269. {
  6270. result = PASS;
  6271. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6272. }
  6273. #endif
  6274. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6275. OCPP_insert_transaction_msg(NO, queuedata);
  6276. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6277. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6278. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6279. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6280. {
  6281. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6282. }
  6283. //for test
  6284. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6285. return result;
  6286. }
  6287. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6288. {
  6289. mtrace();
  6290. int result = FAIL;
  6291. char guid[37]={0};
  6292. char tempdata[65]={0};
  6293. int tempIndex = 0;
  6294. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6295. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6296. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6297. //set value
  6298. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6299. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6300. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6301. -1);
  6302. random_uuid(guid);
  6303. //UTC Date time
  6304. struct timeval tmnow;
  6305. struct tm *tm;
  6306. char buf[28];//, usec_buf[6];
  6307. gettimeofday(&tmnow, NULL);
  6308. time_t t;
  6309. t = time(NULL);
  6310. /*UTC time and date*/
  6311. tm = gmtime(&t);
  6312. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6314. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6315. //********************************(1)Current.Import L1************************************************/
  6316. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6317. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6318. (dataType == ReadingContext_Trigger))
  6319. {
  6320. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6321. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6322. {
  6323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6324. {
  6325. tempIndex = ((gun_index==2) ? 1: 0);
  6326. }
  6327. else
  6328. {
  6329. tempIndex = gun_index;
  6330. }
  6331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6332. {
  6333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6334. {
  6335. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6336. }
  6337. }
  6338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6339. }
  6340. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6341. {
  6342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6343. {
  6344. tempIndex = ((gun_index==2) ? 1: 0);
  6345. }
  6346. else
  6347. {
  6348. tempIndex = gun_index;
  6349. }
  6350. for (int index = 0; index < CCS_QUANTITY; index++)
  6351. {
  6352. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6353. {
  6354. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6355. }
  6356. }
  6357. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6358. }
  6359. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6360. {
  6361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6362. {
  6363. tempIndex = ((gun_index==2) ? 1: 0);
  6364. }
  6365. else
  6366. {
  6367. tempIndex = gun_index;
  6368. }
  6369. for (int index = 0; index < GB_QUANTITY; index++)
  6370. {
  6371. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6372. {
  6373. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6374. }
  6375. }
  6376. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6377. }
  6378. else if(gunType[gun_index] == GUN_TYPE_DO)
  6379. {
  6380. tempIndex = gun_index;
  6381. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6382. {
  6383. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6384. {
  6385. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6386. }
  6387. }
  6388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6389. }
  6390. else
  6391. {
  6392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6393. {
  6394. tempIndex = 2;
  6395. }
  6396. else
  6397. {
  6398. tempIndex = gun_index;
  6399. }
  6400. for (int index = 0; index < AC_QUANTITY; index++)
  6401. {
  6402. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6403. {
  6404. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6405. }
  6406. }
  6407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6408. }
  6409. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6414. }
  6415. //********************************(2)Energy.Active.Import.Register ************************************************/
  6416. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6417. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6418. (dataType == ReadingContext_Trigger))
  6419. {
  6420. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6421. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6422. {
  6423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6424. {
  6425. tempIndex = ((gun_index==2) ? 1: 0);
  6426. }
  6427. else
  6428. {
  6429. tempIndex = gun_index;
  6430. }
  6431. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6432. {
  6433. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6434. {
  6435. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6436. }
  6437. }
  6438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6439. }
  6440. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6441. {
  6442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6443. {
  6444. tempIndex = ((gun_index==2) ? 1: 0);
  6445. }
  6446. else
  6447. {
  6448. tempIndex = gun_index;
  6449. }
  6450. for (int index = 0; index < CCS_QUANTITY; index++)
  6451. {
  6452. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6453. {
  6454. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6455. }
  6456. }
  6457. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6458. }
  6459. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6460. {
  6461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6462. {
  6463. tempIndex = ((gun_index==2) ? 1: 0);
  6464. }
  6465. else
  6466. {
  6467. tempIndex = gun_index;
  6468. }
  6469. for (int index = 0; index < GB_QUANTITY; index++)
  6470. {
  6471. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6472. {
  6473. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6474. }
  6475. }
  6476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6477. }
  6478. else if(gunType[gun_index] == GUN_TYPE_DO)
  6479. {
  6480. tempIndex = gun_index;
  6481. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6482. {
  6483. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6484. {
  6485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6486. }
  6487. }
  6488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6489. }
  6490. else
  6491. {
  6492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6493. {
  6494. tempIndex = 2;
  6495. }
  6496. else
  6497. {
  6498. tempIndex = gun_index;
  6499. }
  6500. for (int index = 0; index < AC_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6503. {
  6504. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6505. }
  6506. }
  6507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6508. }
  6509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6514. }
  6515. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6516. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6517. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6518. (dataType == ReadingContext_Trigger))
  6519. {
  6520. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6521. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6522. {
  6523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6524. {
  6525. tempIndex = ((gun_index==2) ? 1: 0);
  6526. }
  6527. else
  6528. {
  6529. tempIndex = gun_index;
  6530. }
  6531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6532. {
  6533. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6534. {
  6535. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6536. }
  6537. } // END OF FOR CHAdeMO_QUANTITY
  6538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6539. }
  6540. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6541. {
  6542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6543. {
  6544. tempIndex = ((gun_index==2) ? 1: 0);
  6545. }
  6546. else
  6547. {
  6548. tempIndex = gun_index;
  6549. }
  6550. for (int index = 0; index < CCS_QUANTITY; index++)
  6551. {
  6552. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6553. {
  6554. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6555. }
  6556. } // END OF CCS_QUANTITY
  6557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6558. }
  6559. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6560. {
  6561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6562. {
  6563. tempIndex = ((gun_index==2) ? 1: 0);
  6564. }
  6565. else
  6566. {
  6567. tempIndex = gun_index;
  6568. }
  6569. for (int index = 0; index < GB_QUANTITY; index++)
  6570. {
  6571. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6572. {
  6573. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6574. }
  6575. } // END OF GB_QUANTITY
  6576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6577. }
  6578. else if(gunType[gun_index] == GUN_TYPE_DO)
  6579. {
  6580. tempIndex = gun_index;
  6581. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6582. {
  6583. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6584. {
  6585. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6586. }
  6587. }
  6588. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6589. }
  6590. else
  6591. {
  6592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6593. {
  6594. tempIndex = 2;
  6595. }
  6596. else
  6597. {
  6598. tempIndex = gun_index;
  6599. }
  6600. for (int index = 0; index < AC_QUANTITY; index++)
  6601. {
  6602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6603. {
  6604. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6605. }
  6606. }
  6607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6608. }
  6609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6614. }
  6615. //********************************(4)Power.Active.Import************************************************/
  6616. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6617. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6618. (dataType == ReadingContext_Trigger))
  6619. {
  6620. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6621. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6622. {
  6623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6624. {
  6625. tempIndex = ((gun_index==2) ? 1: 0);
  6626. }
  6627. else
  6628. {
  6629. tempIndex = gun_index;
  6630. }
  6631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6632. {
  6633. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6634. {
  6635. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6636. }
  6637. } // END OF FOR
  6638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6639. }
  6640. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6641. {
  6642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6643. {
  6644. tempIndex = ((gun_index==2) ? 1: 0);
  6645. }
  6646. else
  6647. {
  6648. tempIndex = gun_index;
  6649. }
  6650. for (int index = 0; index < CCS_QUANTITY; index++)
  6651. {
  6652. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6653. {
  6654. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6655. }
  6656. }
  6657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6658. }
  6659. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6660. {
  6661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6662. {
  6663. tempIndex = ((gun_index==2) ? 1: 0);
  6664. }
  6665. else
  6666. {
  6667. tempIndex = gun_index;
  6668. }
  6669. for (int index = 0; index < GB_QUANTITY; index++)
  6670. {
  6671. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6672. {
  6673. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6674. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6675. }
  6676. }
  6677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6678. }
  6679. else if(gunType[gun_index] == GUN_TYPE_DO)
  6680. {
  6681. tempIndex = gun_index;
  6682. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6683. {
  6684. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6685. {
  6686. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6687. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6688. }
  6689. }
  6690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6691. }
  6692. else
  6693. {
  6694. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6695. {
  6696. tempIndex = 2;
  6697. }
  6698. else
  6699. {
  6700. tempIndex = gun_index;
  6701. }
  6702. for (int index = 0; index < AC_QUANTITY; index++)
  6703. {
  6704. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6705. {
  6706. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6707. }
  6708. }
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6710. }
  6711. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6712. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6716. }
  6717. //***********************************************(5)VOLTAGE L1******************************************************/
  6718. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6719. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6720. (dataType == ReadingContext_Trigger))
  6721. {
  6722. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6723. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6724. {
  6725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6726. {
  6727. tempIndex = ((gun_index==2) ? 1: 0);
  6728. }
  6729. else
  6730. {
  6731. tempIndex = gun_index;
  6732. }
  6733. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6734. {
  6735. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6736. {
  6737. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6738. }
  6739. }
  6740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6741. }
  6742. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6743. {
  6744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6745. {
  6746. tempIndex = ((gun_index==2) ? 1: 0);
  6747. }
  6748. else
  6749. {
  6750. tempIndex = gun_index;
  6751. }
  6752. for (int index = 0; index < CCS_QUANTITY; index++)
  6753. {
  6754. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6755. {
  6756. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6757. }
  6758. }
  6759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6760. }
  6761. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6762. {
  6763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6764. {
  6765. tempIndex = ((gun_index==2) ? 1: 0);
  6766. }
  6767. else
  6768. {
  6769. tempIndex = gun_index;
  6770. }
  6771. for (int index = 0; index < GB_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6774. {
  6775. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6776. }
  6777. }
  6778. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6779. }
  6780. else if(gunType[gun_index] == GUN_TYPE_DO)
  6781. {
  6782. tempIndex = gun_index;
  6783. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6784. {
  6785. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6786. {
  6787. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6788. }
  6789. }
  6790. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6791. }
  6792. else
  6793. {
  6794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6795. {
  6796. tempIndex = 2;
  6797. }
  6798. else
  6799. {
  6800. tempIndex = gun_index;
  6801. }
  6802. for (int index = 0; index < AC_QUANTITY; index++)
  6803. {
  6804. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6805. {
  6806. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6807. }
  6808. }
  6809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6810. }
  6811. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6812. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6816. }
  6817. //***********************************************(6)SOC******************************************************/
  6818. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6819. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6820. (dataType == ReadingContext_Trigger))
  6821. {
  6822. 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))
  6823. {
  6824. //idx_sample=5;
  6825. //sampledValue = NULL;
  6826. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6827. {
  6828. tempIndex = ((gun_index==2) ? 1: 0);
  6829. }
  6830. else
  6831. {
  6832. tempIndex = gun_index;
  6833. }
  6834. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6835. {
  6836. //tempIndex = ((gun_index==2) ? 1: 0);
  6837. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6838. {
  6839. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6840. {
  6841. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6842. }
  6843. }
  6844. }
  6845. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6846. {
  6847. //tempIndex = ((gun_index==2) ? 1: 0);
  6848. for (int index = 0; index < CCS_QUANTITY; index++)
  6849. {
  6850. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6851. {
  6852. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6853. }
  6854. }
  6855. }
  6856. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6857. {
  6858. //tempIndex = ((gun_index==2) ? 1: 0);
  6859. for (int index = 0; index < GB_QUANTITY; index++)
  6860. {
  6861. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6862. {
  6863. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6864. }
  6865. }
  6866. }
  6867. else if(gunType[gun_index] == GUN_TYPE_DO)
  6868. {
  6869. //tempIndex = ((gun_index==2) ? 1: 0);
  6870. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6871. {
  6872. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6873. {
  6874. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6875. }
  6876. }
  6877. }
  6878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6879. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6880. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6881. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6884. }
  6885. }
  6886. //********************************(7)Current.Import L2************************************************/
  6887. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6888. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6889. (dataType == ReadingContext_Trigger))
  6890. {
  6891. // Only for AC 3 phase
  6892. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6893. {
  6894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6895. {
  6896. tempIndex = 2;
  6897. }
  6898. else
  6899. {
  6900. tempIndex = gun_index;
  6901. }
  6902. for (int index = 0; index < AC_QUANTITY; index++)
  6903. {
  6904. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6905. {
  6906. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6907. }
  6908. }
  6909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6910. }
  6911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6916. }
  6917. //********************************(8)Current.Import L3************************************************/
  6918. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6919. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6920. (dataType == ReadingContext_Trigger))
  6921. {
  6922. // Only for AC 3 phase
  6923. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6924. {
  6925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6926. {
  6927. tempIndex = 2;
  6928. }
  6929. else
  6930. {
  6931. tempIndex = gun_index;
  6932. }
  6933. for (int index = 0; index < AC_QUANTITY; index++)
  6934. {
  6935. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6936. {
  6937. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6938. }
  6939. }
  6940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6941. }
  6942. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6944. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6945. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6946. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6947. }
  6948. //***********************************************(9)VOLTAGE L2******************************************************/
  6949. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6950. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6951. (dataType == ReadingContext_Trigger))
  6952. {
  6953. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6954. {
  6955. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6956. {
  6957. tempIndex = 2;
  6958. }
  6959. else
  6960. {
  6961. tempIndex = gun_index;
  6962. }
  6963. for (int index = 0; index < AC_QUANTITY; index++)
  6964. {
  6965. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6966. {
  6967. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6968. }
  6969. }
  6970. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6971. }
  6972. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6973. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6974. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6975. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6976. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6977. }
  6978. //***********************************************(10)VOLTAGE L3******************************************************/
  6979. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6980. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6981. (dataType == ReadingContext_Trigger))
  6982. {
  6983. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6984. {
  6985. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6986. {
  6987. tempIndex = 2;
  6988. }
  6989. else
  6990. {
  6991. tempIndex = gun_index;
  6992. }
  6993. for (int index = 0; index < AC_QUANTITY; index++)
  6994. {
  6995. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6996. {
  6997. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6998. }
  6999. }
  7000. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7001. }
  7002. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7003. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7004. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7005. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7006. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7007. }
  7008. //***********************************************(11)Current.Offered******************************************************/
  7009. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7010. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7011. (dataType == ReadingContext_Trigger))
  7012. {
  7013. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7014. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7015. {
  7016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7017. {
  7018. tempIndex = ((gun_index==2) ? 1: 0);
  7019. }
  7020. else
  7021. {
  7022. tempIndex = gun_index;
  7023. }
  7024. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7025. {
  7026. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7027. {
  7028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7029. }
  7030. } // END OF FOR CHAdeMO_QUANTITY
  7031. }
  7032. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7033. {
  7034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7035. {
  7036. tempIndex = ((gun_index==2) ? 1: 0);
  7037. }
  7038. else
  7039. {
  7040. tempIndex = gun_index;
  7041. }
  7042. for (int index = 0; index < CCS_QUANTITY; index++)
  7043. {
  7044. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7045. {
  7046. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7047. }
  7048. } // END OF CCS_QUANTITY
  7049. }
  7050. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7051. {
  7052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7053. {
  7054. tempIndex = ((gun_index==2) ? 1: 0);
  7055. }
  7056. else
  7057. {
  7058. tempIndex = gun_index;
  7059. }
  7060. for (int index = 0; index < GB_QUANTITY; index++)
  7061. {
  7062. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7063. {
  7064. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7065. }
  7066. } // END OF GB_QUANTITY
  7067. }
  7068. else if(gunType[gun_index] == GUN_TYPE_DO)
  7069. {
  7070. tempIndex = gun_index;
  7071. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7072. {
  7073. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7074. {
  7075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7076. }
  7077. }
  7078. }
  7079. else
  7080. {
  7081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7082. {
  7083. tempIndex = 2;
  7084. }
  7085. else
  7086. {
  7087. tempIndex = gun_index;
  7088. }
  7089. for (int index = 0; index < AC_QUANTITY; index++)
  7090. {
  7091. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7092. {
  7093. uint16_t currentOffer;
  7094. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7095. {
  7096. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7097. }
  7098. else
  7099. {
  7100. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7101. }
  7102. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7103. }
  7104. }
  7105. }
  7106. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7109. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7110. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7111. }
  7112. //***********************************************(12)Power.Offered******************************************************/
  7113. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7114. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7115. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7116. {
  7117. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7118. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7119. {
  7120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7121. {
  7122. tempIndex = ((gun_index==2) ? 1: 0);
  7123. }
  7124. else
  7125. {
  7126. tempIndex = gun_index;
  7127. }
  7128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7129. {
  7130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7131. {
  7132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7133. }
  7134. } // END OF FOR CHAdeMO_QUANTITY
  7135. }
  7136. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7137. {
  7138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7139. {
  7140. tempIndex = ((gun_index==2) ? 1: 0);
  7141. }
  7142. else
  7143. {
  7144. tempIndex = gun_index;
  7145. }
  7146. for (int index = 0; index < CCS_QUANTITY; index++)
  7147. {
  7148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7149. {
  7150. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7151. }
  7152. } // END OF CCS_QUANTITY
  7153. }
  7154. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7155. {
  7156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7157. {
  7158. tempIndex = ((gun_index==2) ? 1: 0);
  7159. }
  7160. else
  7161. {
  7162. tempIndex = gun_index;
  7163. }
  7164. for (int index = 0; index < GB_QUANTITY; index++)
  7165. {
  7166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7167. {
  7168. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7169. }
  7170. } // END OF GB_QUANTITY
  7171. }
  7172. else if(gunType[gun_index] == GUN_TYPE_DO)
  7173. {
  7174. tempIndex = gun_index;
  7175. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7176. {
  7177. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7178. {
  7179. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7180. }
  7181. }
  7182. }
  7183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7188. }
  7189. // Message create ====================================================================================================
  7190. if(TRUE)
  7191. {
  7192. json_object *MeterValueReq = json_object_new_object();
  7193. json_object *MeterValues = json_object_new_array();
  7194. json_object *sampledValues = json_object_new_array();
  7195. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7196. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7197. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7198. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7199. {
  7200. json_object *MeterValue = json_object_new_object();
  7201. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7202. {
  7203. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7204. {
  7205. json_object *sampledValue = json_object_new_object();
  7206. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7207. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7208. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7209. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7210. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7211. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7212. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7213. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7214. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7215. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7216. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7217. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7218. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7219. json_object_array_add(sampledValues, sampledValue);
  7220. }
  7221. }
  7222. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7223. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7224. json_object_array_add(MeterValues, MeterValue);
  7225. }
  7226. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7227. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7228. ,gun_index + 1
  7229. ,MESSAGE_TYPE_CALL
  7230. ,guid
  7231. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7232. json_object_put(MeterValueReq);
  7233. }
  7234. // Put request guid to hash map
  7235. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7236. 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*/)
  7237. {
  7238. result = PASS;
  7239. //DEBUG_INFO("MeterValues mapitem pass\n");
  7240. }
  7241. if((dataType != ReadingContext_Trigger) &&
  7242. (dataType != ReadingContext_Sample_Clock) &&
  7243. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7244. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7245. else
  7246. {
  7247. if(FirstHeartBeat)
  7248. LWS_Send(queuedata +2);
  7249. }
  7250. return result;
  7251. }
  7252. int sendLogStatusNotificationRequest(char *status)
  7253. {
  7254. mtrace();
  7255. int result = PASS;
  7256. char message[4096]={0};
  7257. char guid[37]={0};
  7258. char tempdata[128]={0};
  7259. json_object *LogStatusNotification = json_object_new_object();
  7260. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7261. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7262. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7263. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7264. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7265. random_uuid(guid);
  7266. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7267. json_object_put(LogStatusNotification);
  7268. LWS_Send(message);
  7269. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7270. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7271. {
  7272. result = PASS;
  7273. }
  7274. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7275. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7276. return result;
  7277. }
  7278. int sendSecurityEventNotificationRequest()
  7279. {
  7280. mtrace();
  7281. int result = PASS;
  7282. char message[4096]={0};
  7283. char guid[37]={0};
  7284. char tempdata[128]={0};
  7285. json_object *SecurityEventNotification = json_object_new_object();
  7286. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7287. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7288. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7289. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7290. random_uuid(guid);
  7291. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7292. json_object_put(SecurityEventNotification);
  7293. LWS_Send(message);
  7294. sprintf(tempdata, "SecurityEventNotification,0");
  7295. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7296. {
  7297. result = PASS;
  7298. }
  7299. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7300. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7301. return result;
  7302. }
  7303. int sendSignCertificateRequest()
  7304. {
  7305. mtrace();
  7306. int result = PASS;
  7307. char message[4096]={0};
  7308. char guid[37]={0};
  7309. char tempdata[128]={0};
  7310. json_object *SignCertificate = json_object_new_object();
  7311. DEBUG_INFO("sendSignCertificateRequest...\n");
  7312. // Read csr file content
  7313. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7314. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7315. char *line = NULL;
  7316. size_t len = 0;
  7317. while(getline(&line, &len, fp) != -1)
  7318. {
  7319. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7320. {
  7321. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7322. }
  7323. }
  7324. fclose(fp);
  7325. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7326. random_uuid(guid);
  7327. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7328. json_object_put(SignCertificate);
  7329. LWS_Send(message);
  7330. sprintf(tempdata, "SignCertificate,0");
  7331. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7332. {
  7333. result = PASS;
  7334. }
  7335. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7336. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7337. return result;
  7338. }
  7339. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7340. {
  7341. mtrace();
  7342. int result = PASS;
  7343. char message[110]={0};
  7344. char guid[37]={0};
  7345. char tempdata[65]={0};
  7346. json_object *FirmwareStatusNotification = json_object_new_object();
  7347. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7348. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7349. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7350. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7351. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7352. random_uuid(guid);
  7353. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7354. json_object_put(FirmwareStatusNotification);
  7355. LWS_Send(message);
  7356. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7357. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7358. {
  7359. result = PASS;
  7360. }
  7361. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7362. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7363. return result;
  7364. }
  7365. //==========================================
  7366. // send confirm routine
  7367. //==========================================
  7368. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7369. {
  7370. mtrace();
  7371. int result = FAIL;
  7372. char message[100]={0};
  7373. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7374. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7375. LWS_Send(message);
  7376. result = TRUE;
  7377. return result;
  7378. }
  7379. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7380. {
  7381. mtrace();
  7382. int result = FAIL;
  7383. char message[100]={0};
  7384. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7385. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7386. LWS_Send(message);
  7387. result = TRUE;
  7388. return result;
  7389. }
  7390. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7391. {
  7392. mtrace();
  7393. int result = FAIL;
  7394. char message[100]={0};
  7395. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7396. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7397. LWS_Send(message);
  7398. result = TRUE;
  7399. return result;
  7400. }
  7401. int sendClearCacheConfirmation(char *uuid,char *payload)
  7402. {
  7403. mtrace();
  7404. int result = FAIL;
  7405. char message[500]={0};
  7406. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7407. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7408. LWS_Send(message);
  7409. return result;
  7410. }
  7411. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7412. {
  7413. mtrace();
  7414. int result = FAIL;
  7415. char message[500]={0};
  7416. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7417. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7418. LWS_Send(message);
  7419. return result;
  7420. }
  7421. int sendDataTransferConfirmation(char *uuid,char *payload)
  7422. {
  7423. mtrace();
  7424. char statusStr[20]={0};
  7425. char dataStr[10]={0};
  7426. char sstr[20]={0};
  7427. int c = 0;
  7428. char *loc;
  7429. int result = FAIL;
  7430. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7431. /**********************status**************************/
  7432. loc = strstr(payload, "status");
  7433. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7434. c = 0;
  7435. while (loc[3+strlen("status")+c] != '\"')
  7436. {
  7437. sstr[c] = loc[3+strlen("status")+c];
  7438. c++;
  7439. }
  7440. sstr[c] = '\0';
  7441. strcpy(statusStr, sstr);
  7442. /**********************data**************************/
  7443. loc = strstr(payload, "data");
  7444. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7445. c = 0;
  7446. while (loc[3+strlen("data")+c] != '\"')
  7447. {
  7448. sstr[c] = loc[3+strlen("data")+c];
  7449. c++;
  7450. }
  7451. sstr[c] = '\0';
  7452. strcpy(dataStr, sstr);
  7453. return result;
  7454. }
  7455. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7456. {
  7457. mtrace();
  7458. int result = FAIL;
  7459. char message[1000]={0};
  7460. int CompositeScheduleIndex = 0;
  7461. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7462. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7463. if(nPeriod == 0)
  7464. {
  7465. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7466. {
  7467. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7468. ,MESSAGE_TYPE_CALLRESULT
  7469. ,uuid
  7470. ,payload
  7471. ,connectorIdInt);
  7472. }
  7473. else
  7474. {
  7475. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7476. ,MESSAGE_TYPE_CALLRESULT
  7477. ,uuid
  7478. ,payload
  7479. ,connectorIdInt
  7480. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7481. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7482. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7483. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7484. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7485. }
  7486. }
  7487. else
  7488. {
  7489. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7490. ,MESSAGE_TYPE_CALLRESULT
  7491. ,uuid
  7492. ,payload
  7493. ,connectorIdInt
  7494. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7495. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7496. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7497. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7498. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7499. {
  7500. if (idx_sample == 0)
  7501. {
  7502. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7503. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7504. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7505. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7506. }
  7507. else
  7508. {
  7509. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7510. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7511. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7512. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7513. }
  7514. }
  7515. sprintf(message + strlen(message), "]}}]");
  7516. }
  7517. LWS_Send(message);
  7518. result = TRUE;
  7519. return result;
  7520. }
  7521. int sendGetConfigurationConfirmation(char *uuid)
  7522. {
  7523. mtrace();
  7524. int result = FAIL;
  7525. int MaxKeySupported = 0;
  7526. int sentConfigurationNumber= 0;
  7527. int sentunConfigurationNumber= 0;
  7528. char message[1024*10]={0};
  7529. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7530. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7531. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7532. ,MESSAGE_TYPE_CALLRESULT
  7533. ,uuid );
  7534. //configuration key
  7535. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7536. {
  7537. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7538. {
  7539. if (sentConfigurationNumber == 0)
  7540. {
  7541. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7542. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7543. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7544. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7545. }
  7546. else
  7547. {
  7548. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7549. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7550. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7551. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7552. }
  7553. sentConfigurationNumber = sentConfigurationNumber + 1;
  7554. }
  7555. }
  7556. sprintf(message + strlen(message), "]");
  7557. if(UnknownKeynum != 0)
  7558. {
  7559. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7560. //unkown key
  7561. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7562. {
  7563. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7564. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7565. if(sentunConfigurationNumber == 0)
  7566. {
  7567. sprintf(message + strlen(message), "\"%s\""
  7568. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7569. }
  7570. else
  7571. {
  7572. sprintf(message + strlen(message), ",\"%s\""
  7573. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7574. }
  7575. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7576. }
  7577. sprintf(message + strlen(message), "]");
  7578. }
  7579. sprintf(message + strlen(message), "}]");
  7580. LWS_Send(message);
  7581. return result;
  7582. }
  7583. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7584. {
  7585. mtrace();
  7586. int result = FAIL;
  7587. char message[400]={0};
  7588. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7589. if(strcmp(payload,"")==0)
  7590. {
  7591. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7592. }
  7593. else
  7594. {
  7595. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7596. }
  7597. LWS_Send(message);
  7598. result = TRUE;
  7599. return result;
  7600. }
  7601. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7602. {
  7603. mtrace();
  7604. int result = FAIL;
  7605. char message[80]={0};
  7606. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7607. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7608. LWS_Send(message);
  7609. result = TRUE;
  7610. return result;
  7611. }
  7612. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7613. {
  7614. mtrace();
  7615. int result = FAIL;
  7616. char message[80]={0};
  7617. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7618. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7619. LWS_Send(message);
  7620. result = TRUE;
  7621. return result;
  7622. }
  7623. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7624. {
  7625. mtrace();
  7626. int result = FAIL;
  7627. char message[80]={0};
  7628. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7629. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7630. LWS_Send(message);
  7631. result = TRUE;
  7632. return result;
  7633. }
  7634. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7635. {
  7636. mtrace();
  7637. int result = FAIL;
  7638. char message[80]={0};
  7639. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7640. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7641. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7642. LWS_Send(message);
  7643. result = TRUE;
  7644. return result;
  7645. }
  7646. int sendResetConfirmation(char *uuid,char *payload)
  7647. {
  7648. mtrace();
  7649. int result = FAIL;
  7650. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7651. char message[80]={0};
  7652. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7653. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7654. LWS_Send(message);
  7655. result = TRUE;
  7656. return result;
  7657. }
  7658. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7659. {
  7660. mtrace();
  7661. int result = FAIL;
  7662. char message[500]={0};
  7663. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7664. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7665. LWS_Send(message);
  7666. result = TRUE;
  7667. return result;
  7668. }
  7669. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7670. {
  7671. mtrace();
  7672. int result = FAIL;
  7673. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7674. char message[80]={0};
  7675. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7676. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7677. LWS_Send(message);
  7678. result = TRUE;
  7679. return result;
  7680. }
  7681. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7682. {
  7683. mtrace();
  7684. int result = FAIL;
  7685. char message[80]={0};
  7686. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7687. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7688. LWS_Send(message);
  7689. result = TRUE;
  7690. return result;
  7691. }
  7692. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7693. {
  7694. mtrace();
  7695. int result = FAIL;
  7696. char message[80]={0};
  7697. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7698. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7699. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7700. LWS_Send(message);
  7701. result = TRUE;
  7702. return result;
  7703. }
  7704. int sendUpdateFirmwareConfirmation(char *uuid)
  7705. {
  7706. mtrace();
  7707. int result = FAIL;
  7708. char message[60]={0};
  7709. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7710. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7711. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7712. LWS_Send(message);
  7713. result = TRUE;
  7714. return result;
  7715. }
  7716. int sendCertificateSignedConfirmation(char *uuid)
  7717. {
  7718. mtrace();
  7719. int result = PASS;
  7720. char message[4096]={0};
  7721. json_object *CertificateSigned = json_object_new_object();
  7722. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7723. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7724. sprintf(message,"[%d,\"%s\",%s]"
  7725. ,MESSAGE_TYPE_CALLRESULT
  7726. ,uuid
  7727. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7728. json_object_put(CertificateSigned);
  7729. LWS_Send(message);
  7730. return result;
  7731. }
  7732. int sendDeleteCertificateConfirmation(char *uuid)
  7733. {
  7734. mtrace();
  7735. int result = PASS;
  7736. char message[4096]={0};
  7737. json_object *DeleteCertificate = json_object_new_object();
  7738. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7739. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7740. sprintf(message,"[%d,\"%s\",%s]"
  7741. ,MESSAGE_TYPE_CALLRESULT
  7742. ,uuid
  7743. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7744. json_object_put(DeleteCertificate);
  7745. LWS_Send(message);
  7746. return result;
  7747. }
  7748. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7749. {
  7750. mtrace();
  7751. int result = PASS;
  7752. char message[4096]={0};
  7753. json_object *ExtendedTriggerMessage = json_object_new_object();
  7754. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7755. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7756. sprintf(message,"[%d,\"%s\",%s]"
  7757. ,MESSAGE_TYPE_CALLRESULT
  7758. ,uuid
  7759. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7760. json_object_put(ExtendedTriggerMessage);
  7761. LWS_Send(message);
  7762. return result;
  7763. }
  7764. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7765. {
  7766. mtrace();
  7767. int result = PASS;
  7768. char message[4096]={0};
  7769. json_object *GetInstalledCertificateIds = json_object_new_object();
  7770. json_object *certificateHashDataDatas = json_object_new_array();
  7771. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7772. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7773. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7774. {
  7775. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7776. {
  7777. json_object *certificateHashData = json_object_new_object();
  7778. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7779. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7780. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7781. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7782. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7783. }
  7784. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7785. }
  7786. else
  7787. {
  7788. json_object_put(certificateHashDataDatas);
  7789. }
  7790. sprintf(message,"[%d,\"%s\",%s]"
  7791. ,MESSAGE_TYPE_CALLRESULT
  7792. ,uuid
  7793. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7794. json_object_put(GetInstalledCertificateIds);
  7795. LWS_Send(message);
  7796. return result;
  7797. }
  7798. int sendGetLogConfirmation(char *uuid)
  7799. {
  7800. mtrace();
  7801. int result = PASS;
  7802. char message[4096]={0};
  7803. json_object *GetLog = json_object_new_object();
  7804. DEBUG_INFO("sendGetLogConfirmation...\n");
  7805. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7806. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7807. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7808. sprintf(message,"[%d,\"%s\",%s]"
  7809. ,MESSAGE_TYPE_CALLRESULT
  7810. ,uuid
  7811. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7812. json_object_put(GetLog);
  7813. LWS_Send(message);
  7814. return result;
  7815. }
  7816. int sendInstallCertificateConfirmation(char *uuid)
  7817. {
  7818. mtrace();
  7819. int result = PASS;
  7820. char message[4096]={0};
  7821. json_object *InstallCertificate = json_object_new_object();
  7822. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7823. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7824. sprintf(message,"[%d,\"%s\",%s]"
  7825. ,MESSAGE_TYPE_CALLRESULT
  7826. ,uuid
  7827. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7828. json_object_put(InstallCertificate);
  7829. LWS_Send(message);
  7830. return result;
  7831. }
  7832. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7833. {
  7834. mtrace();
  7835. int result = PASS;
  7836. char message[4096]={0};
  7837. json_object *SignedUpdateFirmware = json_object_new_object();
  7838. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7839. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7840. sprintf(message,"[%d,\"%s\",%s]"
  7841. ,MESSAGE_TYPE_CALLRESULT
  7842. ,uuid
  7843. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7844. json_object_put(SignedUpdateFirmware);
  7845. LWS_Send(message);
  7846. return result;
  7847. }
  7848. int sendUnknownConfirmation(char *uuid)
  7849. {
  7850. mtrace();
  7851. int result = PASS;
  7852. char message[256]={0};
  7853. DEBUG_INFO("sendUnknownConfirmation...\n");
  7854. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7855. LWS_Send(message);
  7856. return result;
  7857. }
  7858. //==========================================
  7859. // Handle server request routine Start
  7860. //==========================================
  7861. int handleCancelReservationRequest(char *uuid, char *payload)
  7862. {
  7863. mtrace();
  7864. int result = FAIL;
  7865. int gunNO = 0;
  7866. int reservationIdInt = -1;
  7867. char comfirmstr[20];
  7868. DEBUG_INFO("handleCancelReservationRequest...\n");
  7869. json_object *CancelReservation;
  7870. CancelReservation = json_tokener_parse(payload);
  7871. if(!is_error(CancelReservation))
  7872. {
  7873. // Required data
  7874. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7875. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7876. }
  7877. json_object_put(CancelReservation);
  7878. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7879. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7880. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7881. if(reservationIdInt != -1)
  7882. {
  7883. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7884. //check Transaction active
  7885. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7887. {
  7888. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7889. {
  7890. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7891. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7892. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7893. {
  7894. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7895. }
  7896. else
  7897. {
  7898. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7899. }
  7900. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7901. goto end;
  7902. }
  7903. }
  7904. for (int index = 0; index < CCS_QUANTITY; index++)
  7905. {
  7906. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7907. {
  7908. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7909. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7910. if(gunType[2] == GUN_TYPE_CCS)
  7911. {
  7912. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7913. }
  7914. else
  7915. {
  7916. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7917. }
  7918. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7919. goto end;
  7920. }
  7921. }
  7922. for (int index = 0; index < GB_QUANTITY; index++)
  7923. {
  7924. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7925. {
  7926. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7927. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7928. if(gunType[2] == GUN_TYPE_GBT)
  7929. {
  7930. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7931. }
  7932. else
  7933. {
  7934. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7935. }
  7936. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7937. goto end;
  7938. }
  7939. }
  7940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7941. {
  7942. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7943. {
  7944. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7945. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7946. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7947. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7948. goto end;
  7949. }
  7950. }
  7951. for (int index = 0; index < AC_QUANTITY; index++)
  7952. {
  7953. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7954. {
  7955. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7956. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7957. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7958. {
  7959. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7960. }
  7961. else
  7962. {
  7963. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7964. }
  7965. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7966. goto end;
  7967. }
  7968. }
  7969. }
  7970. //The reservationId does NOT match the reservationId
  7971. sendCancelReservationConfirmation(uuid, comfirmstr);
  7972. end:
  7973. // Fill in ocpp packet uuid
  7974. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7975. return result;
  7976. }
  7977. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7978. {
  7979. mtrace();
  7980. int result = FAIL;
  7981. int gunIndex = -1;
  7982. char typeStr[16]={0};
  7983. char comfirmstr[20];
  7984. int specificId = FALSE;
  7985. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7986. json_object *ChangeAvailability;
  7987. ChangeAvailability = json_tokener_parse(payload);
  7988. if(!is_error(ChangeAvailability))
  7989. {
  7990. // Required data
  7991. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7992. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7993. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7994. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7995. }
  7996. json_object_put(ChangeAvailability);
  7997. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7998. {
  7999. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8000. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8001. }
  8002. else if(gunIndex == 0)
  8003. {
  8004. for(int i=0; i < gunTotalNumber; i++)
  8005. {
  8006. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8007. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8008. }
  8009. }
  8010. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8011. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8012. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8013. {
  8014. specificId = TRUE;
  8015. }
  8016. if(specificId == FALSE)
  8017. goto end;
  8018. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8019. {
  8020. //----------------------gunIndex is 0 ------------------------------------------------//
  8021. if(gunIndex == 0)
  8022. {
  8023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8024. {
  8025. for(int i=0; i < gunTotalNumber; i++)
  8026. {
  8027. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8028. {
  8029. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8030. {
  8031. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8032. {
  8033. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8034. goto end;
  8035. }
  8036. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8037. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8038. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8039. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8040. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8041. {
  8042. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8043. goto end;
  8044. }
  8045. }
  8046. }//END FOR CHAdeMO_QUANTITY
  8047. for (int index = 0; index < CCS_QUANTITY; index++)
  8048. {
  8049. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8050. {
  8051. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8052. {
  8053. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8054. goto end;
  8055. }
  8056. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8057. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8058. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8059. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8060. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8061. {
  8062. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8063. goto end;
  8064. }
  8065. }
  8066. }//END FOR CCS_QUANTITY
  8067. for (int index = 0; index < GB_QUANTITY; index++)
  8068. {
  8069. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8070. {
  8071. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8072. {
  8073. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8074. goto end;
  8075. }
  8076. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8077. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8078. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8079. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8080. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8081. {
  8082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8083. goto end;
  8084. }
  8085. }
  8086. }// END FOR GB_QUANTITY
  8087. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8088. {
  8089. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8090. {
  8091. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8092. {
  8093. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8094. goto end;
  8095. }
  8096. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8097. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8098. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8099. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8100. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8101. {
  8102. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8103. goto end;
  8104. }
  8105. }
  8106. }// END FOR GENERAL_GUN_QUANTITY
  8107. for (int index = 0; index < AC_QUANTITY; index++)
  8108. {
  8109. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8110. {
  8111. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8112. {
  8113. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8114. goto end;
  8115. }
  8116. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8117. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8118. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8119. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8120. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8121. {
  8122. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8123. goto end;
  8124. }
  8125. }
  8126. }//END FOR AC_QUANTITY
  8127. }// END FOR gunTotalNumber
  8128. }
  8129. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8130. {
  8131. for(int i=0; i < gunTotalNumber; i++)
  8132. {
  8133. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8134. {
  8135. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8136. goto end;
  8137. }
  8138. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8141. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8142. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8143. {
  8144. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8145. goto end;
  8146. }
  8147. }
  8148. }
  8149. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8150. goto end;
  8151. }
  8152. //----------------------gunIndex is not 0 ------------------------------------------------//
  8153. //check Transaction active
  8154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8155. {
  8156. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8157. {
  8158. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8159. {
  8160. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8161. goto end;
  8162. }
  8163. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8164. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8165. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8168. {
  8169. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8170. goto end;
  8171. }
  8172. else
  8173. {
  8174. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8175. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8176. goto end;
  8177. }
  8178. }
  8179. }//END FOR CHAdeMO_QUANTITY
  8180. for (int index = 0; index < CCS_QUANTITY; index++)
  8181. {
  8182. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8183. {
  8184. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8185. {
  8186. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8187. goto end;
  8188. }
  8189. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8190. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8191. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8192. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8193. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8194. {
  8195. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8196. goto end;
  8197. }
  8198. else
  8199. {
  8200. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8201. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8202. goto end;
  8203. }
  8204. }
  8205. }//END FOR CCS_QUANTITY
  8206. for (int index = 0; index < GB_QUANTITY; index++)
  8207. {
  8208. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8209. {
  8210. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8211. {
  8212. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8213. goto end;
  8214. }
  8215. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8216. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8217. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8218. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8219. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8220. {
  8221. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8222. goto end;
  8223. }
  8224. else
  8225. {
  8226. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8227. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8228. goto end;
  8229. }
  8230. }
  8231. }// END FOR GB_QUANTITY
  8232. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8233. {
  8234. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8235. {
  8236. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8237. {
  8238. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8239. goto end;
  8240. }
  8241. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8242. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8243. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8244. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8245. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8246. {
  8247. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8248. goto end;
  8249. }
  8250. else
  8251. {
  8252. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8254. goto end;
  8255. }
  8256. }
  8257. }// END FOR GENERAL_GUN_QUANTITY
  8258. for (int index = 0; index < AC_QUANTITY; index++)
  8259. {
  8260. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8261. {
  8262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8263. {
  8264. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8265. goto end;
  8266. }
  8267. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8268. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8269. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8270. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8271. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8272. {
  8273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8274. goto end;
  8275. }
  8276. else
  8277. {
  8278. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8279. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8280. goto end;
  8281. }
  8282. }
  8283. }//END FOR AC_QUANTITY
  8284. }//END FOR AvailabilityTypeStr[Inoperative]
  8285. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8286. {
  8287. //----------------------gunIndex is 0 ------------------------------------------------//
  8288. if(gunIndex == 0)
  8289. {
  8290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8291. {
  8292. for(int i=0; i < gunTotalNumber; i++)
  8293. {
  8294. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8295. {
  8296. 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
  8297. {
  8298. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8299. goto end;
  8300. }
  8301. }//END FOR CHAdeMO_QUANTITY
  8302. for (int index = 0; index < CCS_QUANTITY; index++)
  8303. {
  8304. 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
  8305. {
  8306. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8307. goto end;
  8308. }
  8309. }//END FOR CCS_QUANTITY
  8310. for (int index = 0; index < GB_QUANTITY; index++)
  8311. {
  8312. 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
  8313. {
  8314. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8315. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8316. goto end;
  8317. }
  8318. }// END FOR GB_QUANTITY
  8319. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8320. {
  8321. 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
  8322. {
  8323. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8324. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8325. goto end;
  8326. }
  8327. }// END FOR GENERAL_GUN_QUANTITY
  8328. for (int index = 0; index < AC_QUANTITY; index++)
  8329. {
  8330. 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
  8331. {
  8332. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8333. goto end;
  8334. }
  8335. }//END FOR CHAdeMO_QUANTITY
  8336. }// END FOR gunTotalNumber
  8337. }
  8338. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8339. {
  8340. for(int i=0; i < gunTotalNumber; i++)
  8341. {
  8342. for (int index = 0; index < AC_QUANTITY; index++)
  8343. {
  8344. 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
  8345. {
  8346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8347. goto end;
  8348. }
  8349. }//END FOR CHAdeMO_QUANTITY
  8350. } // END FOR gunTotalNumber
  8351. }
  8352. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8353. goto end;
  8354. }
  8355. //----------------------gunIndex is not 0 ------------------------------------------------//
  8356. //check Transaction active
  8357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8358. {
  8359. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8360. {
  8361. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8362. goto end;
  8363. }
  8364. }//END FOR CHAdeMO_QUANTITY
  8365. for (int index = 0; index < CCS_QUANTITY; index++)
  8366. {
  8367. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8368. {
  8369. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8370. goto end;
  8371. }
  8372. }//END FOR CCS_QUANTITY
  8373. for (int index = 0; index < GB_QUANTITY; index++)
  8374. {
  8375. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8376. {
  8377. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8378. goto end;
  8379. }
  8380. }// END FOR GB_QUANTITY
  8381. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8382. {
  8383. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8384. {
  8385. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8386. goto end;
  8387. }
  8388. }// END FOR GENERAL_GUN_QUANTITY
  8389. for (int index = 0; index < AC_QUANTITY; index++)
  8390. {
  8391. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8392. {
  8393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8394. goto end;
  8395. }
  8396. }//END FOR AC_QUANTITY
  8397. }//END FOR AvailabilityTypeStr[Operative]
  8398. end:
  8399. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8400. {
  8401. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8402. }
  8403. else
  8404. {
  8405. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8406. }
  8407. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8408. {
  8409. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8410. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8411. }
  8412. else if(gunIndex == 0)
  8413. {
  8414. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8415. {
  8416. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8417. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8418. }
  8419. }
  8420. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8421. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8422. return result;
  8423. }
  8424. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8425. {
  8426. mtrace();
  8427. int valueInvalid = NO;
  8428. int result = FAIL;
  8429. char keystr[40]={0};
  8430. char valuestr[501]={0}; //value should be limited in 500 bytes
  8431. char comfirmstr[20]={0};
  8432. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8433. json_object *ChangeConfiguration;
  8434. ChangeConfiguration = json_tokener_parse(payload);
  8435. if(!is_error(ChangeConfiguration))
  8436. {
  8437. // Required data
  8438. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8439. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8440. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8441. {
  8442. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8443. }
  8444. else
  8445. {
  8446. valueInvalid = YES;
  8447. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8448. }
  8449. }
  8450. json_object_put(ChangeConfiguration);
  8451. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8452. {
  8453. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8454. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8455. }
  8456. else
  8457. {
  8458. int status = setKeyValue(keystr, valuestr);
  8459. switch(status)
  8460. {
  8461. case ConfigurationStatus_Accepted:
  8462. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8463. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8464. StoreConfigurationTable();
  8465. break;
  8466. case RebootRequired:
  8467. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8468. StoreConfigurationTable();
  8469. break;
  8470. case NotSupported:
  8471. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8472. break;
  8473. case ConfigurationStatus_Rejected:
  8474. default:
  8475. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8476. break;
  8477. }
  8478. }
  8479. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8480. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8481. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8482. {
  8483. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8484. SetOcppConnStatus(FALSE);
  8485. }
  8486. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8487. {
  8488. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8489. }
  8490. return result;
  8491. }
  8492. int handleClearCacheRequest(char *uuid, char *payload)
  8493. {
  8494. mtrace();
  8495. int result = FAIL;
  8496. char comfirmstr[20];
  8497. char rmFileCmd[100]={0};
  8498. struct stat stats;
  8499. DEBUG_INFO("handleClearCacheRequest...\n");
  8500. stat("/Storage/OCPP", &stats);
  8501. // Check for directory existence
  8502. if (S_ISDIR(stats.st_mode) == 1)
  8503. {}
  8504. else
  8505. {
  8506. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8507. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8508. system(rmFileCmd);
  8509. }
  8510. if(OCPP_cleanLocalCache())
  8511. {
  8512. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8513. }
  8514. else
  8515. {
  8516. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8517. }
  8518. sendClearCacheConfirmation(uuid, comfirmstr);
  8519. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8520. return result;
  8521. }
  8522. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8523. {
  8524. mtrace();
  8525. int result = FAIL;
  8526. int resultRename;
  8527. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8528. char chargingProfilePurposeStr[26]={0};
  8529. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8530. char tempchargingProfilePurposeStr[26]={0};
  8531. char str[100]={0};
  8532. char fname[200]={0};
  8533. char comfirmstr[20]={0};
  8534. char word[1600]={0};
  8535. int clearflag = FALSE;
  8536. int chargingProfileIdIsNULL = FALSE;
  8537. int connectorIsNULL = FALSE;
  8538. int chargingProfilePurposeIsNULL = FALSE;
  8539. int stackLevelIsNULL = FALSE;
  8540. //int GotoEnd = FALSE;
  8541. FILE *fptr1, *fptr2;
  8542. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8543. int n_chargingProfile=0;
  8544. int isEmptyFile = FALSE;
  8545. char sLineWord[1600]={0};
  8546. char chargingProfiles[10][100]={0};
  8547. int ChargeProfileCount = 0;
  8548. int ch;
  8549. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8550. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8551. json_object *ClearChargingProfile;
  8552. ClearChargingProfile = json_tokener_parse(payload);
  8553. if(!is_error(ClearChargingProfile))
  8554. {
  8555. // Optional data
  8556. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8557. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8558. else
  8559. chargingProfileIdIsNULL = TRUE;
  8560. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8561. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8562. else
  8563. connectorIsNULL = TRUE;
  8564. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8565. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8566. else
  8567. chargingProfilePurposeIsNULL = TRUE;
  8568. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8569. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8570. else
  8571. stackLevelIsNULL = TRUE;
  8572. }
  8573. json_object_put(ClearChargingProfile);
  8574. if(connectorIsNULL == FALSE)
  8575. {
  8576. switch(connectorIdInt)
  8577. {
  8578. case 0:
  8579. if(chargingProfilePurposeIsNULL == TRUE)
  8580. {
  8581. int l = 0;
  8582. strcpy(fname, ChargePointMaxProfile_JSON);
  8583. if((access(fname,F_OK))!=-1)
  8584. {
  8585. strcpy(chargingProfiles[l], fname);
  8586. l = l + 1;
  8587. }
  8588. strcpy(fname, TxDefaultProfile_0_JSON);
  8589. if((access(fname,F_OK))!=-1)
  8590. {
  8591. strcpy(chargingProfiles[l], fname);
  8592. l = l + 1;
  8593. }
  8594. ChargeProfileCount = l;
  8595. }
  8596. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8597. {
  8598. strcpy(fname, ChargePointMaxProfile_JSON);
  8599. if((access(fname,F_OK))!=-1)
  8600. {
  8601. strcpy(chargingProfiles[0], fname);
  8602. ChargeProfileCount = 1;
  8603. }
  8604. }
  8605. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8606. {
  8607. strcpy(fname, TxDefaultProfile_0_JSON);
  8608. if((access(fname,F_OK))!=-1)
  8609. {
  8610. strcpy(chargingProfiles[0], fname);
  8611. ChargeProfileCount = 1;
  8612. }
  8613. }
  8614. break;
  8615. default:
  8616. if(chargingProfilePurposeIsNULL == TRUE)
  8617. {
  8618. int m = 0;
  8619. memset(fname, 0, ARRAY_SIZE(fname));
  8620. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8621. if((access(fname,F_OK))!=-1)
  8622. {
  8623. strcpy(chargingProfiles[m], fname);
  8624. m = m + 1;
  8625. }
  8626. memset(fname, 0, ARRAY_SIZE(fname));
  8627. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8628. if((access(fname,F_OK))!=-1)
  8629. {
  8630. strcpy(chargingProfiles[m], fname);
  8631. m = m + 1;
  8632. }
  8633. ChargeProfileCount = m;
  8634. }
  8635. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8636. {
  8637. //strcpy(fname, TxDefaultProfile_1_JSON);
  8638. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8639. if((access(fname,F_OK))!=-1)
  8640. {
  8641. strcpy(chargingProfiles[0], fname);
  8642. ChargeProfileCount = 1;
  8643. }
  8644. }
  8645. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8646. {
  8647. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8648. if((access(fname,F_OK))!=-1)
  8649. {
  8650. strcpy(chargingProfiles[0], fname);
  8651. ChargeProfileCount = 1;
  8652. }
  8653. //strcpy(fname, TxProfile_1_JSON);
  8654. }
  8655. //strcpy(fname, ChargePointMaxProfile_JSON );
  8656. break;
  8657. }
  8658. }
  8659. else // Check all Charging Profiles
  8660. {
  8661. int i = 0;
  8662. char fnametemp[200]={0};
  8663. ChargeProfileCount = 0;
  8664. //Check ChargePointMaxProfile.json exit
  8665. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8666. {
  8667. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8668. i = i + 1;
  8669. }
  8670. //Check TxDefaultProfile_0.json exit
  8671. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8672. {
  8673. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8674. i = i + 1;
  8675. }
  8676. //Check TxDefaultProfile_%d.json
  8677. for(int j=1; j <= gunTotalNumber; j++)
  8678. {
  8679. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8680. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8681. if((access(fnametemp,F_OK))!=-1)
  8682. {
  8683. strcpy(chargingProfiles[i], fnametemp);
  8684. i = i + 1;
  8685. }
  8686. }
  8687. //Check TxProfile_%d.json
  8688. for(int j=1; j <= gunTotalNumber; j++)
  8689. {
  8690. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8691. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8692. if((access(fnametemp,F_OK))!=-1)
  8693. {
  8694. strcpy(chargingProfiles[i], fnametemp);
  8695. i = i + 1;
  8696. }
  8697. }
  8698. ChargeProfileCount = i;
  8699. }// End connectorIsNULL is TRUE
  8700. if(ChargeProfileCount == 0)
  8701. {
  8702. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8703. goto end;
  8704. }
  8705. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8706. {
  8707. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8708. goto end;
  8709. }
  8710. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8711. {
  8712. memset(str, 0, ARRAY_SIZE(str));
  8713. // clear temp file
  8714. sprintf(str,"rm -f %s",temp);
  8715. system(str);
  8716. for(int k=0; k < ChargeProfileCount; k++)
  8717. {
  8718. memset(str, 0, ARRAY_SIZE(str));
  8719. //clear file in C
  8720. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8721. system(str);
  8722. }
  8723. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8724. goto end;
  8725. }
  8726. else if(connectorIsNULL == TRUE)
  8727. {
  8728. for(int k=0; k < ChargeProfileCount; k++)
  8729. {
  8730. fptr1 = fopen(chargingProfiles[k], "r");
  8731. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8732. //Check Charging Profile Count
  8733. while(fscanf(fptr1, "%s", word) != EOF)
  8734. {
  8735. //DEBUG_INFO("word=%s\n",word);
  8736. if(strstr(word, "chargingProfileId")!= NULL)
  8737. {
  8738. //DEBUG_INFO("test chargingProfileId \n");
  8739. n_chargingProfile = n_chargingProfile + 1;
  8740. //DEBUG_INFO("chargingProfileId Found\n");
  8741. }
  8742. }
  8743. rewind(fptr1);
  8744. //search Charging Profile Element
  8745. //int i= 0;
  8746. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8747. {
  8748. json_object *tmpProfilee;
  8749. tmpProfilee = json_tokener_parse(sLineWord);
  8750. if(!is_error(tmpProfilee))
  8751. {
  8752. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8753. {
  8754. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8755. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8756. }
  8757. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8758. {
  8759. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8760. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8761. }
  8762. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8763. {
  8764. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8765. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8766. }
  8767. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8768. {
  8769. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8770. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8771. }
  8772. }
  8773. json_object_put(tmpProfilee);
  8774. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8775. {
  8776. //------- not write to fptr2-------//
  8777. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8778. //clearflag = TRUE;
  8779. }
  8780. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8781. {
  8782. //------- not write to fptr2-------//
  8783. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8784. }
  8785. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8786. {
  8787. //------- not write to fptr2-------//
  8788. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8789. }
  8790. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8791. {
  8792. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8793. }
  8794. else
  8795. {
  8796. fprintf(fptr2, sLineWord);//writing data into file
  8797. }
  8798. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8799. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8800. if(clearflag == TRUE)
  8801. {
  8802. fclose(fptr1);
  8803. fclose(fptr2);
  8804. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8805. system(str);
  8806. // clear temp file
  8807. sprintf(str,"rm -f %s",temp);
  8808. system(str);
  8809. }
  8810. else
  8811. {
  8812. fclose(fptr1);
  8813. fclose(fptr2);
  8814. memset(str, 0, ARRAY_SIZE(str));
  8815. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8816. system(str);
  8817. resultRename = rename(temp, chargingProfiles[k]);
  8818. if(resultRename == 0)
  8819. {
  8820. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8821. }
  8822. else
  8823. {
  8824. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8825. }
  8826. if(comfirmstr[0]== 0)
  8827. {
  8828. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8829. }
  8830. //Check chargingProfile is empty file
  8831. /*------ Read the file ----------------*/
  8832. fptr1=fopen(chargingProfiles[k],"r");
  8833. ch=fgetc(fptr1);
  8834. rewind(fptr1);
  8835. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8836. if(ch!=EOF)
  8837. {
  8838. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8839. {
  8840. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8841. if(sLineWord[0]=='\0')
  8842. {
  8843. isEmptyFile = TRUE;
  8844. break;
  8845. }
  8846. else
  8847. {
  8848. isEmptyFile = FALSE;
  8849. break;
  8850. }
  8851. }
  8852. }
  8853. else
  8854. isEmptyFile = TRUE;
  8855. fclose(fptr1);
  8856. if(isEmptyFile == TRUE)
  8857. {
  8858. memset(str, 0, ARRAY_SIZE(str));
  8859. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8860. system(str);
  8861. }
  8862. }
  8863. }// End of while(int k=0; k < ChargePointCount; k++)
  8864. }
  8865. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8866. {
  8867. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8868. for(int k=0; k < ChargeProfileCount; k++)
  8869. {
  8870. fptr1 = fopen(chargingProfiles[k], "r");
  8871. fptr2 = fopen(temp, "w+");
  8872. //Check Charging Profile Count
  8873. while(fscanf(fptr1, "%s", word) != EOF)
  8874. {
  8875. //DEBUG_INFO("word=%s\n",word);
  8876. if(strstr(word, "chargingProfileId")!= NULL)
  8877. {
  8878. n_chargingProfile = n_chargingProfile + 1;
  8879. }
  8880. }
  8881. rewind(fptr1);
  8882. //search Charging Profile Element
  8883. //int i= 0;
  8884. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8885. {
  8886. json_object *tmpProfilee;
  8887. tmpProfilee = json_tokener_parse(sLineWord);
  8888. if(!is_error(tmpProfilee))
  8889. {
  8890. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8891. {
  8892. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8893. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8894. }
  8895. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8896. {
  8897. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8898. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8899. }
  8900. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8901. {
  8902. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8903. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8904. }
  8905. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8906. {
  8907. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8908. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8909. }
  8910. }
  8911. json_object_put(tmpProfilee);
  8912. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8913. {
  8914. //------- not write to fptr2-------//
  8915. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8916. //clearflag = TRUE;
  8917. }
  8918. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8919. {
  8920. //------- not write to fptr2-------//
  8921. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8922. }
  8923. else if(stackLevelIsNULL == TRUE)
  8924. {
  8925. //Clear Whole File
  8926. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8927. clearflag = TRUE;
  8928. break;
  8929. }
  8930. else
  8931. {
  8932. fprintf(fptr2, sLineWord);//writing data into file
  8933. }
  8934. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8935. }
  8936. if(clearflag == TRUE)
  8937. {
  8938. fclose(fptr1);
  8939. fclose(fptr2);
  8940. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8941. system(str);
  8942. // clear temp file
  8943. sprintf(str,"rm -f %s",temp);
  8944. system(str);
  8945. }
  8946. else
  8947. {
  8948. fclose(fptr1);
  8949. fclose(fptr2);
  8950. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8951. system(str);
  8952. resultRename = rename(temp, chargingProfiles[k]);
  8953. if(resultRename == 0)
  8954. {
  8955. DEBUG_INFO("File ChargingProfile renamed successfully");
  8956. }
  8957. else
  8958. {
  8959. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8960. }
  8961. if(comfirmstr[0]== 0)
  8962. {
  8963. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8964. }
  8965. //Check chargingProfile is empty file
  8966. /*------ Read the file ----------------*/
  8967. fptr1=fopen(chargingProfiles[k],"r");
  8968. ch=fgetc(fptr1);
  8969. rewind(fptr1);
  8970. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8971. if(ch!=EOF)
  8972. {
  8973. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8974. {
  8975. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8976. if(sLineWord[0]=='\0')
  8977. {
  8978. isEmptyFile = TRUE;
  8979. break;
  8980. }
  8981. else
  8982. {
  8983. isEmptyFile = FALSE;
  8984. break;
  8985. }
  8986. }
  8987. }
  8988. else
  8989. isEmptyFile = TRUE;
  8990. fclose(fptr1);
  8991. if(isEmptyFile == TRUE)
  8992. {
  8993. memset(str, 0, ARRAY_SIZE(str));
  8994. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8995. system(str);
  8996. }
  8997. /*------- End of reading ---------------*/
  8998. }
  8999. } // while(int k=0; k < ChargeProfileCount; k++)
  9000. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9001. end:
  9002. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9003. {
  9004. if(connectorIdInt == 0)
  9005. {
  9006. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9007. {
  9008. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9009. }
  9010. }
  9011. else
  9012. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9013. }
  9014. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9015. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9016. return result;
  9017. }
  9018. void createFirmwareVersionByDataTransfer(void)
  9019. {
  9020. json_object *FirmwareDataTransfer = json_object_new_object();
  9021. // AC & DC model
  9022. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9023. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9024. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9025. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9026. // DC model
  9027. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9028. {
  9029. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9030. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9031. (gunType[3] != GUN_TYPE_UNKNOWN))
  9032. {
  9033. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9034. }
  9035. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9036. {
  9037. // DS DM DW
  9038. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9039. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9040. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9041. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9042. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9043. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9044. }
  9045. else
  9046. {
  9047. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9048. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9049. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9050. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9051. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9052. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9053. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9054. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9055. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9056. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9057. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9058. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9059. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9060. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9061. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9062. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9063. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9064. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9065. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9066. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9067. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9068. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9069. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9070. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9071. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9072. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9073. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9074. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9075. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9076. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9077. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9078. }
  9079. }
  9080. // 4G model
  9081. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9082. {
  9083. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9084. }
  9085. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9086. json_object_put(FirmwareDataTransfer);
  9087. }
  9088. int handleDataTransferRequest(char *uuid, char *payload)
  9089. {
  9090. mtrace();
  9091. json_object *response = json_object_new_object();
  9092. int result = FAIL;
  9093. char tempvendorId[255]={0};
  9094. char tempmessageId[50]={0};
  9095. char tempdata[512]={0};
  9096. char message[2048]={0};
  9097. DEBUG_INFO("handleDataTransferRequest...\n");
  9098. if((uuid != NULL) && (payload != NULL))
  9099. {
  9100. json_object *DataTransfer;
  9101. DataTransfer = json_tokener_parse(payload);
  9102. if(!is_error(DataTransfer))
  9103. {
  9104. // Required data
  9105. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9106. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9107. // Optional data
  9108. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9109. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9110. if(json_object_object_get(DataTransfer, "data") != NULL)
  9111. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9112. result = PASS;
  9113. }
  9114. json_object_put(DataTransfer);
  9115. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9116. {
  9117. // Send all moudle firmware version on EVSE
  9118. createFirmwareVersionByDataTransfer();
  9119. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9120. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9121. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9122. json_object_put(response);
  9123. }
  9124. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9125. {
  9126. system("/usr/bin/run_tmate_restart.sh &");
  9127. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9128. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9129. json_object_put(response);
  9130. }
  9131. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9132. {
  9133. json_object *data;
  9134. data = json_tokener_parse(tempdata);
  9135. if(!is_error(data))
  9136. {
  9137. 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))
  9138. {
  9139. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9140. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9141. if(json_object_object_get(data, "SOC") != NULL)
  9142. {
  9143. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9144. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9145. }
  9146. if(json_object_object_get(data, "Energy") != NULL)
  9147. {
  9148. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9149. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9150. }
  9151. if(json_object_object_get(data, "Duration") != NULL)
  9152. {
  9153. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9154. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9155. }
  9156. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9157. }
  9158. else
  9159. {
  9160. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9161. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9162. }
  9163. }
  9164. else
  9165. {
  9166. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9167. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9168. }
  9169. json_object_put(data);
  9170. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9171. json_object_put(response);
  9172. }
  9173. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9174. {
  9175. json_object *data;
  9176. data = json_tokener_parse(tempdata);
  9177. if(!is_error(data))
  9178. {
  9179. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9180. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9181. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9182. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9183. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9184. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9185. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9186. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9187. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9188. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9189. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9190. }
  9191. else
  9192. {
  9193. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9194. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9195. }
  9196. json_object_put(data);
  9197. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9198. json_object_put(response);
  9199. }
  9200. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9201. {
  9202. json_object *data;
  9203. data = json_tokener_parse(tempdata);
  9204. if(!is_error(data))
  9205. {
  9206. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9207. if(json_object_object_get(data, "idToken") != NULL)
  9208. {
  9209. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9210. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9211. }
  9212. if(json_object_object_get(data, "price") != NULL)
  9213. {
  9214. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9215. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9216. }
  9217. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9218. }
  9219. else
  9220. {
  9221. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9222. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9223. }
  9224. json_object_put(data);
  9225. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9226. json_object_put(response);
  9227. }
  9228. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9229. {
  9230. json_object *data;
  9231. data = json_tokener_parse(tempdata);
  9232. if(!is_error(data))
  9233. {
  9234. if(json_object_object_get(data, "txId") != NULL)
  9235. {
  9236. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9237. for(int idx = 0;idx<gunTotalNumber;idx++)
  9238. {
  9239. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9240. {
  9241. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9242. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9243. if(json_object_object_get(data, "description") != NULL)
  9244. {
  9245. // California pricing V1.0
  9246. DEBUG_INFO("California pricing V1.0\n");
  9247. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9248. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9249. }
  9250. else
  9251. {
  9252. // California pricing V1.1
  9253. DEBUG_INFO("California pricing V1.1\n");
  9254. if(json_object_object_get(data, "timestamp") != NULL)
  9255. {
  9256. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9257. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9258. }
  9259. if(json_object_object_get(data, "meterValue") != NULL)
  9260. {
  9261. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9262. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9263. }
  9264. if(json_object_object_get(data, "cost") != NULL)
  9265. {
  9266. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9267. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9268. }
  9269. if(json_object_object_get(data, "state") != NULL)
  9270. {
  9271. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9272. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9273. }
  9274. if(json_object_object_get(data, "chargingPrice") != NULL)
  9275. {
  9276. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9277. {
  9278. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9279. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9280. }
  9281. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9282. {
  9283. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9284. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9285. }
  9286. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9287. {
  9288. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9289. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9290. }
  9291. }
  9292. if(json_object_object_get(data, "idlePrice") != NULL)
  9293. {
  9294. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9295. {
  9296. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9297. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9298. }
  9299. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9300. {
  9301. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9302. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9303. }
  9304. }
  9305. if(json_object_object_get(data, "nextPeriod") != NULL)
  9306. {
  9307. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9308. {
  9309. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9310. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9311. }
  9312. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9313. {
  9314. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9315. {
  9316. 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")));
  9317. 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"));
  9318. }
  9319. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9320. {
  9321. 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")));
  9322. 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"));
  9323. }
  9324. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9325. {
  9326. 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")));
  9327. 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"));
  9328. }
  9329. }
  9330. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9331. {
  9332. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9333. {
  9334. 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")));
  9335. 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"));
  9336. }
  9337. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9338. {
  9339. 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")));
  9340. 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"));
  9341. }
  9342. }
  9343. }
  9344. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9345. {
  9346. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9347. {
  9348. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9349. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9350. }
  9351. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9352. {
  9353. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9354. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9355. }
  9356. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9357. {
  9358. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9359. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9360. }
  9361. }
  9362. }
  9363. }
  9364. }
  9365. }
  9366. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9367. }
  9368. else
  9369. {
  9370. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9371. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9372. }
  9373. json_object_put(data);
  9374. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9375. json_object_put(response);
  9376. }
  9377. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9378. {
  9379. json_object *data;
  9380. data = json_tokener_parse(tempdata);
  9381. if(!is_error(data))
  9382. {
  9383. if(json_object_object_get(data, "txId") != NULL)
  9384. {
  9385. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9386. for(int idx = 0;idx<gunTotalNumber;idx++)
  9387. {
  9388. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9389. {
  9390. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9391. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9392. if(json_object_object_get(data, "description") != NULL)
  9393. {
  9394. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9395. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9396. }
  9397. }
  9398. }
  9399. }
  9400. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9401. }
  9402. else
  9403. {
  9404. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9405. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9406. }
  9407. json_object_put(data);
  9408. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9409. json_object_put(response);
  9410. }
  9411. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9412. {
  9413. json_object *data;
  9414. data = json_tokener_parse(tempdata);
  9415. if(!is_error(data))
  9416. {
  9417. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9418. if(json_object_object_get(data, "Content_Type") != NULL)
  9419. {
  9420. 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))
  9421. {
  9422. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9423. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9424. {
  9425. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9426. }
  9427. }
  9428. else
  9429. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9430. }
  9431. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9432. }
  9433. else
  9434. {
  9435. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9436. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9437. }
  9438. json_object_put(data);
  9439. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9440. json_object_put(response);
  9441. }
  9442. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9443. {
  9444. json_object *data;
  9445. data = json_tokener_parse(tempdata);
  9446. if(!is_error(data))
  9447. {
  9448. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9449. if(json_object_object_get(data, "ConnectorId") != NULL)
  9450. {
  9451. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9452. }
  9453. if(json_object_object_get(data, "SerialNo") != NULL)
  9454. {
  9455. sprintf((char *)ShmOCPP16Data->TcciCustomData.LineStatusPage.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9456. }
  9457. if(json_object_object_get(data, "Page_Index") != NULL)
  9458. {
  9459. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9460. }
  9461. if(json_object_object_get(data, "Duration") != NULL)
  9462. {
  9463. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9464. }
  9465. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9466. }
  9467. else
  9468. {
  9469. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9470. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9471. }
  9472. json_object_put(data);
  9473. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9474. json_object_put(response);
  9475. }
  9476. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9477. {
  9478. json_object *data;
  9479. data = json_tokener_parse(tempdata);
  9480. if(!is_error(data))
  9481. {
  9482. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9483. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9484. {
  9485. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9486. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9487. else
  9488. {
  9489. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9490. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9491. }
  9492. }
  9493. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9494. {
  9495. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9496. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9497. else
  9498. {
  9499. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9500. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9501. }
  9502. }
  9503. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9504. {
  9505. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9506. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9507. else
  9508. {
  9509. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9510. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9511. }
  9512. }
  9513. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9514. {
  9515. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9516. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9517. else
  9518. {
  9519. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9520. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9521. }
  9522. }
  9523. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9524. {
  9525. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9526. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9527. else
  9528. {
  9529. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9530. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9531. }
  9532. }
  9533. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9534. {
  9535. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9536. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9537. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9538. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9539. else
  9540. {
  9541. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9542. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9543. }
  9544. }
  9545. if(json_object_object_get(data, "isAuthentication") != NULL)
  9546. {
  9547. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9548. {
  9549. case 0:
  9550. case 1:
  9551. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9552. break;
  9553. default:
  9554. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9555. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9556. break;
  9557. }
  9558. }
  9559. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9560. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9561. }
  9562. else
  9563. {
  9564. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9565. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9566. }
  9567. json_object_put(data);
  9568. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9569. json_object_put(response);
  9570. }
  9571. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9572. {
  9573. json_object *data;
  9574. data = json_tokener_parse(tempdata);
  9575. if(!is_error(data))
  9576. {
  9577. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9578. {
  9579. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9580. {
  9581. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9582. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9583. }
  9584. else
  9585. {
  9586. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9587. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9588. }
  9589. }
  9590. else
  9591. {
  9592. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9593. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9594. }
  9595. }
  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("Configuration content something wrong."));
  9600. }
  9601. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9602. json_object_put(response);
  9603. }
  9604. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9605. {
  9606. json_object *data;
  9607. data = json_tokener_parse(tempdata);
  9608. if(!is_error(data))
  9609. {
  9610. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9611. if(json_object_object_get(data, "stationName") != NULL)
  9612. {
  9613. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9614. }
  9615. else
  9616. {
  9617. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9618. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9619. }
  9620. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9621. {
  9622. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9623. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9624. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9625. }
  9626. }
  9627. else
  9628. {
  9629. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9630. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9631. }
  9632. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9633. json_object_put(response);
  9634. }
  9635. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9636. {
  9637. json_object *data;
  9638. data = json_tokener_parse(tempdata);
  9639. if(!is_error(data))
  9640. {
  9641. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9642. if(json_object_object_get(data, "weatherId") != NULL)
  9643. {
  9644. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9645. }
  9646. else
  9647. {
  9648. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9649. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9650. }
  9651. if(json_object_object_get(data, "Temperature") != NULL)
  9652. {
  9653. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9654. }
  9655. else
  9656. {
  9657. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9658. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9659. }
  9660. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9661. {
  9662. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9663. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9664. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9665. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9666. );
  9667. }
  9668. }
  9669. else
  9670. {
  9671. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9672. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9673. }
  9674. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9675. json_object_put(response);
  9676. }
  9677. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9678. {
  9679. json_object *data;
  9680. data = json_tokener_parse(tempdata);
  9681. if(!is_error(data))
  9682. {
  9683. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9684. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9685. {
  9686. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9687. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9688. }
  9689. else
  9690. {
  9691. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9692. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9693. }
  9694. }
  9695. else
  9696. {
  9697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9698. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9699. }
  9700. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9701. json_object_put(response);
  9702. }
  9703. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9704. {
  9705. json_object *data;
  9706. data = json_tokener_parse(tempdata);
  9707. if(!is_error(data))
  9708. {
  9709. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9710. {
  9711. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9712. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9713. if(gun_index < gunTotalNumber)
  9714. {
  9715. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9716. {
  9717. json_object *responsedata = json_object_new_object();
  9718. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  9719. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9720. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.LineStatusPage.SerialNo[gun_index]));
  9721. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  9722. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9723. }
  9724. else
  9725. {
  9726. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9727. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9728. }
  9729. }
  9730. else
  9731. {
  9732. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9733. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9734. }
  9735. }
  9736. else
  9737. {
  9738. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9739. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9740. }
  9741. }
  9742. else
  9743. {
  9744. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9745. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9746. }
  9747. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9748. json_object_put(response);
  9749. }
  9750. else
  9751. {
  9752. // Can not find valid message id
  9753. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9754. }
  9755. }
  9756. else
  9757. {
  9758. // Payload is null
  9759. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9760. }
  9761. LWS_Send(message);
  9762. return result;
  9763. }
  9764. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9765. {
  9766. mtrace();
  9767. int result = FAIL;
  9768. int connectorIdInt, durationInt;
  9769. char chargingRateUnitStr[4]={0};
  9770. char comfirmstr[20];
  9771. int confirmPeriods = 0;
  9772. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9773. json_object *GetCompositeSchedule;
  9774. GetCompositeSchedule = json_tokener_parse(payload);
  9775. if(!is_error(GetCompositeSchedule))
  9776. {
  9777. // Required data
  9778. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9779. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9780. else
  9781. connectorIdInt = -1;
  9782. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9783. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9784. else
  9785. durationInt = 86400;
  9786. // Optional data
  9787. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9788. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9789. }
  9790. json_object_put(GetCompositeSchedule);
  9791. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9792. if((connectorIdInt == 0) ||
  9793. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9794. {
  9795. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9796. struct StructChargingProfile tmpProfile[1];
  9797. if(strstr(chargingRateUnitStr, "W") != NULL)
  9798. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9799. else
  9800. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9801. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9802. {
  9803. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9804. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9805. }
  9806. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9807. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9808. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9809. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9810. {
  9811. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9812. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9813. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9814. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9815. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9816. {
  9817. confirmPeriods = idx;
  9818. break;
  9819. }
  9820. }
  9821. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9822. {
  9823. confirmPeriods += 1;
  9824. }
  9825. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9826. }
  9827. else
  9828. {
  9829. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9830. }
  9831. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9832. return result;
  9833. }
  9834. int handleGetConfigurationRequest(char *uuid, char *payload)
  9835. {
  9836. mtrace();
  9837. int result = FAIL;
  9838. int MaxKeySupported = 0;
  9839. int n_keys = 0;
  9840. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9841. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9842. json_object *GetConfiguration;
  9843. GetConfiguration = json_tokener_parse(payload);
  9844. if(!is_error(GetConfiguration))
  9845. {
  9846. // Optional data
  9847. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9848. {
  9849. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9850. {
  9851. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9852. n_keys = idx + 1;
  9853. }
  9854. }
  9855. }
  9856. json_object_put(GetConfiguration);
  9857. UnknownKeynum = 0;
  9858. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9859. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9860. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9861. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9862. if(n_keys != 0)
  9863. {
  9864. for(int i=0;i<n_keys;i++)
  9865. {
  9866. getKeyValue(requestKey[i]);
  9867. }
  9868. }
  9869. else
  9870. {
  9871. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9872. getKeyValue("");
  9873. }
  9874. processUnkownKey();
  9875. sendGetConfigurationConfirmation(uuid);
  9876. return result;
  9877. }
  9878. static char fnamePlusPath[100]={0};
  9879. static char fnamePWithNoPath[60]={0};
  9880. void checkUploadLog(void)
  9881. {
  9882. FILE *fp;
  9883. /* Open the command for reading. */
  9884. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9885. if (fp == NULL) {
  9886. DEBUG_WARN("Failed to run command\n" );
  9887. exit(1);
  9888. }
  9889. int ftppathlen = 0;
  9890. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9891. int i = 0;
  9892. /* Read the output a line at a time - output it. */
  9893. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9894. if(i==0)
  9895. {
  9896. ftppathlen = strlen(fnamePlusPath);
  9897. DEBUG_INFO("%s\n", fnamePlusPath);
  9898. fnamePlusPath[ftppathlen]='\0';
  9899. break;
  9900. }
  9901. i= i+1;
  9902. }
  9903. /* close */
  9904. pclose(fp);
  9905. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9906. {
  9907. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9908. {
  9909. fnamePlusPath[k]='\0';
  9910. }
  9911. }
  9912. i=1;
  9913. //char fname[60]={0};
  9914. while(i < ftppathlen)
  9915. {
  9916. int len=ftppathlen-i;
  9917. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9918. {
  9919. DEBUG_INFO("compare '/' all right\n");
  9920. break;
  9921. }
  9922. i=i+1;
  9923. }
  9924. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9925. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9926. fnamePWithNoPath[i+1] = '\0';
  9927. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9928. {
  9929. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9930. {
  9931. fnamePWithNoPath[j]='\0';
  9932. }
  9933. }
  9934. FILE* fp1 = fopen(fnamePlusPath, "r");
  9935. if (fp1)
  9936. {
  9937. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9938. // file exists
  9939. fclose(fp1);
  9940. }
  9941. else
  9942. {
  9943. // file doesn't exist
  9944. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9945. }
  9946. }
  9947. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9948. {
  9949. mtrace();
  9950. int result = FAIL;
  9951. time_t CurrentTime;
  9952. struct tm *tm;
  9953. pthread_t th_Status;
  9954. CurrentTime = time(NULL);
  9955. tm = localtime(&CurrentTime);
  9956. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9957. 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);
  9958. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9959. if(!interLock.isGetDiagnosticGoing)
  9960. {
  9961. interLock.isGetDiagnosticGoing = 1;
  9962. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9963. sleep(1);
  9964. }
  9965. else
  9966. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9967. return result;
  9968. }
  9969. void* GetDiagnosticsProcess(void* data)
  9970. {
  9971. pthread_detach(pthread_self());
  9972. mtrace();
  9973. int retriesInt=0, retryIntervalInt=0;
  9974. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9975. 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};
  9976. int port=0;
  9977. int isSuccess = FALSE;
  9978. char cmdBuf[2048];
  9979. struct tm *tmNow;
  9980. time_t CurrentTime;
  9981. struct tm tmStart;
  9982. struct tm tmStop;
  9983. CurrentTime = time(NULL);
  9984. tmNow=localtime(&CurrentTime);
  9985. uint16_t targetYear, targetMonth;
  9986. json_object *GetDiagnostics;
  9987. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9988. GetDiagnostics = json_tokener_parse(data);
  9989. if(!is_error(GetDiagnostics))
  9990. {
  9991. // Required data
  9992. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9993. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9994. // Optional data
  9995. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9996. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9997. else
  9998. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9999. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10000. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10001. else
  10002. retryIntervalInt = 30;
  10003. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10004. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10005. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10006. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10007. }
  10008. json_object_put(GetDiagnostics);
  10009. // Pack log to compress file
  10010. 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) &&
  10011. (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))
  10012. {
  10013. // Pack system log
  10014. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10015. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10016. targetYear = tmStart.tm_year;
  10017. targetMonth = tmStart.tm_mon;
  10018. do
  10019. {
  10020. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10021. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10022. if(targetMonth+1>=13)
  10023. {
  10024. targetYear += 1;
  10025. targetMonth = 1;
  10026. }
  10027. else
  10028. {
  10029. targetMonth += 1;
  10030. }
  10031. }while((targetYear < (tmNow->tm_year+1900)) ||
  10032. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10033. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10034. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10035. system(cmdBuf);
  10036. // Pack charging & event log
  10037. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10038. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10039. targetYear = tmStart.tm_year;
  10040. targetMonth = tmStart.tm_mon;
  10041. do
  10042. {
  10043. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10044. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10045. if(targetMonth+1>=13)
  10046. {
  10047. targetYear += 1;
  10048. targetMonth = 1;
  10049. }
  10050. else
  10051. {
  10052. targetMonth += 1;
  10053. }
  10054. }while((targetYear < (tmNow->tm_year+1900)) ||
  10055. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10056. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10057. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10058. system(cmdBuf);
  10059. // Combine log file
  10060. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10061. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10062. }
  10063. else
  10064. {
  10065. system("exec /root/logPackTools 'log' 6");
  10066. }
  10067. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10068. system(cmdBuf);
  10069. checkUploadLog();
  10070. //****************location*******************/
  10071. if(strcmp(locationstr,"")==0)
  10072. {
  10073. DEBUG_INFO("location is <Empty>!\n");
  10074. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10075. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10076. goto end;
  10077. }
  10078. memset(protocol, 0, ARRAY_SIZE(protocol));
  10079. memset(user, 0, ARRAY_SIZE(user) );
  10080. memset(password, 0, ARRAY_SIZE(password));
  10081. memset(host, 0, ARRAY_SIZE(host));
  10082. memset(path, 0, ARRAY_SIZE(path));
  10083. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10084. memset(host1, 0, ARRAY_SIZE(host1));
  10085. memset(path1, 0, ARRAY_SIZE(path1));
  10086. /*location: ftp://user:password@host:port/path*/
  10087. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10088. if((access(fnamePlusPath,F_OK))!=-1)
  10089. {
  10090. DEBUG_INFO("fnamePlusPath exist.\n");
  10091. }
  10092. else
  10093. {
  10094. DEBUG_INFO("fnamePlusPath not exist!\n");
  10095. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10096. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10097. goto end;
  10098. }
  10099. if(strchr(locationstr,'@')==NULL)
  10100. {
  10101. sscanf(locationstr,
  10102. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10103. protocol, host, &port, path);
  10104. strcpy(user,"anonymous");
  10105. strcpy(password,"");
  10106. }
  10107. else
  10108. {
  10109. //DEBUG_INFO("pch=%s\n", pch);
  10110. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10111. protocol, user, password, host, &port, path);
  10112. }
  10113. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10114. {
  10115. DEBUG_INFO("protocol is not ftp/http ! \n");
  10116. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10117. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10118. goto end;
  10119. }
  10120. if(strncmp(locationstr,"http", 4) == 0)
  10121. {
  10122. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10123. sprintf(ftppath,"/%s", path);
  10124. do
  10125. {
  10126. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10127. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10128. sleep(3);
  10129. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10130. if(!isSuccess)
  10131. {
  10132. DEBUG_INFO("Diagnostics fail.\n");
  10133. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10134. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10135. sleep(retryIntervalInt);
  10136. }
  10137. else
  10138. {
  10139. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10140. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10141. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10142. }
  10143. retriesInt--;
  10144. }while((isSuccess == 0)&&(retriesInt >= 0));
  10145. }
  10146. else
  10147. {
  10148. sscanf(host,"%[^/]%s",host1, path1);
  10149. if(strlen(path) > 0)
  10150. sprintf(ftppath,"/%s", path);
  10151. else
  10152. sprintf(ftppath,"/%s", path1);
  10153. int ftppathlen=strlen(ftppath);
  10154. int i=1;
  10155. char filenametemp[50];
  10156. while(i < ftppathlen)
  10157. {
  10158. int len=ftppathlen-i;
  10159. if(ftppath[len]== 47) // '/' ascll code: 47
  10160. {
  10161. DEBUG_INFO("find '/' all right\n");
  10162. break;
  10163. }
  10164. i=i+1;
  10165. }
  10166. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10167. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10168. filenametemp[i+1] = 0;
  10169. if(port == 0)
  10170. port = 21;
  10171. do
  10172. {
  10173. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10174. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10175. sleep(3);
  10176. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10177. if(!isSuccess)
  10178. {
  10179. DEBUG_INFO("Diagnostics fail.\n");
  10180. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10181. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10182. sleep(retryIntervalInt);
  10183. }
  10184. else
  10185. {
  10186. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10187. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10188. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10189. }
  10190. retriesInt--;
  10191. }while((!isSuccess)&&(retriesInt >= 0));
  10192. }
  10193. end:
  10194. system("rm -f /mnt/*");
  10195. sleep(5);
  10196. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10197. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10198. interLock.isGetDiagnosticGoing = 0;
  10199. pthread_exit(NULL);
  10200. }
  10201. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10202. {
  10203. mtrace();
  10204. int result = FAIL;
  10205. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10206. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10207. {
  10208. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10209. locallistVersion = -1;
  10210. }
  10211. else
  10212. {
  10213. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10214. OCPP_getListVerion();
  10215. }
  10216. //from db.OCPP_getListVerion
  10217. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10218. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10219. sendGetLocalListVersionConfirmation(uuid,"");
  10220. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10221. return result;
  10222. }
  10223. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10224. {
  10225. mtrace();
  10226. int result = FAIL;
  10227. int connectorIdInt=-1;
  10228. int tempIndex = 0;
  10229. int connectorIdIsNULL, chargingProfileIsNULL;
  10230. char comfirmstr[20]={0};
  10231. char cmdBuf[512];
  10232. json_object *RemoteStartTransaction;
  10233. FILE *fp;
  10234. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10235. if(server_pending == TRUE)
  10236. {
  10237. return 0;
  10238. }
  10239. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10240. RemoteStartTransaction = json_tokener_parse(payload);
  10241. if(!is_error(RemoteStartTransaction))
  10242. {
  10243. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10244. {
  10245. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10246. }
  10247. else
  10248. {
  10249. connectorIdIsNULL = TRUE;
  10250. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10251. {
  10252. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10253. {
  10254. connectorIdIsNULL = FALSE;
  10255. connectorIdInt = (gun_index+1);
  10256. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10257. break;
  10258. }
  10259. }
  10260. }
  10261. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10262. {
  10263. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10264. // Required data
  10265. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10266. // Optional data
  10267. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10268. {
  10269. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10270. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10271. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10272. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10273. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10274. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10275. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10276. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10277. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10278. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10279. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10280. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10281. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10282. {
  10283. 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")));
  10284. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10285. 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"));
  10286. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10287. 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"));
  10288. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10289. 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")));
  10290. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10291. {
  10292. 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++)
  10293. {
  10294. 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"));
  10295. 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"));
  10296. 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)
  10297. 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"));
  10298. }
  10299. }
  10300. }
  10301. }
  10302. else
  10303. {
  10304. chargingProfileIsNULL = TRUE;
  10305. }
  10306. }
  10307. }
  10308. else
  10309. {
  10310. connectorIdIsNULL = TRUE;
  10311. }
  10312. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10313. {
  10314. DEBUG_WARN("Connector id is NULL\n.");
  10315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10316. goto end;
  10317. }
  10318. /*
  10319. enum _SYSTEM_STATUS
  10320. {
  10321. S_BOOTING = 0,
  10322. S_IDLE, = 1
  10323. S_AUTHORIZING, = 2
  10324. S_REASSIGN_CHECK, = 3
  10325. S_REASSIGN, = 4
  10326. S_PRECHARGE, = 5
  10327. S_PREPARING_FOR_EV, = 6
  10328. S_PREPARING_FOR_EVSE, = 7
  10329. S_CHARGING, = 8
  10330. S_TERMINATING, = 9
  10331. S_COMPLETE, = 10
  10332. S_ALARM, = 11
  10333. S_FAULT = 12
  10334. }
  10335. */
  10336. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10337. {
  10338. //check Transaction active
  10339. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10340. {
  10341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10342. {
  10343. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10344. }
  10345. else
  10346. {
  10347. tempIndex = connectorIdInt -1;
  10348. }
  10349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10350. {
  10351. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10352. {
  10353. 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))
  10354. {
  10355. //Reserved
  10356. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10357. }
  10358. 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))
  10359. {
  10360. //Reserved
  10361. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10362. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10363. goto end;
  10364. }
  10365. else
  10366. {
  10367. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10368. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10369. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10370. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10371. {
  10372. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10373. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10374. goto end;
  10375. }
  10376. }//END FOR ELSE
  10377. }
  10378. }// END FOR CHAdeMO_QUANTITY
  10379. }
  10380. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10381. {
  10382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10383. {
  10384. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10385. }
  10386. else
  10387. {
  10388. tempIndex = connectorIdInt -1;
  10389. }
  10390. for (int index = 0; index < CCS_QUANTITY; index++)
  10391. {
  10392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10393. {
  10394. 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))
  10395. {
  10396. //Reserved
  10397. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10398. }
  10399. 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))
  10400. {
  10401. //Reserved
  10402. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10403. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10404. goto end;
  10405. }
  10406. else
  10407. {
  10408. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10409. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10410. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10411. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10412. {
  10413. DEBUG_WARN("CCS connector not allow start\n.");
  10414. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10415. goto end;
  10416. }
  10417. }// END FOR ELSE
  10418. }
  10419. }// END FOR CCS_QUANTITY
  10420. }
  10421. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10422. {
  10423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10424. {
  10425. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10426. }
  10427. else
  10428. {
  10429. tempIndex = connectorIdInt -1;
  10430. }
  10431. for (int index = 0; index < GB_QUANTITY; index++)
  10432. {
  10433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10434. {
  10435. 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))
  10436. {
  10437. //Reserved
  10438. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10439. }
  10440. 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))
  10441. {
  10442. //Reserved
  10443. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10444. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10445. goto end;
  10446. }
  10447. else
  10448. {
  10449. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10450. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10451. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10452. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10453. {
  10454. DEBUG_WARN("GB connector not allow start\n.");
  10455. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10456. goto end;
  10457. }
  10458. }// END FOR ELSE
  10459. }
  10460. } // END FOR GB_QUANTITY
  10461. }
  10462. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10463. {
  10464. tempIndex = connectorIdInt -1;
  10465. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10466. {
  10467. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10468. {
  10469. 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))
  10470. {
  10471. //Reserved
  10472. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10473. }
  10474. 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))
  10475. {
  10476. //Reserved
  10477. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10478. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10479. goto end;
  10480. }
  10481. else
  10482. {
  10483. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10484. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10485. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10486. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10487. {
  10488. DEBUG_WARN("GB connector not allow start\n.");
  10489. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10490. goto end;
  10491. }
  10492. }// END FOR ELSE
  10493. }
  10494. } // END FOR GB_QUANTITY
  10495. }
  10496. else
  10497. {
  10498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10499. {
  10500. tempIndex = 2;
  10501. }
  10502. else
  10503. {
  10504. tempIndex = connectorIdInt -1;
  10505. }
  10506. for (int index = 0; index < AC_QUANTITY; index++)
  10507. {
  10508. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10509. {
  10510. 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))
  10511. {
  10512. //Reserved
  10513. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10514. }
  10515. 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))
  10516. {
  10517. //Reserved
  10518. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10519. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10520. goto end;
  10521. }
  10522. else
  10523. {
  10524. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10525. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10526. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10527. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10528. {
  10529. DEBUG_WARN("AC connector not allow start\n.");
  10530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10531. goto end;
  10532. }
  10533. }//END FOR ELSE
  10534. }
  10535. }// END FOR AC_QUANTITY
  10536. }
  10537. if(chargingProfileIsNULL == FALSE)
  10538. {
  10539. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10540. {
  10541. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10542. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10543. //memset idTag
  10544. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10545. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10546. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10547. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10548. // Save profile to file
  10549. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10550. system(cmdBuf);
  10551. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10552. fp = fopen(cmdBuf, "w");
  10553. 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));
  10554. fclose(fp);
  10555. }
  10556. else
  10557. {
  10558. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10559. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10560. }
  10561. }
  10562. else
  10563. {
  10564. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10565. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10566. //memset idTag
  10567. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10568. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10569. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10570. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10571. }
  10572. }
  10573. else
  10574. {
  10575. DEBUG_WARN("Connector id over\n.");
  10576. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10577. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10578. }
  10579. end:
  10580. json_object_put(RemoteStartTransaction);
  10581. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10582. {
  10583. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10584. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10585. }
  10586. //OCPP send RemoteStartConfirmation by first.
  10587. sendRemoteStartConfirmation(uuid, comfirmstr);
  10588. return result;
  10589. }
  10590. int handleRemoteStartRequest(char *uuid, char *payload)
  10591. {
  10592. mtrace();
  10593. int result = PASS;
  10594. int connectorIdInt=-1;
  10595. int tempIndex = 0;
  10596. char comfirmstr[20]={0};
  10597. char cmdBuf[512];
  10598. json_object *RemoteStartTransaction;
  10599. FILE *fp;
  10600. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10601. if(server_pending == TRUE)
  10602. {
  10603. result = FAIL;
  10604. }
  10605. RemoteStartTransaction = json_tokener_parse(payload);
  10606. if(!is_error(RemoteStartTransaction))
  10607. {
  10608. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10609. {
  10610. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10611. }
  10612. else
  10613. {
  10614. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10615. {
  10616. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10617. {
  10618. connectorIdInt = (gun_index+1);
  10619. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10620. break;
  10621. }
  10622. }
  10623. }
  10624. if(connectorIdInt == 0)
  10625. {
  10626. DEBUG_WARN("Connector id shall not equal 0.\n");
  10627. result = FAIL;
  10628. }
  10629. else if(connectorIdInt == -1)
  10630. {
  10631. DEBUG_INFO("Connector id does not specific.\n");
  10632. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10633. {
  10634. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10635. // Required data
  10636. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10637. // Optional data
  10638. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10639. {
  10640. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10641. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10642. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10643. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10644. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10645. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10646. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10647. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10648. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10649. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10650. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10651. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10652. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10653. {
  10654. 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")));
  10655. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10656. 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"));
  10657. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10658. 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"));
  10659. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10660. 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")));
  10661. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10662. {
  10663. 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++)
  10664. {
  10665. 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"));
  10666. 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"));
  10667. 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)
  10668. 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"));
  10669. }
  10670. }
  10671. }
  10672. }
  10673. else
  10674. {
  10675. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10676. }
  10677. }
  10678. }
  10679. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10680. {
  10681. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10682. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10683. // Required data
  10684. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10685. // Optional data
  10686. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10687. {
  10688. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10689. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10690. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10691. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10692. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10693. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10694. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10695. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10696. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10697. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10698. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10699. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10700. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10701. {
  10702. 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")));
  10703. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10704. 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"));
  10705. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10706. 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"));
  10707. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10708. 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")));
  10709. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10710. {
  10711. 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++)
  10712. {
  10713. 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"));
  10714. 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"));
  10715. 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)
  10716. 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"));
  10717. }
  10718. }
  10719. }
  10720. }
  10721. else
  10722. {
  10723. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10724. }
  10725. }
  10726. else
  10727. {
  10728. DEBUG_WARN("Connector id is over maximun value.\n");
  10729. result = FAIL;
  10730. }
  10731. }
  10732. if(result == PASS)
  10733. {
  10734. if(connectorIdInt > 0)
  10735. {
  10736. //check Transaction active
  10737. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10738. {
  10739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10740. {
  10741. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10742. }
  10743. else
  10744. {
  10745. tempIndex = connectorIdInt -1;
  10746. }
  10747. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10748. {
  10749. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10750. {
  10751. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10752. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10753. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10754. {
  10755. //Reserved
  10756. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10757. }
  10758. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10759. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10760. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10761. {
  10762. //Reserved
  10763. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10764. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10765. goto end;
  10766. }
  10767. else
  10768. {
  10769. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10770. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10771. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10772. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10773. {
  10774. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10775. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10776. goto end;
  10777. }
  10778. }//END FOR ELSE
  10779. }
  10780. }// END FOR CHAdeMO_QUANTITY
  10781. }
  10782. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10783. {
  10784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10785. {
  10786. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10787. }
  10788. else
  10789. {
  10790. tempIndex = connectorIdInt -1;
  10791. }
  10792. for (int index = 0; index < CCS_QUANTITY; index++)
  10793. {
  10794. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10795. {
  10796. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10797. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10798. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10799. {
  10800. //Reserved
  10801. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10802. }
  10803. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10804. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10805. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10806. {
  10807. //Reserved
  10808. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10809. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10810. goto end;
  10811. }
  10812. else
  10813. {
  10814. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10815. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10816. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10817. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10818. {
  10819. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10820. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10821. goto end;
  10822. }
  10823. }// END FOR ELSE
  10824. }
  10825. }// END FOR CCS_QUANTITY
  10826. }
  10827. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10828. {
  10829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10830. {
  10831. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10832. }
  10833. else
  10834. {
  10835. tempIndex = connectorIdInt -1;
  10836. }
  10837. for (int index = 0; index < GB_QUANTITY; index++)
  10838. {
  10839. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10840. {
  10841. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10842. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10843. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10844. {
  10845. //Reserved
  10846. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10847. }
  10848. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10849. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10850. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10851. {
  10852. //Reserved
  10853. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10854. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10855. goto end;
  10856. }
  10857. else
  10858. {
  10859. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10860. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10861. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10862. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10863. {
  10864. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10865. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10866. goto end;
  10867. }
  10868. }// END FOR ELSE
  10869. }
  10870. } // END FOR GB_QUANTITY
  10871. }
  10872. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10873. {
  10874. tempIndex = connectorIdInt -1;
  10875. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10876. {
  10877. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10878. {
  10879. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10880. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10881. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10882. {
  10883. //Reserved
  10884. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10885. }
  10886. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10887. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10888. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10889. {
  10890. //Reserved
  10891. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10892. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10893. goto end;
  10894. }
  10895. else
  10896. {
  10897. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10898. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10899. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10900. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10901. {
  10902. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10903. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10904. goto end;
  10905. }
  10906. }// END FOR ELSE
  10907. }
  10908. } // END FOR GB_QUANTITY
  10909. }
  10910. else
  10911. {
  10912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10913. {
  10914. tempIndex = 2;
  10915. }
  10916. else
  10917. {
  10918. tempIndex = connectorIdInt -1;
  10919. }
  10920. for (int index = 0; index < AC_QUANTITY; index++)
  10921. {
  10922. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10923. {
  10924. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10925. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10926. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10927. {
  10928. //Reserved
  10929. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10930. }
  10931. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10932. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10933. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10934. {
  10935. //Reserved
  10936. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10937. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10938. goto end;
  10939. }
  10940. else
  10941. {
  10942. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10943. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10944. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10945. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10946. {
  10947. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10948. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10949. goto end;
  10950. }
  10951. }//END FOR ELSE
  10952. }
  10953. }// END FOR AC_QUANTITY
  10954. }
  10955. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10956. {
  10957. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10958. {
  10959. // Save profile to file
  10960. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10961. system(cmdBuf);
  10962. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10963. fp = fopen(cmdBuf, "w");
  10964. 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));
  10965. fclose(fp);
  10966. }
  10967. else
  10968. {
  10969. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10970. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10971. goto end;
  10972. }
  10973. }
  10974. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10975. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10976. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10977. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10978. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10979. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10980. }
  10981. else
  10982. {
  10983. uint8_t isHasIdleConnector = FALSE;
  10984. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10985. {
  10986. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10987. {
  10988. isHasIdleConnector = TRUE;
  10989. break;
  10990. }
  10991. }
  10992. if(isHasIdleConnector == TRUE)
  10993. {
  10994. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10995. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10996. {
  10997. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10998. {
  10999. // Save profile to file
  11000. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11001. system(cmdBuf);
  11002. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11003. fp = fopen(cmdBuf, "w");
  11004. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11005. fclose(fp);
  11006. refreshStartTimer(&clientTime.RemoteStartWait);
  11007. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11008. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11009. }
  11010. else
  11011. {
  11012. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11013. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11014. }
  11015. }
  11016. else
  11017. {
  11018. refreshStartTimer(&clientTime.RemoteStartWait);
  11019. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11020. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11021. }
  11022. }
  11023. else
  11024. {
  11025. DEBUG_INFO("There is not any connector is idle.\n");
  11026. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11027. }
  11028. }
  11029. }
  11030. else
  11031. {
  11032. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11033. }
  11034. end:
  11035. json_object_put(RemoteStartTransaction);
  11036. sendRemoteStartConfirmation(uuid, comfirmstr);
  11037. return result;
  11038. }
  11039. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11040. {
  11041. mtrace();
  11042. int result = FAIL;
  11043. int match = FALSE;
  11044. int GunNO = 0;
  11045. int tempIndex = 0;
  11046. int transactionIdInt=0;
  11047. int transactionIdIsNULL= TRUE;
  11048. char comfirmstr[20];
  11049. json_object *RemoteStopTransaction;
  11050. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11051. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11052. if(server_pending == TRUE)
  11053. {
  11054. return 0;
  11055. }
  11056. RemoteStopTransaction = json_tokener_parse(payload);
  11057. if(!is_error(RemoteStopTransaction))
  11058. {
  11059. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11060. {
  11061. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11062. transactionIdIsNULL = FALSE;
  11063. }
  11064. }
  11065. json_object_put(RemoteStopTransaction);
  11066. if(transactionIdIsNULL == FALSE)
  11067. {
  11068. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11069. {
  11070. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11071. {
  11072. //check Transaction active
  11073. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11074. {
  11075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11076. {
  11077. tempIndex = ((gun_index==2) ? 1: 0);
  11078. }
  11079. else
  11080. {
  11081. tempIndex = gun_index;
  11082. }
  11083. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11084. {
  11085. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11086. {
  11087. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11088. {
  11089. match = TRUE;
  11090. GunNO = gun_index;
  11091. }
  11092. }
  11093. }// END FOR CHAdeMO_QUANTITY
  11094. }
  11095. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11096. {
  11097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11098. {
  11099. tempIndex = ((gun_index==2) ? 1: 0);
  11100. }
  11101. else
  11102. {
  11103. tempIndex = gun_index;
  11104. }
  11105. for (int index = 0; index < CCS_QUANTITY; index++)
  11106. {
  11107. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11108. {
  11109. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11110. {
  11111. match = TRUE;
  11112. GunNO = gun_index;
  11113. }
  11114. }
  11115. }// END FOR CCS_QUANTITY
  11116. }
  11117. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11118. {
  11119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11120. {
  11121. tempIndex = ((gun_index==2) ? 1: 0);
  11122. }
  11123. else
  11124. {
  11125. tempIndex = gun_index;
  11126. }
  11127. for (int index = 0; index < GB_QUANTITY; index++)
  11128. {
  11129. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11130. {
  11131. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11132. {
  11133. match = TRUE;
  11134. GunNO = gun_index;
  11135. }
  11136. }
  11137. }// END FOR GB_QUANTITY
  11138. }
  11139. else if(gunType[gun_index] == GUN_TYPE_DO)
  11140. {
  11141. tempIndex = gun_index;
  11142. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11143. {
  11144. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11145. {
  11146. 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
  11147. {
  11148. match = TRUE;
  11149. GunNO = gun_index;
  11150. }
  11151. }
  11152. }// END FOR GB_QUANTITY
  11153. }
  11154. else
  11155. {
  11156. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11157. {
  11158. tempIndex = 2;
  11159. }
  11160. else
  11161. {
  11162. tempIndex = gun_index;
  11163. }
  11164. for (int index = 0; index < AC_QUANTITY; index++)
  11165. {
  11166. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11167. {
  11168. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11169. {
  11170. match = TRUE;
  11171. GunNO = gun_index;
  11172. }
  11173. }
  11174. }// END FOR CHAdeMO_QUANTITY
  11175. } // END FOR AC ELSE
  11176. }// CHECK IF ResponseTransactionId == transactionIdInt
  11177. }//END FOR
  11178. if( match == TRUE)
  11179. {
  11180. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11181. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11182. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11183. }
  11184. else
  11185. {
  11186. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11187. }
  11188. }
  11189. else
  11190. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11191. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11192. return result;
  11193. }
  11194. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11195. {
  11196. mtrace();
  11197. int result = FAIL;
  11198. int connectorIdInt=0, reservationIdInt=0;
  11199. int tempIndex = 0;
  11200. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11201. char comfirmstr[20]={0};
  11202. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11203. int c = 0;
  11204. char *loc;
  11205. //char *ptr;
  11206. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11207. strcpy(sstrtemp, stringtrimspace(payload));
  11208. //***(1)connectorId ****/
  11209. c=0;
  11210. loc = strstr(sstrtemp, "connectorId");
  11211. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11212. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11213. {
  11214. sstr[c] = loc[strlen("connectorId")+2+c];
  11215. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11216. c++;
  11217. }
  11218. sstr[c] = '\0';
  11219. connectorIdInt = atoi(sstr);
  11220. //***(2)expiryDate ****/
  11221. loc = strstr(sstrtemp, "expiryDate");
  11222. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11223. c = 0;
  11224. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11225. {
  11226. sstr[c] = loc[3+strlen("expiryDate")+c];
  11227. c++;
  11228. }
  11229. sstr[c] = '\0';
  11230. strcpy(expiryDatestr, sstr);
  11231. //***(3)idTag ****/
  11232. loc = strstr(sstrtemp, "idTag");
  11233. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11234. c = 0;
  11235. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11236. {
  11237. sstr[c] = loc[3+strlen("idTag")+c];
  11238. c++;
  11239. }
  11240. sstr[c] = '\0';
  11241. strcpy(idTagstr, sstr);
  11242. //***(4)parentIdTag ****/
  11243. loc = strstr(sstrtemp, "parentIdTag");
  11244. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11245. c = 0;
  11246. if(loc == NULL)
  11247. {
  11248. strcpy(parentIdTagstr, "");
  11249. }
  11250. else
  11251. {
  11252. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11253. {
  11254. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11255. c++;
  11256. }
  11257. sstr[c] = '\0';
  11258. strcpy(parentIdTagstr, sstr);
  11259. }
  11260. //***(5)reservationId ****/
  11261. c=0;
  11262. loc = strstr(sstrtemp, "reservationId");
  11263. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11264. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11265. {
  11266. sstr[c] = loc[strlen("reservationId")+2+c];
  11267. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11268. c++;
  11269. }
  11270. sstr[c] = '\0';
  11271. reservationIdInt = atoi(sstr);
  11272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11273. /*
  11274. enum SYSTEM_STATUS
  11275. {
  11276. SYS_MODE_BOOTING = 0,
  11277. SYS_MODE_IDLE = 1,
  11278. SYS_MODE_AUTHORIZING = 2,
  11279. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11280. SYS_MODE_REASSIGN = 4,
  11281. SYS_MODE_PREPARING = 5,
  11282. SYS_MODE_PREPARE_FOR_EV = 6,
  11283. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11284. SYS_MODE_CHARGING = 8,
  11285. SYS_MODE_TERMINATING = 9,
  11286. SYS_MODE_COMPLETE = 10,
  11287. SYS_MODE_ALARM = 11,
  11288. SYS_MODE_FAULT = 12,
  11289. SYS_MODE_RESERVATION = 13,
  11290. SYS_MODE_BOOKING = 14,
  11291. SYS_MODE_MAINTAIN = 15,
  11292. SYS_MODE_DEBUG = 16,
  11293. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11294. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11295. SYS_MODE_UPDATE = 19
  11296. };
  11297. */
  11298. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11299. {
  11300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11301. goto end;
  11302. }
  11303. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11304. {
  11305. //check Transaction active
  11306. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11307. {
  11308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11309. {
  11310. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11311. }
  11312. else
  11313. {
  11314. tempIndex = connectorIdInt -1;
  11315. }
  11316. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11317. {
  11318. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11319. {
  11320. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11321. {
  11322. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11323. {
  11324. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11325. {
  11326. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11327. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11328. }
  11329. 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'))
  11330. {
  11331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11332. }
  11333. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11334. {
  11335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11336. }
  11337. else
  11338. {
  11339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11340. }
  11341. }
  11342. 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
  11343. {
  11344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11345. }
  11346. }
  11347. else
  11348. {
  11349. //replace reservation
  11350. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11352. }
  11353. }
  11354. } // END FOR CHAdeMO_QUANTITY
  11355. }
  11356. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11357. {
  11358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11359. {
  11360. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11361. }
  11362. else
  11363. {
  11364. tempIndex = connectorIdInt -1;
  11365. }
  11366. for (int index = 0; index < CCS_QUANTITY; index++)
  11367. {
  11368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11369. {
  11370. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11371. {
  11372. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11373. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11374. {
  11375. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11376. {
  11377. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11378. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11379. }
  11380. 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'))
  11381. {
  11382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11383. }
  11384. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11385. {
  11386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11387. }
  11388. else
  11389. {
  11390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11391. }
  11392. }
  11393. 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
  11394. {
  11395. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11396. }
  11397. }
  11398. else
  11399. {
  11400. //replace reservation
  11401. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11402. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11403. }
  11404. }
  11405. } // END FOR CCS_QUANTITY
  11406. }
  11407. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11408. {
  11409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11410. {
  11411. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11412. }
  11413. else
  11414. {
  11415. tempIndex = connectorIdInt -1;
  11416. }
  11417. for (int index = 0; index < GB_QUANTITY; index++)
  11418. {
  11419. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11420. {
  11421. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11422. {
  11423. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11424. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11425. {
  11426. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11427. {
  11428. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11429. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11430. }
  11431. 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'))
  11432. {
  11433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11434. }
  11435. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11436. {
  11437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11438. }
  11439. else
  11440. {
  11441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11442. }
  11443. }
  11444. 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
  11445. {
  11446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11447. }
  11448. }
  11449. else
  11450. {
  11451. //replace reservation
  11452. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11454. }
  11455. }
  11456. }// END FOR GB_QUANTITY
  11457. }
  11458. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11459. {
  11460. tempIndex = connectorIdInt -1;
  11461. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11462. {
  11463. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11464. {
  11465. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11466. {
  11467. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11468. 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
  11469. {
  11470. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11471. {
  11472. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11474. }
  11475. 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'))
  11476. {
  11477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11478. }
  11479. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11480. {
  11481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11482. }
  11483. else
  11484. {
  11485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11486. }
  11487. }
  11488. 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
  11489. {
  11490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11491. }
  11492. }
  11493. else
  11494. {
  11495. //replace reservation
  11496. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11498. }
  11499. }
  11500. }// END FOR GB_QUANTITY
  11501. }
  11502. else
  11503. {
  11504. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11505. {
  11506. tempIndex = 2;
  11507. }
  11508. else
  11509. {
  11510. tempIndex = (connectorIdInt -1);
  11511. }
  11512. for (int index = 0; index < AC_QUANTITY; index++)
  11513. {
  11514. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11515. {
  11516. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11517. {
  11518. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11519. {
  11520. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11521. {
  11522. 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))
  11523. {
  11524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11525. }
  11526. else
  11527. {
  11528. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11530. }
  11531. }
  11532. 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'))
  11533. {
  11534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11535. }
  11536. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11537. {
  11538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11539. }
  11540. else
  11541. {
  11542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11543. }
  11544. }
  11545. 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
  11546. {
  11547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11548. }
  11549. }
  11550. else
  11551. {
  11552. //replace reservation
  11553. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11554. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11555. }
  11556. }
  11557. } // END FOR AC_QUANTITY
  11558. }
  11559. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11560. }
  11561. else if(connectorIdInt == 0)
  11562. {
  11563. //check Transaction active
  11564. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11565. {
  11566. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11567. {
  11568. 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'))
  11569. {
  11570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11571. goto end;
  11572. }
  11573. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11574. {
  11575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11576. goto end;
  11577. }
  11578. 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
  11579. {
  11580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11581. goto end;
  11582. }
  11583. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11584. {
  11585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11586. goto end;
  11587. }
  11588. }
  11589. }// END FOR CHAdeMO_QUANTITY
  11590. for (int index = 0; index < CCS_QUANTITY; index++)
  11591. {
  11592. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11593. {
  11594. 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'))
  11595. {
  11596. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11597. goto end;
  11598. }
  11599. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11600. {
  11601. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11602. goto end;
  11603. }
  11604. 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
  11605. {
  11606. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11607. goto end;
  11608. }
  11609. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11610. {
  11611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11612. goto end;
  11613. }
  11614. }
  11615. } // END FOR CCS_QUANTITY
  11616. for (int index = 0; index < GB_QUANTITY; index++)
  11617. {
  11618. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11619. {
  11620. 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'))
  11621. {
  11622. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11623. goto end;
  11624. }
  11625. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11626. {
  11627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11628. goto end;
  11629. }
  11630. 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
  11631. {
  11632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11633. goto end;
  11634. }
  11635. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11636. {
  11637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11638. goto end;
  11639. }
  11640. }
  11641. } // END FOR GB_QUANTITY
  11642. for (int index = 0; index < AC_QUANTITY; index++)
  11643. {
  11644. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11645. {
  11646. 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'))
  11647. {
  11648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11649. goto end;
  11650. }
  11651. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11652. {
  11653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11654. goto end;
  11655. }
  11656. 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
  11657. {
  11658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11659. goto end;
  11660. }
  11661. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11662. {
  11663. 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))
  11664. {
  11665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11666. goto end;
  11667. }
  11668. }
  11669. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11670. {
  11671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11672. goto end;
  11673. }
  11674. }
  11675. }// END FOR AC_QUANTITY
  11676. //The connectorId is 0
  11677. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11679. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11680. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11681. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11682. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11683. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11684. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11685. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11686. result = TRUE;
  11687. return result;
  11688. }
  11689. else
  11690. {
  11691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11692. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11693. }
  11694. if(strcmp(comfirmstr,"Accepted") == 0)
  11695. {
  11696. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11697. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11698. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11699. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11700. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11701. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11702. result = TRUE;
  11703. return result;
  11704. }
  11705. end:
  11706. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11707. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11708. return result;
  11709. }
  11710. int handleResetRequest(char *uuid, char *payload)
  11711. {
  11712. mtrace();
  11713. int result = FAIL;
  11714. char sstr[10]={0},sstrtemp[30]={ 0 };
  11715. char typestr[10]={0};
  11716. char comfirmstr[20]={0};
  11717. int c = 0;
  11718. char *loc;
  11719. DEBUG_INFO("handleResetRequest...\n");
  11720. strcpy(sstrtemp, stringtrimspace(payload));
  11721. loc = strstr(sstrtemp, "type");
  11722. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11723. c = 0;
  11724. while (loc[3+strlen("type")+c] != '\"')
  11725. {
  11726. sstr[c] = loc[3+strlen("type")+c];
  11727. c++;
  11728. }
  11729. sstr[c] = '\0';
  11730. strcpy(typestr,sstr);
  11731. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11732. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11733. {
  11734. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11735. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11736. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11737. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11738. }
  11739. else
  11740. {
  11741. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11742. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11743. result = PASS;
  11744. }
  11745. sendResetConfirmation(uuid, comfirmstr);
  11746. return result;
  11747. }
  11748. int handleSendLocalListRequest(char *uuid, char *payload)
  11749. {
  11750. mtrace();
  11751. int result = FAIL;
  11752. char comfirmstr[20];
  11753. int checkState_Faulted = FALSE;
  11754. json_object *SendLocalList;
  11755. DEBUG_INFO("handleSendLocalListRequest...\n");
  11756. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11757. {
  11758. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11759. goto end;
  11760. }
  11761. //check Charge Point state
  11762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11763. {
  11764. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11765. {
  11766. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11767. }
  11768. }
  11769. for (int index = 0; index < CCS_QUANTITY; index++)
  11770. {
  11771. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11772. {
  11773. checkState_Faulted = TRUE; //OCPP Status
  11774. }
  11775. }
  11776. for (int index = 0; index < GB_QUANTITY; index++)
  11777. {
  11778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11779. {
  11780. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11781. }
  11782. }
  11783. //check Charge Point state
  11784. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11785. {
  11786. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11787. {
  11788. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11789. }
  11790. }
  11791. //check Charge Point state
  11792. for (int index = 0; index < AC_QUANTITY; index++)
  11793. {
  11794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11795. {
  11796. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11797. }
  11798. }
  11799. if(checkState_Faulted == TRUE)
  11800. {
  11801. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11802. goto end;
  11803. }
  11804. // Parsing payload
  11805. SendLocalList = json_tokener_parse(payload);
  11806. if(!is_error(SendLocalList))
  11807. {
  11808. // Required data
  11809. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11810. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11811. // Optional data
  11812. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11813. {
  11814. //Check UpdateType
  11815. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11816. {
  11817. //Local list full update
  11818. DEBUG_INFO("Local list full update.\n");
  11819. OCPP_getListVerion();
  11820. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11821. {
  11822. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11823. goto end;
  11824. }
  11825. OCPP_cleanLocalList();
  11826. }
  11827. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11828. {
  11829. //Local list different update
  11830. DEBUG_INFO("Local list different update.\n");
  11831. OCPP_getListVerion();
  11832. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11833. {
  11834. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11835. goto end;
  11836. }
  11837. }
  11838. else
  11839. {
  11840. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11841. goto end;
  11842. }
  11843. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11844. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11845. {
  11846. 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")));
  11847. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11848. {
  11849. 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")));
  11850. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11851. 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")));
  11852. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11853. 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")));
  11854. }
  11855. // Add to db
  11856. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11857. {
  11858. //Local list full update
  11859. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11860. idx,
  11861. ShmOCPP16Data->SendLocalList.ListVersion,
  11862. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11863. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11864. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11865. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11866. // update list
  11867. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11868. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11869. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11870. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11871. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11872. }
  11873. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11874. {
  11875. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11876. idx,
  11877. ShmOCPP16Data->SendLocalList.ListVersion,
  11878. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11879. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11880. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11881. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11882. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11883. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11884. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11885. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11886. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11887. }
  11888. }
  11889. }
  11890. else
  11891. {
  11892. //Check UpdateType
  11893. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11894. {
  11895. //Local list full update
  11896. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11897. OCPP_cleanLocalList();
  11898. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11899. goto end;
  11900. }
  11901. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11902. {
  11903. //Local list different update
  11904. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11905. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11906. goto end;
  11907. }
  11908. }
  11909. result = PASS;
  11910. }
  11911. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11912. end:
  11913. json_object_put(SendLocalList);
  11914. sendSendLocalListConfirmation(uuid, comfirmstr);
  11915. return result;
  11916. }
  11917. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11918. {
  11919. mtrace();
  11920. int result = FAIL;
  11921. struct StructSetChargingProfile SetProfileReq = {0};
  11922. int tempchargingProfileIdInt;
  11923. int chargingSchedulePeriodCount = 0;
  11924. char comfirmstr[20]={0};
  11925. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11926. char rmFileCmd[128]={0};
  11927. int profileQuantity = 0;
  11928. json_object *SetChargingProfile;
  11929. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11930. SetChargingProfile = json_tokener_parse(payload);
  11931. if(!is_error(SetChargingProfile))
  11932. {
  11933. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11934. {
  11935. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11936. }
  11937. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11938. {
  11939. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11940. {
  11941. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11942. }
  11943. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11944. {
  11945. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11946. }
  11947. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11948. {
  11949. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11950. }
  11951. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11952. {
  11953. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11954. }
  11955. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11956. {
  11957. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11958. }
  11959. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11960. {
  11961. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11962. }
  11963. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11964. {
  11965. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11966. }
  11967. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11968. {
  11969. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11970. }
  11971. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11972. {
  11973. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11974. {
  11975. 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")));
  11976. }
  11977. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11978. {
  11979. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11980. }
  11981. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11982. {
  11983. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11984. }
  11985. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11986. {
  11987. 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")));
  11988. }
  11989. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11990. {
  11991. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11992. if(chargingSchedulePeriodCount <= 10)
  11993. {
  11994. 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++)
  11995. {
  11996. 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)
  11997. {
  11998. 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"));
  11999. }
  12000. 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)
  12001. {
  12002. 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"));
  12003. }
  12004. 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)
  12005. {
  12006. 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"));
  12007. }
  12008. }
  12009. }
  12010. }
  12011. }
  12012. }
  12013. }
  12014. // Profile periods quantity check
  12015. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12016. {
  12017. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12018. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12019. goto end;
  12020. }
  12021. // Check invalid limit
  12022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12023. {
  12024. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12025. {
  12026. 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)))) ||
  12027. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12028. {
  12029. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12030. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12031. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12032. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12033. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12034. goto end;
  12035. }
  12036. }
  12037. }
  12038. else
  12039. {
  12040. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12041. {
  12042. 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))
  12043. {
  12044. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12045. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12046. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12047. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12048. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12049. goto end;
  12050. }
  12051. }
  12052. }
  12053. // Profile purpose info check
  12054. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12055. {
  12056. FILE *fp;
  12057. char dataLine[4096]={0};
  12058. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12059. if(SetProfileReq.ConnectorId != 0)
  12060. {
  12061. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12062. DEBUG_WARN("Profile connector id is not 0.\n");
  12063. goto end;
  12064. }
  12065. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12066. if (!fp)
  12067. {
  12068. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12069. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12070. }
  12071. else
  12072. {
  12073. while(fscanf(fp, "%s", dataLine) != EOF)
  12074. {
  12075. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12076. {
  12077. profileQuantity += 1;
  12078. }
  12079. }
  12080. }
  12081. fclose(fp);
  12082. }
  12083. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12084. {
  12085. FILE *fp;
  12086. char dataLine[4096]={0};
  12087. char filename[128]={0};
  12088. int tmpProfileQuantity;
  12089. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12090. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12091. {
  12092. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12093. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12094. goto end;
  12095. }
  12096. if(SetProfileReq.ConnectorId == 0)
  12097. {
  12098. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12099. {
  12100. tmpProfileQuantity = 0;
  12101. memset(filename, 0, ARRAY_SIZE(filename));
  12102. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12103. fp = fopen(filename, "r");
  12104. if (!fp)
  12105. {
  12106. DEBUG_INFO("%s does not create.\n", filename);
  12107. fp = fopen(filename, "w+");
  12108. }
  12109. else
  12110. {
  12111. while(fscanf(fp, "%s", dataLine) != EOF)
  12112. {
  12113. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12114. {
  12115. tmpProfileQuantity += 1;
  12116. }
  12117. }
  12118. }
  12119. fclose(fp);
  12120. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12121. }
  12122. }
  12123. else
  12124. {
  12125. memset(filename, 0, ARRAY_SIZE(filename));
  12126. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12127. fp = fopen(filename, "r");
  12128. if (!fp)
  12129. {
  12130. DEBUG_INFO("%s does not create.\n", filename);
  12131. fp = fopen(filename, "w+");
  12132. }
  12133. else
  12134. {
  12135. while(fscanf(fp, "%s", dataLine) != EOF)
  12136. {
  12137. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12138. {
  12139. profileQuantity += 1;
  12140. }
  12141. }
  12142. }
  12143. fclose(fp);
  12144. }
  12145. }
  12146. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12147. {
  12148. int isMatchTransactiodId= FALSE;
  12149. FILE *fp;
  12150. char dataLine[4096]={0};
  12151. char filename[128]={0};
  12152. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12153. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12154. if(SetProfileReq.ConnectorId == 0)
  12155. {
  12156. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12157. DEBUG_WARN("Profile connector id is 0.\n");
  12158. goto end;
  12159. }
  12160. int tempIndex = 0;
  12161. //check Transaction active
  12162. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12163. {
  12164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12165. {
  12166. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12167. }
  12168. else
  12169. {
  12170. tempIndex = SetProfileReq.ConnectorId -1;
  12171. }
  12172. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12173. {
  12174. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12175. {
  12176. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12177. {
  12178. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12179. {
  12180. isMatchTransactiodId = TRUE;
  12181. break;
  12182. }
  12183. }
  12184. }
  12185. }
  12186. }
  12187. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12188. {
  12189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12190. {
  12191. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12192. }
  12193. else
  12194. {
  12195. tempIndex = SetProfileReq.ConnectorId -1;
  12196. }
  12197. for (int index = 0; index < CCS_QUANTITY; index++)
  12198. {
  12199. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12200. {
  12201. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12202. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12203. {
  12204. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12205. {
  12206. isMatchTransactiodId = TRUE;
  12207. break;
  12208. }
  12209. }
  12210. }
  12211. }
  12212. }
  12213. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12214. {
  12215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12216. {
  12217. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12218. }
  12219. else
  12220. {
  12221. tempIndex = SetProfileReq.ConnectorId -1;
  12222. }
  12223. for (int index = 0; index < GB_QUANTITY; index++)
  12224. {
  12225. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12226. {
  12227. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12228. {
  12229. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12230. {
  12231. isMatchTransactiodId = TRUE;
  12232. break;
  12233. }
  12234. }
  12235. }
  12236. }
  12237. }
  12238. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12239. {
  12240. tempIndex = SetProfileReq.ConnectorId -1;
  12241. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12242. {
  12243. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12244. {
  12245. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12246. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12247. {
  12248. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12249. {
  12250. isMatchTransactiodId = TRUE;
  12251. break;
  12252. }
  12253. }
  12254. }
  12255. }
  12256. }
  12257. else
  12258. {
  12259. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12260. {
  12261. tempIndex = 2;
  12262. }
  12263. else
  12264. {
  12265. tempIndex = (SetProfileReq.ConnectorId -1);
  12266. }
  12267. for (int index = 0; index < AC_QUANTITY; index++)
  12268. {
  12269. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12270. {
  12271. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12272. {
  12273. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12274. {
  12275. isMatchTransactiodId = TRUE;
  12276. break;
  12277. }
  12278. }
  12279. }
  12280. }
  12281. }
  12282. //check Transaction active
  12283. if(isMatchTransactiodId == FALSE)
  12284. {
  12285. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12286. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12287. goto end;
  12288. }
  12289. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12290. {
  12291. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12292. DEBUG_WARN("Connector id is over max gun number.\n");
  12293. goto end;
  12294. }
  12295. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12296. fp = fopen(filename, "r");
  12297. if (!fp)
  12298. {
  12299. DEBUG_INFO("%s does not create.\n", filename);
  12300. fp = fopen(filename, "w+");
  12301. }
  12302. else
  12303. {
  12304. //Check Charging Profile Count
  12305. while(fscanf(fp, "%s", dataLine) != EOF)
  12306. {
  12307. //DEBUG_INFO("word=%s\n",word);
  12308. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12309. {
  12310. profileQuantity += 1;
  12311. }
  12312. }
  12313. }
  12314. fclose(fp);
  12315. }
  12316. // Check ChargeProfileMaxStackLevel
  12317. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12318. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12319. {
  12320. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12321. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12322. goto end;
  12323. }
  12324. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12325. {
  12326. FILE *fp;
  12327. char dataLine[4096]={0};
  12328. char fnametemp[128]={0};
  12329. int tmpProfileQuantity;
  12330. //Check ChargePointMaxProfile.json exit
  12331. profileQuantity = 0;
  12332. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12333. {
  12334. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12335. //Check Charging Profile Count
  12336. tmpProfileQuantity = 0;
  12337. while(fscanf(fp, "%s", dataLine) != EOF)
  12338. {
  12339. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12340. {
  12341. profileQuantity += 1;
  12342. tmpProfileQuantity += 1;
  12343. }
  12344. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12345. }
  12346. fclose(fp);
  12347. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12348. }
  12349. //Check TxDefaultProfile_%d.json
  12350. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12351. {
  12352. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12353. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12354. if((access(fnametemp,F_OK))!=-1)
  12355. {
  12356. fp = fopen(fnametemp, "r");
  12357. //Check Charging Profile Count
  12358. tmpProfileQuantity = 0;
  12359. while(fscanf(fp, "%s", dataLine) != EOF)
  12360. {
  12361. //DEBUG_INFO("word=%s\n",word);
  12362. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12363. {
  12364. profileQuantity += 1;
  12365. tmpProfileQuantity += 1;
  12366. }
  12367. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12368. }
  12369. fclose(fp);
  12370. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12371. }
  12372. }
  12373. //Check TxProfile_%d.json
  12374. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12375. {
  12376. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12377. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12378. if((access(fnametemp,F_OK))!=-1)
  12379. {
  12380. fp = fopen(fnametemp, "r");
  12381. //Check Charging Profile Count
  12382. tmpProfileQuantity = 0;
  12383. while(fscanf(fp, "%s", dataLine) != EOF)
  12384. {
  12385. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12386. {
  12387. profileQuantity += 1;
  12388. tmpProfileQuantity += 1;
  12389. }
  12390. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12391. }
  12392. fclose(fp);
  12393. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12394. }
  12395. }
  12396. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12397. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12398. {
  12399. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12400. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12401. goto end;
  12402. }
  12403. }
  12404. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12405. //**********************************Write to File********************************************************/
  12406. {
  12407. FILE *infile;
  12408. FILE *outfile;
  12409. char dataLine[4096]={0};
  12410. char filename[128]={0};
  12411. int chkChar=0;
  12412. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12413. {
  12414. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12415. {
  12416. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12417. }
  12418. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12419. {
  12420. if(SetProfileReq.ConnectorId==0)
  12421. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12422. else
  12423. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12424. }
  12425. else
  12426. {
  12427. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12428. }
  12429. infile = fopen (filename, "r");
  12430. outfile = fopen (tempfile, "w");
  12431. chkChar = fgetc(infile);
  12432. rewind(infile);
  12433. if(chkChar == EOF)
  12434. {
  12435. // Profile is empty
  12436. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12437. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12438. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12439. fclose(infile);
  12440. fclose(outfile);
  12441. sprintf(rmFileCmd,"rm -f %s",filename);
  12442. system(rmFileCmd);
  12443. rename(tempfile, filename);
  12444. }
  12445. else
  12446. {
  12447. // Profile is not empty
  12448. int ChargingProfileAdded = FALSE;
  12449. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12450. {
  12451. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12452. json_object *tmpChargingProfile;
  12453. tmpChargingProfile = json_tokener_parse(dataLine);
  12454. if(!is_error(SetChargingProfile))
  12455. {
  12456. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12457. {
  12458. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12459. {
  12460. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12461. }
  12462. }
  12463. }
  12464. json_object_put(tmpChargingProfile);
  12465. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12466. {
  12467. if(ChargingProfileAdded == FALSE)
  12468. {
  12469. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12470. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12471. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12472. ChargingProfileAdded = TRUE;
  12473. }
  12474. }
  12475. else
  12476. {
  12477. fprintf(outfile,"%s\n",dataLine);
  12478. if(ChargingProfileAdded == FALSE)
  12479. {
  12480. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12481. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12482. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12483. ChargingProfileAdded = TRUE;
  12484. }
  12485. }
  12486. } // end of while loop
  12487. fclose(infile);
  12488. fclose(outfile);
  12489. sprintf(rmFileCmd,"rm -f %s",filename);
  12490. system(rmFileCmd);
  12491. rename(tempfile, filename);
  12492. }
  12493. }
  12494. sleep(1);
  12495. result = TRUE;
  12496. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12497. }
  12498. end:
  12499. json_object_put(SetChargingProfile);
  12500. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12501. {
  12502. if(SetProfileReq.ConnectorId == 0)
  12503. {
  12504. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12505. {
  12506. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12507. }
  12508. }
  12509. else
  12510. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12511. }
  12512. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12513. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12514. return result;
  12515. }
  12516. int handleTriggerMessageRequest(char *uuid, char *payload)
  12517. {
  12518. mtrace();
  12519. int result = FAIL;
  12520. int connectorIdIsNULL = FALSE;
  12521. int connectorIdInt =0;
  12522. char sstr[40]={0},sstrtemp[100]={ 0 };
  12523. char requestedMessagestr[40]={0};
  12524. char comfirmstr[20]={0};
  12525. int c = 0;
  12526. char *loc;
  12527. DEBUG_INFO("handleTriggerMessageRequest\n");
  12528. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12529. strcpy(sstrtemp, stringtrimspace(payload));
  12530. c = 0;
  12531. loc = strstr(sstrtemp, "requestedMessage");
  12532. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12533. {
  12534. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12535. c++;
  12536. }
  12537. sstr[c] = '\0';
  12538. strcpy(requestedMessagestr, sstr);
  12539. c = 0;
  12540. loc = strstr(sstrtemp, "connectorId");
  12541. if(loc == NULL)
  12542. {
  12543. connectorIdIsNULL = TRUE;
  12544. }
  12545. else
  12546. {
  12547. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12548. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12549. {
  12550. sstr[c] = loc[strlen("connectorId")+2+c];
  12551. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12552. c++;
  12553. }
  12554. sstr[c] = '\0';
  12555. connectorIdInt = atoi(sstr);
  12556. }
  12557. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12558. {
  12559. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12560. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12561. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12562. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12563. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12564. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12565. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12566. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12567. {
  12568. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12569. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12570. return TRUE;
  12571. }
  12572. else
  12573. {
  12574. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12575. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12576. }
  12577. }
  12578. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12579. {
  12580. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12581. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12582. return TRUE;
  12583. }
  12584. //==========================
  12585. // Trigger message
  12586. //==========================
  12587. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12588. {
  12589. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12590. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12591. {
  12592. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12593. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12594. }
  12595. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12596. }
  12597. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12598. {
  12599. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12600. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12601. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12602. }
  12603. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12604. {
  12605. //sendBootNotificationRequest();
  12606. server_sign = FALSE;
  12607. }
  12608. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12609. {
  12610. refreshStartTimer(&clientTime.Heartbeat);
  12611. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12612. }
  12613. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12614. {
  12615. if(connectorIdIsNULL == FALSE)
  12616. {
  12617. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12618. {
  12619. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12620. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12621. }
  12622. }
  12623. else
  12624. {
  12625. for(int idx=0;idx< gunTotalNumber;idx++)
  12626. {
  12627. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12628. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12629. }
  12630. }
  12631. }
  12632. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12633. {
  12634. if(connectorIdIsNULL == FALSE)
  12635. {
  12636. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12637. {
  12638. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12639. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12640. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12641. }
  12642. }
  12643. else
  12644. {
  12645. for(int idx=0;idx< gunTotalNumber;idx++)
  12646. {
  12647. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12648. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12649. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12650. }
  12651. }
  12652. }
  12653. return result;
  12654. }
  12655. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12656. {
  12657. mtrace();
  12658. int result = FAIL;
  12659. int connectorIdInt =0;
  12660. char comfirmstr[20]={0};
  12661. int tempIndex = 0;
  12662. json_object *UnlockConnector;
  12663. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12664. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12665. UnlockConnector = json_tokener_parse(payload);
  12666. if(!is_error(UnlockConnector))
  12667. {
  12668. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12669. {
  12670. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12671. }
  12672. }
  12673. json_object_put(UnlockConnector);
  12674. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12675. if(gunTotalNumber == 0)
  12676. {
  12677. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12678. goto end;
  12679. }
  12680. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12681. {
  12682. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12683. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12684. goto end;
  12685. }
  12686. else
  12687. {
  12688. //check Transaction active
  12689. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12690. {
  12691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12692. {
  12693. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12694. }
  12695. else
  12696. {
  12697. tempIndex = connectorIdInt -1;
  12698. }
  12699. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12700. {
  12701. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12702. {
  12703. //stop Transaction
  12704. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12705. }
  12706. }
  12707. }
  12708. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12709. {
  12710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12711. {
  12712. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12713. }
  12714. else
  12715. {
  12716. tempIndex = connectorIdInt -1;
  12717. }
  12718. for (int index = 0; index < CCS_QUANTITY; index++)
  12719. {
  12720. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12721. {
  12722. //stop Transaction
  12723. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12724. }
  12725. }
  12726. }
  12727. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12728. {
  12729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12730. {
  12731. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12732. }
  12733. else
  12734. {
  12735. tempIndex = connectorIdInt -1;
  12736. }
  12737. for (int index = 0; index < GB_QUANTITY; index++)
  12738. {
  12739. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12740. {
  12741. //stop Transaction
  12742. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12743. }
  12744. }
  12745. }
  12746. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12747. {
  12748. tempIndex = connectorIdInt -1;
  12749. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12750. {
  12751. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12752. {
  12753. //stop Transaction
  12754. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12755. }
  12756. }
  12757. }
  12758. else
  12759. {
  12760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12761. {
  12762. tempIndex = 2;
  12763. }
  12764. else
  12765. {
  12766. tempIndex = connectorIdInt-1;
  12767. }
  12768. for (int index = 0; index < AC_QUANTITY; index++)
  12769. {
  12770. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12771. {
  12772. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12773. }
  12774. }
  12775. }
  12776. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12777. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12778. result = TRUE;
  12779. return result;
  12780. }
  12781. end:
  12782. //json_object_put(obj); --- remove temporally
  12783. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12784. return result;
  12785. }
  12786. static char UpdateFirmwarepayloadData[300]={0};
  12787. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12788. {
  12789. mtrace();
  12790. int result = FAIL;
  12791. pthread_t t;
  12792. sendUpdateFirmwareConfirmation(uuid);
  12793. memset(UpdateFirmwarepayloadData, 0, 300);
  12794. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12795. if(!interLock.isUpdateFirmwareGoing)
  12796. {
  12797. interLock.isUpdateFirmwareGoing = 1;
  12798. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12799. sleep(1);
  12800. }
  12801. else
  12802. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12803. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12804. return result;
  12805. }
  12806. void *UpdateFirmwareProcess(void *data)
  12807. {
  12808. pthread_detach(pthread_self());
  12809. mtrace();
  12810. int retriesInt =0, retryIntervalInt=0;
  12811. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12812. int port=0;
  12813. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12814. int isSuccess = 0;
  12815. char ftpbuf[1024];
  12816. char temp[1024];
  12817. char * pch;
  12818. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12819. json_object *UpdateFirmware;
  12820. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12821. if(!is_error(UpdateFirmware))
  12822. {
  12823. // Required data
  12824. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12825. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12826. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12827. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12828. // Optional data
  12829. if(json_object_object_get(UpdateFirmware, "retries"))
  12830. {
  12831. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12832. }
  12833. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12834. {
  12835. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12836. }
  12837. }
  12838. json_object_put(UpdateFirmware);
  12839. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12840. memset(path, 0, ARRAY_SIZE(path));
  12841. // Wait retrieveData
  12842. if(strlen(retrieveDatestr) > 10)
  12843. {
  12844. do
  12845. {
  12846. sleep(1);
  12847. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12848. }
  12849. // Ready to download
  12850. system("rm -f /mnt/*");
  12851. if(strncmp(locationstr,"http", 4) == 0)
  12852. {
  12853. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12854. sprintf(ftppath,"/%s", path);
  12855. DEBUG_INFO("locationstr: %s\n", locationstr);
  12856. DEBUG_INFO("protocol: %s\n",protocol);
  12857. DEBUG_INFO("host: %s\n",host);
  12858. DEBUG_INFO("path: %s\n",path);
  12859. DEBUG_INFO("ftppath: %s\n",ftppath);
  12860. int ftppathlen=strlen(ftppath);
  12861. int i=1;
  12862. char filenametemp[50];
  12863. while(i < ftppathlen)
  12864. {
  12865. int len=ftppathlen-i;
  12866. if(ftppath[len]== 47) // '/' ascll code: 47
  12867. {
  12868. DEBUG_INFO("compare '/' all right\n");
  12869. break;
  12870. }
  12871. i=i+1;
  12872. }
  12873. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12874. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12875. filenametemp[i+1] = 0;
  12876. do
  12877. {
  12878. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12879. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12880. sleep(1);
  12881. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12882. if(!isSuccess)
  12883. {
  12884. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12885. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12886. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12887. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12888. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12889. }
  12890. else
  12891. {
  12892. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12893. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12894. }
  12895. retriesInt--;
  12896. }while((isSuccess == 0)&&(retriesInt >= 0));
  12897. }
  12898. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12899. {
  12900. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12901. memset(temp, 0, ARRAY_SIZE(temp));
  12902. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12903. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12904. int ftppathlen=strlen(ftpbuf);
  12905. int i=1;
  12906. char filenametemp[50];
  12907. while(i < ftppathlen)
  12908. {
  12909. int len=ftppathlen-i;
  12910. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12911. {
  12912. DEBUG_INFO(" compare '/' all right\n");
  12913. break;
  12914. }
  12915. i=i+1;
  12916. }
  12917. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12918. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12919. filenametemp[i+1] = 0;
  12920. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12921. pch=strchr(temp,'@');
  12922. if(pch==NULL)
  12923. {
  12924. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12925. protocol, host, &port, path);
  12926. strcpy(user,"anonymous");
  12927. strcpy(password,"");
  12928. }
  12929. else
  12930. {
  12931. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12932. protocol, user, password, host, &port, path);
  12933. }
  12934. sscanf(host,"%[^/]%s",host1, path1);
  12935. sprintf(ftppath,"%s", path1);
  12936. //DEBUG_INFO("protocol =%s\n",protocol);
  12937. //DEBUG_INFO("user =%s\n",user);
  12938. //DEBUG_INFO("password =%s\n",password);
  12939. //DEBUG_INFO("host1 =%s\n",host1);
  12940. //DEBUG_INFO("port =%d\n",port);
  12941. //DEBUG_INFO("path1 =%s\n",path1);
  12942. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12943. //ftpFile(host, user, password, port, ftppath, fname);
  12944. //download firmware pthred
  12945. if(port == 0)
  12946. {
  12947. port = 21;
  12948. }
  12949. do
  12950. {
  12951. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12952. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12953. sleep(1);
  12954. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12955. if(!isSuccess)
  12956. {
  12957. //BulldogUtil.sleepMs(interval*1000);
  12958. DEBUG_INFO("Update firmware request and download file fail.\n");
  12959. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12960. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12961. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12962. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12963. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12964. }
  12965. else
  12966. {
  12967. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12968. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12969. }
  12970. retriesInt--;
  12971. }while((!isSuccess)&&(retriesInt >= 0));
  12972. }
  12973. else
  12974. {
  12975. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12976. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12977. sleep(1);
  12978. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12979. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12980. }
  12981. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12982. interLock.isUpdateFirmwareGoing = 0;
  12983. pthread_exit(NULL);
  12984. }
  12985. int handleCertificateSignedRequest(char *uuid, char *payload)
  12986. {
  12987. mtrace();
  12988. int result = PASS;
  12989. json_object *CertificateSigned;
  12990. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12991. CertificateSigned = json_tokener_parse(payload);
  12992. if(!is_error(CertificateSigned))
  12993. {
  12994. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12995. }
  12996. json_object_put(CertificateSigned);
  12997. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12998. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12999. fclose(fp);
  13000. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13001. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13002. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13003. sendCertificateSignedConfirmation(uuid);
  13004. return result;
  13005. }
  13006. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13007. {
  13008. mtrace();
  13009. int result = PASS;
  13010. json_object *DeleteCertificate;
  13011. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13012. DeleteCertificate = json_tokener_parse(payload);
  13013. if(!is_error(DeleteCertificate))
  13014. {
  13015. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13016. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13017. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13018. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13019. }
  13020. json_object_put(DeleteCertificate);
  13021. /*
  13022. * TODO: Delete certificateSigned process
  13023. */
  13024. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13025. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13026. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13027. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13028. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13029. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13030. sendDeleteCertificateConfirmation(uuid);
  13031. return result;
  13032. }
  13033. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13034. {
  13035. mtrace();
  13036. int result = PASS;
  13037. json_object *ExtendedTriggerMessage;
  13038. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13039. ExtendedTriggerMessage = json_tokener_parse(payload);
  13040. if(!is_error(ExtendedTriggerMessage))
  13041. {
  13042. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13043. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13044. {
  13045. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13046. }
  13047. else
  13048. {
  13049. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13050. }
  13051. }
  13052. json_object_put(ExtendedTriggerMessage);
  13053. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13054. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13055. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13056. {
  13057. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13058. }
  13059. else
  13060. {
  13061. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13062. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13063. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13064. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13065. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13066. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13067. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13068. {
  13069. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13070. }
  13071. else
  13072. {
  13073. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13074. }
  13075. }
  13076. sendExtendedTriggerMessageConfirmation(uuid);
  13077. //==========================
  13078. // Trigger message
  13079. //==========================
  13080. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13081. {
  13082. //sendBootNotificationRequest();
  13083. server_sign = FALSE;
  13084. }
  13085. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13086. {
  13087. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13088. }
  13089. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13090. {
  13091. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13092. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13093. {
  13094. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13095. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13096. }
  13097. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13098. }
  13099. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13100. {
  13101. refreshStartTimer(&clientTime.Heartbeat);
  13102. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13103. }
  13104. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13105. {
  13106. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13107. {
  13108. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13109. }
  13110. else
  13111. {
  13112. for(int idx=0;idx< gunTotalNumber;idx++)
  13113. {
  13114. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13115. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13116. }
  13117. }
  13118. }
  13119. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13120. {
  13121. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13122. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13123. {
  13124. 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\" &");
  13125. }
  13126. }
  13127. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13128. {
  13129. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13130. {
  13131. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13132. }
  13133. else
  13134. {
  13135. for(int idx=0;idx< gunTotalNumber;idx++)
  13136. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13137. }
  13138. }
  13139. return result;
  13140. }
  13141. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13142. {
  13143. mtrace();
  13144. int result = PASS;
  13145. json_object *GetInstalledCertificateIds;
  13146. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13147. GetInstalledCertificateIds = json_tokener_parse(payload);
  13148. if(!is_error(GetInstalledCertificateIds))
  13149. {
  13150. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13151. }
  13152. json_object_put(GetInstalledCertificateIds);
  13153. /*
  13154. * TODO: Return installed certificate process
  13155. */
  13156. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13157. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13158. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13159. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13160. sendGetInstalledCertificateIdsConfirmation(uuid);
  13161. return result;
  13162. }
  13163. int handleGetLogRequest(char *uuid, char *payload)
  13164. {
  13165. mtrace();
  13166. int result = PASS;
  13167. json_object *GetLog;
  13168. DEBUG_INFO("handleGetLogRequest...\n");
  13169. GetLog = json_tokener_parse(payload);
  13170. if(!is_error(GetLog))
  13171. {
  13172. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13173. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13174. if(json_object_object_get(GetLog, "retries") != NULL)
  13175. {
  13176. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13177. }
  13178. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13179. {
  13180. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13181. }
  13182. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13183. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13184. {
  13185. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13186. }
  13187. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13188. {
  13189. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13190. }
  13191. }
  13192. json_object_put(GetLog);
  13193. /*
  13194. * TODO: Upload log process
  13195. */
  13196. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13197. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13198. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13199. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13200. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13201. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13202. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13203. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13204. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13205. sendGetLogConfirmation(uuid);
  13206. return result;
  13207. }
  13208. int handleInstallCertificateRequest(char *uuid, char *payload)
  13209. {
  13210. mtrace();
  13211. int result = PASS;
  13212. json_object *InstallCertificate;
  13213. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13214. InstallCertificate = json_tokener_parse(payload);
  13215. if(!is_error(InstallCertificate))
  13216. {
  13217. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13218. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13219. /*
  13220. * TODO: Install certificate process
  13221. */
  13222. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13223. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13224. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13225. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13226. sendInstallCertificateConfirmation(uuid);
  13227. }
  13228. json_object_put(InstallCertificate);
  13229. return result;
  13230. }
  13231. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13232. {
  13233. mtrace();
  13234. int result = PASS;
  13235. json_object *SignedUpdateFirmware;
  13236. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13237. SignedUpdateFirmware = json_tokener_parse(payload);
  13238. if(!is_error(SignedUpdateFirmware))
  13239. {
  13240. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13241. {
  13242. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13243. }
  13244. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13245. {
  13246. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13247. }
  13248. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13249. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13250. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13251. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13252. {
  13253. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13254. }
  13255. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13256. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13257. }
  13258. json_object_put(SignedUpdateFirmware);
  13259. /*
  13260. * TODO: Upgrade firmware process
  13261. */
  13262. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13263. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13264. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13265. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13266. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13267. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13268. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13269. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13270. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13271. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13272. sendInstallCertificateConfirmation(uuid);
  13273. return result;
  13274. }
  13275. int handleUnknownRequest(char *uuid, char *payload)
  13276. {
  13277. mtrace();
  13278. int result = PASS;
  13279. DEBUG_INFO("handleUnknownRequest...\n");
  13280. sendUnknownConfirmation(uuid);
  13281. result = PASS;
  13282. return result;
  13283. }
  13284. //==========================================
  13285. // Handle server response routine
  13286. //==========================================
  13287. void handleAuthorizeResponse(char *payload, int gun_index)
  13288. {
  13289. mtrace();
  13290. char expiryDatestr[30]={0};
  13291. char parentIdTagstr[20]={0};
  13292. char statusstr[20]={0};
  13293. int expiryDateISNULL=FALSE;
  13294. int parentIdTagISNULL=FALSE;
  13295. DEBUG_INFO("handleAuthorizeResponse...\n");
  13296. json_object *Authorize;
  13297. Authorize = json_tokener_parse(payload);
  13298. if(!is_error(Authorize))
  13299. {
  13300. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13301. {
  13302. // Required data
  13303. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13304. // Optional data
  13305. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13306. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13307. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13308. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13309. }
  13310. }
  13311. json_object_put(Authorize);
  13312. if(expiryDateISNULL == FALSE)
  13313. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13314. if(parentIdTagISNULL == FALSE)
  13315. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13316. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13317. //Update idTag information to authorization cache if supproted
  13318. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13319. {
  13320. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13321. }
  13322. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13323. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13324. authorizeRetryTimes = 0;
  13325. }
  13326. void handleBootNotificationResponse(char *payload, int gun_index)
  13327. {
  13328. mtrace();
  13329. char statusStr[12]={0};
  13330. char currentTimeStr[30]={0};
  13331. int intervalInt = 0;
  13332. DEBUG_INFO("handleBootNotificationResponse...\n");
  13333. json_object *BootNotification;
  13334. BootNotification = json_tokener_parse(payload);
  13335. if(!is_error(BootNotification))
  13336. {
  13337. // Required data
  13338. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13339. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13340. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13341. }
  13342. json_object_put(BootNotification);
  13343. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13344. BootNotificationInterval = intervalInt;
  13345. //write back to ShmOCPP16Data->BootNotification
  13346. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13347. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13348. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13349. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13350. {
  13351. if((intervalInt == 0) || (intervalInt >= 10))
  13352. {
  13353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13354. HeartBeatWaitTime = intervalInt;
  13355. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13356. }
  13357. server_sign = TRUE;
  13358. server_pending =FALSE;
  13359. }
  13360. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13361. {
  13362. server_pending = TRUE;
  13363. }
  13364. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13365. srand(time(NULL));
  13366. refreshStartTimer(&clientTime.Heartbeat);
  13367. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13368. SetOcppConnStatus(TRUE);
  13369. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13370. }
  13371. void handleDataTransferResponse(char *payload, int gun_index)
  13372. {
  13373. json_object *DataTransfer = json_tokener_parse(payload);
  13374. if(!is_error(DataTransfer))
  13375. {
  13376. // Required data
  13377. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13378. // Optional data
  13379. if(json_object_object_get(DataTransfer, "data") != NULL)
  13380. {
  13381. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13382. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13383. if(!is_error(Data))
  13384. {
  13385. if(json_object_object_get(Data, "msgId") != NULL)
  13386. {
  13387. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13388. {
  13389. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  13390. }
  13391. }
  13392. }
  13393. json_object_put(Data);
  13394. }
  13395. }
  13396. json_object_put(DataTransfer);
  13397. }
  13398. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13399. {
  13400. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13401. //struct json_object *obj;
  13402. // obj = json_tokener_parse(payload);
  13403. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13404. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13405. //No fields are defined.
  13406. }
  13407. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13408. {
  13409. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13410. //struct json_object *obj;
  13411. // obj = json_tokener_parse(payload);
  13412. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13413. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13414. //No fields are defined.
  13415. }
  13416. void handleHeartbeatResponse(char *payload, int gun_index)
  13417. {
  13418. mtrace();
  13419. DEBUG_INFO("handleHeartbeatResponse...\n");
  13420. json_object *Heartbeat;
  13421. Heartbeat = json_tokener_parse(payload);
  13422. if(!is_error(Heartbeat))
  13423. {
  13424. // Required data
  13425. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13426. }
  13427. json_object_put(Heartbeat);
  13428. if(FirstHeartBeat == 0)
  13429. {
  13430. FirstHeartBeat = 1;
  13431. DEBUG_INFO("FirstHeartBeat \n");
  13432. }
  13433. HeartBeatWithNOResponse = 0;
  13434. refreshStartTimer(&clientTime.Heartbeat);
  13435. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13436. }
  13437. void handleMeterValuesResponse(char *payload, int gun_index)
  13438. {
  13439. mtrace();
  13440. DEBUG_INFO("handleMeterValuesResponse...\n");
  13441. isQueueSendable = 1;
  13442. }
  13443. void handleStartTransactionResponse(char *payload, int gun_index)
  13444. {
  13445. mtrace();
  13446. //int transactionIdInt = 0;
  13447. FILE *outfile;
  13448. char data[100]={0};
  13449. DEBUG_INFO("handleStartTransactionResponse...\n");
  13450. json_object *StartTransaction;
  13451. StartTransaction = json_tokener_parse(payload);
  13452. if(!is_error(StartTransaction))
  13453. {
  13454. // Required data
  13455. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13456. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13457. // Optional data
  13458. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13459. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13460. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13461. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13462. }
  13463. json_object_put(StartTransaction);
  13464. isQueueSendable = 1;
  13465. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13466. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13467. //-----------Start : write to the Queue TransactionId file -----------------//
  13468. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13469. {}
  13470. else
  13471. {
  13472. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13473. if(log == NULL)
  13474. {
  13475. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13476. return ;
  13477. }
  13478. else
  13479. {
  13480. fclose(log);
  13481. }
  13482. }
  13483. // open file for writing
  13484. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13485. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13486. {
  13487. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13488. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13489. fputs(data, outfile);
  13490. fclose (outfile);
  13491. }
  13492. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13493. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13494. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13495. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13496. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13497. }
  13498. void handleStatusNotificationResponse(char *payload, int gun_index)
  13499. {
  13500. mtrace();
  13501. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13502. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13503. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13504. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13505. }
  13506. void handleStopTransactionnResponse(char *payload, int gun_index)
  13507. {
  13508. mtrace();
  13509. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13510. json_object *StopTransaction;
  13511. StopTransaction = json_tokener_parse(payload);
  13512. if(!is_error(StopTransaction))
  13513. {
  13514. // Optional data
  13515. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13516. {
  13517. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13518. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13519. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13520. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13521. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13522. }
  13523. }
  13524. json_object_put(StopTransaction);
  13525. isQueueSendable = 1;
  13526. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13527. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13528. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13529. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13530. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13531. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13532. }
  13533. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13534. {
  13535. mtrace();
  13536. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13537. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13538. }
  13539. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13540. {
  13541. mtrace();
  13542. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13543. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13544. }
  13545. void handleSignCertificateResponse(char *payload, int gun_index)
  13546. {
  13547. mtrace();
  13548. DEBUG_INFO("handleSignCertificateResponse...\n");
  13549. json_object *SignCertificate;
  13550. SignCertificate = json_tokener_parse(payload);
  13551. if(!is_error(SignCertificate))
  13552. {
  13553. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13554. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13555. }
  13556. json_object_put(SignCertificate);
  13557. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13558. }
  13559. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13560. {
  13561. mtrace();
  13562. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13563. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13564. }
  13565. //==========================================
  13566. // Handle Error routine
  13567. //==========================================
  13568. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13569. {
  13570. mtrace();
  13571. #ifdef SystemLogMessage
  13572. DEBUG_INFO("errorCode: %s\n", errorCode);
  13573. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13574. DEBUG_INFO("errorDetails: %s\n", payload);
  13575. #endif
  13576. }
  13577. //===============================================
  13578. // Common routine
  13579. //===============================================
  13580. int initialConfigurationTable(void)
  13581. {
  13582. //clock_t start_t, end_t, total_t;
  13583. FILE *fp;
  13584. FILE *outfile;
  13585. char str[512]={0};
  13586. char sstr[256]={0};
  13587. int c = 0;
  13588. char *loc;
  13589. int confVersion = 13;
  13590. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13591. //start_t = clock();
  13592. //printf("Starting of the program, start_t = %ld\n", start_t);
  13593. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13594. // Check configuration file size is correct
  13595. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13596. {
  13597. struct stat st;
  13598. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13599. if(st.st_size < 3100)
  13600. {
  13601. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13602. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13603. }
  13604. }
  13605. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13606. {
  13607. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13608. if(outfile == NULL)
  13609. {
  13610. DEBUG_INFO("Error opening file\n");
  13611. return FALSE;
  13612. }
  13613. /*Core Profile*/
  13614. //AllowOfflineTxForUnknownId
  13615. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13619. //AuthorizationCacheEnabled
  13620. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13624. //AuthorizeRemoteTxRequests
  13625. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13629. //BlinkRepeat
  13630. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13634. //ClockAlignedDataInterval
  13635. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13639. //ConnectionTimeOut
  13640. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13644. //GetConfigurationMaxKeys
  13645. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13649. // HeartbeatInterval
  13650. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13654. // LightIntensity
  13655. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13659. // LocalAuthorizeOffline
  13660. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13664. // LocalPreAuthorize
  13665. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13669. // MaxEnergyOnInvalidId
  13670. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13674. // MeterValuesAlignedData
  13675. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13677. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13678. 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" );
  13679. else
  13680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13682. // MeterValuesAlignedDataMaxLength
  13683. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13687. else
  13688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13690. // MeterValuesSampledData
  13691. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13693. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13694. 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" );
  13695. else
  13696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13698. // MeterValuesSampledDataMaxLength
  13699. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13701. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13703. else
  13704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13706. // MeterValueSampleInterval
  13707. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13711. // MinimumStatusDuration
  13712. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13715. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13717. // NumberOfConnectors
  13718. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13721. {
  13722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13723. }
  13724. else
  13725. {
  13726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13727. }
  13728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13729. // ResetRetries
  13730. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13734. // ConnectorPhaseRotation
  13735. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13739. // ConnectorPhaseRotationMaxLength
  13740. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13744. // StopTransactionOnEVSideDisconnect
  13745. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13749. // StopTransactionOnInvalidId
  13750. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13754. // StopTxnAlignedData
  13755. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13759. // StopTxnAlignedDataMaxLength
  13760. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13764. // StopTxnSampledData
  13765. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13769. else
  13770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13772. // StopTxnSampledDataMaxLength
  13773. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13776. {
  13777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13778. }
  13779. else
  13780. {
  13781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13782. }
  13783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13784. // SupportedFeatureProfiles
  13785. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13789. // SupportedFeatureProfilesMaxLength
  13790. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13794. // TransactionMessageAttempts
  13795. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13798. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13800. // TransactionMessageRetryInterval
  13801. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13804. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13806. // UnlockConnectorOnEVSideDisconnect
  13807. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13811. // WebSocketPingInterval
  13812. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13816. // QueueOffLineMeterValues
  13817. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13821. // AuthorizationKey
  13822. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13826. // SecurityProfile
  13827. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13831. // DefaultPrice
  13832. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13836. // CustomDisplayCostAndPrice
  13837. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13841. // CustomIdleFeeAfterStop
  13842. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13846. // TimeOffset
  13847. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13851. // NextTimeOffsetTransitionDateTime
  13852. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13856. // TimeOffsetNextTransition
  13857. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13861. // SystemUptimeSec
  13862. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13866. // FreeVend
  13867. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13871. // FreeVendIdtag
  13872. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13876. // OcppServer
  13877. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13879. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13881. // MaintainServer
  13882. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13884. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13886. // StatusNotificationPeriodically
  13887. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13891. // StatusNotificationInterval
  13892. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13896. // Configuration Version
  13897. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13901. //* Local Auth List Management Profile*/
  13902. #if 0
  13903. //For OCTT Test Case
  13904. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13907. #endif
  13908. #if 1
  13909. //LocalAuthListEnabled
  13910. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13914. #endif
  13915. //LocalAuthListMaxLength
  13916. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13920. //SendLocalListMaxLength
  13921. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13925. //ReserveConnectorZeroSupported
  13926. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13930. //* Smart Charging Profile */
  13931. //ChargeProfileMaxStackLevel
  13932. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13936. // ChargingScheduleAllowedChargingRateUnit
  13937. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13941. // ChargingScheduleMaxPeriods
  13942. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13946. // ConnectorSwitch3to1PhaseSupported
  13947. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13951. // MaxChargingProfilesInstalled
  13952. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13956. fclose(outfile);
  13957. }
  13958. else
  13959. {
  13960. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13961. char keystr[60]={0};
  13962. char readonlystr[10]={0};
  13963. char valuestr[256]={0};
  13964. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13965. if(fp == NULL) {
  13966. DEBUG_INFO("Error opening file");
  13967. return FALSE;
  13968. }
  13969. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13970. {
  13971. //DEBUG_INFO("Get Configuration \n");
  13972. if(strlen(str) > 0)
  13973. {
  13974. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13975. //*************************key*********************************/
  13976. if(strstr(str, "key") != NULL)
  13977. {
  13978. loc = strstr(str, "key");
  13979. c = 0;
  13980. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13981. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13982. {
  13983. sstr[c] = loc[strlen("key")+3+c];
  13984. c++;
  13985. }
  13986. sstr[c] = '\0';
  13987. strcpy(keystr,sstr);
  13988. }
  13989. //*************************readonly*********************************/
  13990. if(strstr(str, "readonly") != NULL)
  13991. {
  13992. loc = strstr(str, "readonly");
  13993. c = 0;
  13994. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13995. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13996. {
  13997. sstr[c] = loc[strlen("readonly")+2+c];
  13998. c++;
  13999. }
  14000. sstr[c] = '\0';
  14001. strcpy(readonlystr,sstr);
  14002. }
  14003. //*************************value*********************************/
  14004. if(strstr(str, "value") != NULL)
  14005. {
  14006. loc = strstr(str, "value");
  14007. c = 0;
  14008. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14009. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14010. {
  14011. sstr[c] = loc[strlen("value")+3+c];
  14012. c++;
  14013. }
  14014. sstr[c] = '\0';
  14015. strcpy(valuestr,sstr);
  14016. }
  14017. // DEBUG_INFO("keystr=%s\n",keystr);
  14018. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14019. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14020. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14021. {
  14022. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14023. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14025. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14026. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14027. }
  14028. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14029. {
  14030. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14031. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14033. }
  14034. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14035. {
  14036. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14038. }
  14039. if(strcmp(keystr, "BlinkRepeat") == 0)
  14040. {
  14041. //Charger.BlinkRepeat = Integer.parseInt(value);
  14042. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14044. }
  14045. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14046. {
  14047. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14049. }
  14050. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14051. {
  14052. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14054. }
  14055. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14056. {
  14057. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14059. }
  14060. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14061. {
  14062. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14064. HeartBeatWaitTime = atoi(valuestr);
  14065. }
  14066. if(strcmp(keystr, "LightIntensity") == 0)
  14067. {
  14068. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14070. }
  14071. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14072. {
  14073. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14075. }
  14076. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14077. {
  14078. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14080. }
  14081. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14082. {
  14083. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14085. }
  14086. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14087. {
  14088. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14090. }
  14091. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14092. {
  14093. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14095. }
  14096. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14097. {
  14098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14100. }
  14101. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14102. {
  14103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14105. }
  14106. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14107. {
  14108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14110. }
  14111. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14112. {
  14113. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14115. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14116. }
  14117. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14118. {
  14119. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14121. }
  14122. if(strcmp(keystr, "ResetRetries") == 0)
  14123. {
  14124. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14126. }
  14127. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14128. {
  14129. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14131. }
  14132. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14133. {
  14134. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14136. }
  14137. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14138. {
  14139. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14141. }
  14142. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14143. {
  14144. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14146. }
  14147. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14148. {
  14149. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14151. }
  14152. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14153. {
  14154. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14156. }
  14157. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14158. {
  14159. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14161. }
  14162. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14163. {
  14164. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14166. }
  14167. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14168. {
  14169. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14171. }
  14172. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14173. {
  14174. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14176. }
  14177. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14178. {
  14179. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14181. TransactionMessageAttemptsValue = atoi(valuestr);
  14182. }
  14183. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14184. {
  14185. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14187. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14188. }
  14189. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14190. {
  14191. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14193. }
  14194. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14195. {
  14196. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14198. }
  14199. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14200. {
  14201. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14203. }
  14204. if(strcmp(keystr, "AuthorizationKey") == 0)
  14205. {
  14206. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14207. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14209. }
  14210. if(strcmp(keystr, "SecurityProfile") == 0)
  14211. {
  14212. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14214. }
  14215. if(strcmp(keystr, "DefaultPrice") == 0)
  14216. {
  14217. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14219. }
  14220. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14221. {
  14222. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14224. }
  14225. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14226. {
  14227. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14229. }
  14230. if(strcmp(keystr, "TimeOffset") == 0)
  14231. {
  14232. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14234. }
  14235. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14236. {
  14237. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14239. }
  14240. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14241. {
  14242. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14244. }
  14245. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14246. {
  14247. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14249. }
  14250. if(strcmp(keystr, "FreeVend") == 0)
  14251. {
  14252. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14254. }
  14255. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14256. {
  14257. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14259. }
  14260. if(strcmp(keystr, "OcppServer") == 0)
  14261. {
  14262. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14263. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14264. }
  14265. if(strcmp(keystr, "MaintainServer") == 0)
  14266. {
  14267. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14268. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14269. }
  14270. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14271. {
  14272. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14274. }
  14275. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14276. {
  14277. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14279. }
  14280. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14281. {
  14282. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14284. }
  14285. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14286. {
  14287. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14289. }
  14290. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14291. {
  14292. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14294. }
  14295. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14296. {
  14297. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14299. }
  14300. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14301. {
  14302. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14304. }
  14305. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14306. {
  14307. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14309. }
  14310. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14311. {
  14312. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14314. }
  14315. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14316. {
  14317. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14319. }
  14320. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14321. {
  14322. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14324. }
  14325. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14326. {
  14327. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14329. }
  14330. }
  14331. }
  14332. fclose(fp);
  14333. }
  14334. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14335. {
  14336. return PASS;
  14337. }
  14338. else
  14339. {
  14340. return FAIL;
  14341. }
  14342. }
  14343. void StoreConfigurationTable(void)
  14344. {
  14345. FILE *outfile;
  14346. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14347. if(outfile == NULL)
  14348. {
  14349. DEBUG_INFO("Error opening file");
  14350. return ;
  14351. }
  14352. /*Core Profile*/
  14353. //AllowOfflineTxForUnknownId
  14354. /*
  14355. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14356. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14359. */
  14360. //DEBUG_INFO("data=%s\n",data);
  14361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14362. //AuthorizationCacheEnabled
  14363. /*
  14364. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14367. */
  14368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14369. //AuthorizeRemoteTxRequests
  14370. /*
  14371. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14374. */
  14375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14376. //BlinkRepeat
  14377. /*
  14378. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14381. */
  14382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14383. //ClockAlignedDataInterval
  14384. /*
  14385. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14388. */
  14389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14390. //ConnectionTimeOut
  14391. /*
  14392. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14395. */
  14396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14397. //GetConfigurationMaxKeys
  14398. /*
  14399. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14402. */
  14403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14404. // HeartbeatInterval
  14405. /*
  14406. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14409. */
  14410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14411. // LightIntensity
  14412. /*
  14413. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14416. */
  14417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14418. // LocalAuthorizeOffline
  14419. /*
  14420. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14423. */
  14424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14425. // LocalPreAuthorize
  14426. /*
  14427. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14430. */
  14431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14432. // MaxEnergyOnInvalidId
  14433. /*
  14434. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14437. */
  14438. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14440. // MeterValuesAlignedData
  14441. /*
  14442. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14445. */
  14446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14447. // MeterValuesAlignedDataMaxLength
  14448. /*
  14449. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14452. */
  14453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14454. // MeterValuesSampledData
  14455. /*
  14456. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14459. */
  14460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14461. // MeterValuesSampledDataMaxLength
  14462. /*
  14463. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14466. */
  14467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14468. // MeterValueSampleInterval
  14469. /*
  14470. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14473. */
  14474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14475. // MinimumStatusDuration
  14476. /*
  14477. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14480. */
  14481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14482. // NumberOfConnectors
  14483. /*
  14484. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14487. {
  14488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14489. }
  14490. else
  14491. {
  14492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14493. }
  14494. */
  14495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14496. // ResetRetries
  14497. /*
  14498. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14501. */
  14502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14503. // ConnectorPhaseRotation
  14504. /*
  14505. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14508. */
  14509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14510. // ConnectorPhaseRotationMaxLength
  14511. /*
  14512. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14515. */
  14516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14517. // StopTransactionOnEVSideDisconnect
  14518. /*
  14519. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14522. */
  14523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14524. // StopTransactionOnInvalidId
  14525. /*
  14526. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14529. */
  14530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14531. // StopTxnAlignedData
  14532. /*
  14533. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14536. */
  14537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14538. // StopTxnAlignedDataMaxLength
  14539. /*
  14540. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14543. */
  14544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14545. // StopTxnSampledData
  14546. /*
  14547. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14550. */
  14551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14552. // StopTxnSampledDataMaxLength
  14553. /*
  14554. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14557. */
  14558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14559. // SupportedFeatureProfiles
  14560. /*
  14561. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14564. */
  14565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14566. // SupportedFeatureProfilesMaxLength
  14567. /*
  14568. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14571. */
  14572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14573. // TransactionMessageAttempts
  14574. /*
  14575. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14578. */
  14579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14580. // TransactionMessageRetryInterval
  14581. /*
  14582. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14585. */
  14586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14587. // UnlockConnectorOnEVSideDisconnect
  14588. /*
  14589. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14592. */
  14593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14594. // WebSocketPingInterval
  14595. /*
  14596. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14599. */
  14600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14601. // QueueOffLineMeterValues
  14602. /*
  14603. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14606. */
  14607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14608. // AuthorizationKey
  14609. /*
  14610. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14613. */
  14614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14615. // SecurityProfile
  14616. /*
  14617. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14620. */
  14621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14622. // DefaultPrice
  14623. /*
  14624. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14627. */
  14628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14629. // CustomDisplayCostAndPrice
  14630. /*
  14631. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14634. */
  14635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14636. // CustomIdleFeeAfterStop
  14637. /*
  14638. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14641. */
  14642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14643. // TimeOffset
  14644. /*
  14645. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14648. */
  14649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14650. // NextTimeOffsetTransitionDateTime
  14651. /*
  14652. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14655. */
  14656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14657. // TimeOffsetNextTransition
  14658. /*
  14659. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14662. */
  14663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14664. // SystemUptimeSec
  14665. /*
  14666. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14669. */
  14670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14671. // FreeVend
  14672. /*
  14673. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14676. */
  14677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14678. // FreeVendIdtag
  14679. /*
  14680. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14683. */
  14684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14685. // OcppServer
  14686. /*
  14687. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14690. */
  14691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14692. // MaintainServer
  14693. /*
  14694. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14697. */
  14698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14699. // StatusNotificationPeriodically
  14700. /*
  14701. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14704. */
  14705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14706. // StatusNotificationInterval
  14707. /*
  14708. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14711. */
  14712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14713. // ConfigurationVersion
  14714. /*
  14715. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14718. */
  14719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14720. //* Local Auth List Management Profile*/
  14721. //LocalAuthListEnabled
  14722. /*
  14723. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14726. */
  14727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14728. //LocalAuthListMaxLength
  14729. /*
  14730. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14733. */
  14734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14735. //SendLocalListMaxLength
  14736. /*
  14737. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14740. */
  14741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14742. //ReserveConnectorZeroSupported
  14743. /*
  14744. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14747. */
  14748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14749. //* Smart Charging Profile */
  14750. //ChargeProfileMaxStackLevel
  14751. /*
  14752. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14755. */
  14756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14757. // ChargingScheduleAllowedChargingRateUnit
  14758. /*
  14759. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14762. */
  14763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14764. // ChargingScheduleMaxPeriods
  14765. /*
  14766. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14769. */
  14770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14771. // ConnectorSwitch3to1PhaseSupported
  14772. /*
  14773. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14776. */
  14777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14778. // MaxChargingProfilesInstalled
  14779. /*
  14780. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14783. */
  14784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14785. fclose(outfile);
  14786. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14787. }
  14788. void getKeyValue(char *keyReq)
  14789. {
  14790. int isEmpty = FALSE;
  14791. int isKnowKey = FALSE;
  14792. DEBUG_INFO("keyReq = %s\n", keyReq);
  14793. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14794. isEmpty = TRUE;
  14795. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14796. {
  14797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14800. {
  14801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14802. }
  14803. else
  14804. {
  14805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14806. }
  14807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14808. isKnowKey = TRUE;
  14809. }
  14810. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14811. {
  14812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14815. {
  14816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14817. }
  14818. else
  14819. {
  14820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14821. }
  14822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14823. isKnowKey = TRUE;
  14824. }
  14825. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14826. {
  14827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14830. {
  14831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14832. }
  14833. else
  14834. {
  14835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14836. }
  14837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14838. isKnowKey = TRUE;
  14839. }
  14840. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14841. {
  14842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14845. {
  14846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14847. }
  14848. else
  14849. {
  14850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14851. }
  14852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14853. isKnowKey = TRUE;
  14854. }
  14855. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14856. {
  14857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14860. {
  14861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14862. }
  14863. else
  14864. {
  14865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14866. }
  14867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14868. isKnowKey = TRUE;
  14869. }
  14870. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14871. {
  14872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14875. {
  14876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14877. }
  14878. else
  14879. {
  14880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14881. }
  14882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14883. isKnowKey = TRUE;
  14884. }
  14885. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14886. {
  14887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14890. {
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14892. }
  14893. else
  14894. {
  14895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14896. }
  14897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14898. isKnowKey = TRUE;
  14899. }
  14900. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14901. {
  14902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14905. {
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14907. }
  14908. else
  14909. {
  14910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14911. }
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14913. isKnowKey = TRUE;
  14914. }
  14915. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14916. {
  14917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14920. {
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14922. }
  14923. else
  14924. {
  14925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14926. }
  14927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14928. isKnowKey = TRUE;
  14929. }
  14930. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14931. {
  14932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14935. {
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14937. }
  14938. else
  14939. {
  14940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14941. }
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14943. isKnowKey = TRUE;
  14944. }
  14945. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14946. {
  14947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14950. {
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14952. }
  14953. else
  14954. {
  14955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14956. }
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14958. isKnowKey = TRUE;
  14959. }
  14960. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14961. {
  14962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14965. {
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14967. }
  14968. else
  14969. {
  14970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14971. }
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14973. isKnowKey = TRUE;
  14974. }
  14975. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14976. {
  14977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14980. {
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14982. }
  14983. else
  14984. {
  14985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14986. }
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14988. isKnowKey = TRUE;
  14989. }
  14990. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14991. {
  14992. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14995. {
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14997. }
  14998. else
  14999. {
  15000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15001. }
  15002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15003. isKnowKey = TRUE;
  15004. }
  15005. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15006. {
  15007. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15010. {
  15011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15012. }
  15013. else
  15014. {
  15015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15016. }
  15017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15018. isKnowKey = TRUE;
  15019. }
  15020. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15021. {
  15022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15025. {
  15026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15027. }
  15028. else
  15029. {
  15030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15031. }
  15032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15033. isKnowKey = TRUE;
  15034. }
  15035. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15036. {
  15037. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15040. {
  15041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15042. }
  15043. else
  15044. {
  15045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15046. }
  15047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15048. isKnowKey = TRUE;
  15049. }
  15050. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15051. {
  15052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15055. {
  15056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15057. }
  15058. else
  15059. {
  15060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15061. }
  15062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15063. isKnowKey = TRUE;
  15064. }
  15065. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15066. {
  15067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15070. {
  15071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15072. }
  15073. else
  15074. {
  15075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15076. }
  15077. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15079. isKnowKey = TRUE;
  15080. }
  15081. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15082. {
  15083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15086. {
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15088. }
  15089. else
  15090. {
  15091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15092. }
  15093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15094. isKnowKey = TRUE;
  15095. }
  15096. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15097. {
  15098. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15101. {
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15103. }
  15104. else
  15105. {
  15106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15107. }
  15108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15109. isKnowKey = TRUE;
  15110. }
  15111. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15112. {
  15113. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15116. {
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15118. }
  15119. else
  15120. {
  15121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15122. }
  15123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15124. isKnowKey = TRUE;
  15125. }
  15126. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15127. {
  15128. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15131. {
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15133. }
  15134. else
  15135. {
  15136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15137. }
  15138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15139. isKnowKey = TRUE;
  15140. }
  15141. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15142. {
  15143. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15146. {
  15147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15148. }
  15149. else
  15150. {
  15151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15152. }
  15153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15154. isKnowKey = TRUE;
  15155. }
  15156. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15157. {
  15158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15161. {
  15162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15163. }
  15164. else
  15165. {
  15166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15167. }
  15168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15169. isKnowKey = TRUE;
  15170. }
  15171. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15172. {
  15173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15176. {
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15178. }
  15179. else
  15180. {
  15181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15182. }
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15184. isKnowKey = TRUE;
  15185. }
  15186. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15187. {
  15188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15191. {
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15193. }
  15194. else
  15195. {
  15196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15197. }
  15198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15199. isKnowKey = TRUE;
  15200. }
  15201. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15202. {
  15203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15206. {
  15207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15208. }
  15209. else
  15210. {
  15211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15212. }
  15213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15214. isKnowKey = TRUE;
  15215. }
  15216. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15217. {
  15218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15221. {
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15223. }
  15224. else
  15225. {
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15227. }
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15229. isKnowKey = TRUE;
  15230. }
  15231. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15232. {
  15233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15236. {
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15238. }
  15239. else
  15240. {
  15241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15242. }
  15243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15244. isKnowKey = TRUE;
  15245. }
  15246. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15247. {
  15248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15251. {
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15253. }
  15254. else
  15255. {
  15256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15257. }
  15258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15259. isKnowKey = TRUE;
  15260. }
  15261. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15262. {
  15263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15266. {
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15268. }
  15269. else
  15270. {
  15271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15272. }
  15273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15274. isKnowKey = TRUE;
  15275. }
  15276. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15277. {
  15278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15281. {
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15283. }
  15284. else
  15285. {
  15286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15287. }
  15288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15289. isKnowKey = TRUE;
  15290. }
  15291. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15292. {
  15293. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15296. {
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15298. }
  15299. else
  15300. {
  15301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15302. }
  15303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15304. isKnowKey = TRUE;
  15305. }
  15306. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15307. {
  15308. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15311. {
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15313. }
  15314. else
  15315. {
  15316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15317. }
  15318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15319. isKnowKey = TRUE;
  15320. }
  15321. /*
  15322. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15323. {
  15324. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15327. {
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15329. }
  15330. else
  15331. {
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15333. }
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15335. isKnowKey = TRUE;
  15336. }*/
  15337. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15338. {
  15339. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15342. {
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15344. }
  15345. else
  15346. {
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15348. }
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15350. isKnowKey = TRUE;
  15351. }
  15352. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15353. {
  15354. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15357. {
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15359. }
  15360. else
  15361. {
  15362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15363. }
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15365. isKnowKey = TRUE;
  15366. }
  15367. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15368. {
  15369. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15372. {
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15374. }
  15375. else
  15376. {
  15377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15378. }
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15380. isKnowKey = TRUE;
  15381. }
  15382. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15383. {
  15384. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15387. {
  15388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15389. }
  15390. else
  15391. {
  15392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15393. }
  15394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15395. isKnowKey = TRUE;
  15396. }
  15397. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15398. {
  15399. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15402. {
  15403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15404. }
  15405. else
  15406. {
  15407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15408. }
  15409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15410. isKnowKey = TRUE;
  15411. }
  15412. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15413. {
  15414. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15417. {
  15418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15419. }
  15420. else
  15421. {
  15422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15423. }
  15424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15425. isKnowKey = TRUE;
  15426. }
  15427. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15428. {
  15429. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15432. {
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15434. }
  15435. else
  15436. {
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15438. }
  15439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15440. isKnowKey = TRUE;
  15441. }
  15442. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15443. {
  15444. struct sysinfo s_info;
  15445. int error = sysinfo(&s_info);
  15446. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15449. {
  15450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15451. }
  15452. else
  15453. {
  15454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15455. }
  15456. if(error != 0)
  15457. {
  15458. DEBUG_WARN("System uptime get error: %d\n", error);
  15459. }
  15460. else
  15461. {
  15462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15463. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15464. }
  15465. isKnowKey = TRUE;
  15466. }
  15467. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15468. {
  15469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15472. {
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15474. }
  15475. else
  15476. {
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15478. }
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15480. isKnowKey = TRUE;
  15481. }
  15482. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15483. {
  15484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15487. {
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15489. }
  15490. else
  15491. {
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15493. }
  15494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15495. isKnowKey = TRUE;
  15496. }
  15497. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15498. {
  15499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15502. {
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15504. }
  15505. else
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15508. }
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15510. isKnowKey = TRUE;
  15511. }
  15512. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15513. {
  15514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15517. {
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15519. }
  15520. else
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15523. }
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15525. isKnowKey = TRUE;
  15526. }
  15527. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15528. {
  15529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15532. {
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15534. }
  15535. else
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15538. }
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15540. isKnowKey = TRUE;
  15541. }
  15542. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15543. {
  15544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15549. }
  15550. else
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15553. }
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15555. isKnowKey = TRUE;
  15556. }
  15557. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15558. {
  15559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15562. {
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15564. }
  15565. else
  15566. {
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15568. }
  15569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15570. isKnowKey = TRUE;
  15571. }
  15572. #if 1
  15573. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15574. {
  15575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15577. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15578. {
  15579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15580. }
  15581. else
  15582. {
  15583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15584. }
  15585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15586. isKnowKey = TRUE;
  15587. }
  15588. #endif
  15589. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15590. {
  15591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15593. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15594. {
  15595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15596. }
  15597. else
  15598. {
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15600. }
  15601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15602. isKnowKey = TRUE;
  15603. }
  15604. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15605. {
  15606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15608. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15609. {
  15610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15611. }
  15612. else
  15613. {
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15615. }
  15616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15617. isKnowKey = TRUE;
  15618. }
  15619. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15620. {
  15621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15623. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15624. {
  15625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15626. }
  15627. else
  15628. {
  15629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15630. }
  15631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15632. isKnowKey = TRUE;
  15633. }
  15634. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15635. {
  15636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15638. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15639. {
  15640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15641. }
  15642. else
  15643. {
  15644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15645. }
  15646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15647. isKnowKey = TRUE;
  15648. }
  15649. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15650. {
  15651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15653. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15654. {
  15655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15656. }
  15657. else
  15658. {
  15659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15660. }
  15661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15662. isKnowKey = TRUE;
  15663. }
  15664. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15665. {
  15666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15668. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15669. {
  15670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15671. }
  15672. else
  15673. {
  15674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15675. }
  15676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15677. isKnowKey = TRUE;
  15678. }
  15679. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15680. {
  15681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15683. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15684. {
  15685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15686. }
  15687. else
  15688. {
  15689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15690. }
  15691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15692. isKnowKey = TRUE;
  15693. }
  15694. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15695. {
  15696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15698. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15699. {
  15700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15701. }
  15702. else
  15703. {
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15705. }
  15706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15707. isKnowKey = TRUE;
  15708. }
  15709. //=========================================================
  15710. if(!isEmpty && !isKnowKey)
  15711. {
  15712. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15713. strcpy(unknownkey[UnknownKeynum], keyReq);
  15714. UnknownKeynum = UnknownKeynum + 1;
  15715. }
  15716. }
  15717. void processUnkownKey(void)
  15718. {
  15719. DEBUG_INFO("processUnkownKey...\n");
  15720. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15721. for(int index=0; index < UnknownKeynum; index++)
  15722. {
  15723. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15724. {
  15725. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15726. }
  15727. }
  15728. }
  15729. int setKeyValue(char *key, char *value)
  15730. {
  15731. int isSuccess = NotSupported;
  15732. int check_ascii=0;
  15733. char str[501]={0};
  15734. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15735. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15736. {
  15737. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15739. {
  15740. strcpy(str, (const char*)value);
  15741. for(int i = 0; str[i]; i++){
  15742. str[i] = tolower(str[i]);
  15743. }
  15744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15745. isSuccess = ConfigurationStatus_Accepted;
  15746. }
  15747. else
  15748. {
  15749. isSuccess = ConfigurationStatus_Rejected;
  15750. }
  15751. }
  15752. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15753. {
  15754. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15756. {
  15757. strcpy(str, (const char*)value);
  15758. for(int i = 0; str[i]; i++){
  15759. str[i] = tolower(str[i]);
  15760. }
  15761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15762. isSuccess = ConfigurationStatus_Accepted;
  15763. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15764. }
  15765. else
  15766. {
  15767. isSuccess = ConfigurationStatus_Rejected;
  15768. }
  15769. }
  15770. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15771. {
  15772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15773. {
  15774. strcpy(str, (const char*)value);
  15775. for(int i = 0; str[i]; i++)
  15776. {
  15777. str[i] = tolower(str[i]);
  15778. }
  15779. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15781. isSuccess = ConfigurationStatus_Accepted;
  15782. }
  15783. else
  15784. {
  15785. isSuccess = ConfigurationStatus_Rejected;
  15786. }
  15787. }
  15788. if(strcmp(key, "BlinkRepeat") == 0)
  15789. {
  15790. //Charger.BlinkRepeat = Integer.parseInt(value);
  15791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15792. {
  15793. check_ascii = value[0];
  15794. if( (check_ascii < 48) || (check_ascii > 57) )
  15795. {
  15796. isSuccess = ConfigurationStatus_Rejected;
  15797. }
  15798. else
  15799. {
  15800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15801. isSuccess = ConfigurationStatus_Accepted;
  15802. }
  15803. }
  15804. else
  15805. {
  15806. isSuccess = ConfigurationStatus_Rejected;
  15807. }
  15808. }
  15809. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15810. {
  15811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15812. {
  15813. check_ascii = value[0];
  15814. if( (check_ascii < 48) || (check_ascii > 57) )
  15815. {
  15816. isSuccess = ConfigurationStatus_Rejected;
  15817. }
  15818. else
  15819. {
  15820. if((atoi(value) == 0) || (atoi(value) >= 5))
  15821. {
  15822. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15823. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15824. isSuccess = ConfigurationStatus_Accepted;
  15825. }
  15826. else
  15827. isSuccess = ConfigurationStatus_Rejected;
  15828. }
  15829. }
  15830. else
  15831. {
  15832. isSuccess = ConfigurationStatus_Rejected;
  15833. }
  15834. }
  15835. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15836. {
  15837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15838. {
  15839. check_ascii = value[0];
  15840. if( (check_ascii < 48) || (check_ascii > 57) )
  15841. {
  15842. isSuccess = ConfigurationStatus_Rejected;
  15843. }
  15844. else
  15845. {
  15846. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15848. isSuccess = ConfigurationStatus_Accepted;
  15849. }
  15850. }
  15851. else
  15852. {
  15853. isSuccess = ConfigurationStatus_Rejected;
  15854. }
  15855. }
  15856. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15857. {
  15858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15859. {
  15860. check_ascii = value[0];
  15861. if( (check_ascii < 48) || (check_ascii > 57) )
  15862. {
  15863. isSuccess = ConfigurationStatus_Rejected;
  15864. }
  15865. else
  15866. {
  15867. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15869. isSuccess = ConfigurationStatus_Accepted;
  15870. }
  15871. }
  15872. else
  15873. {
  15874. isSuccess = ConfigurationStatus_Rejected;
  15875. }
  15876. }
  15877. if(strcmp(key, "HeartbeatInterval") == 0)
  15878. {
  15879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15880. {
  15881. check_ascii = value[0];
  15882. if( (check_ascii < 48) || (check_ascii > 57) )
  15883. {
  15884. isSuccess = ConfigurationStatus_Rejected;
  15885. }
  15886. else
  15887. {
  15888. if((atoi(value) == 0) || (atoi(value) >= 10))
  15889. {
  15890. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15892. HeartBeatWaitTime = atoi(value);
  15893. isSuccess = ConfigurationStatus_Accepted;
  15894. }
  15895. else
  15896. {
  15897. isSuccess = ConfigurationStatus_Rejected;
  15898. }
  15899. }
  15900. }
  15901. else
  15902. {
  15903. isSuccess = ConfigurationStatus_Rejected;
  15904. }
  15905. }
  15906. if(strcmp(key, "LightIntensity") == 0)
  15907. {
  15908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15909. {
  15910. check_ascii = value[0];
  15911. if( (check_ascii < 48) || (check_ascii > 57) )
  15912. {
  15913. isSuccess = ConfigurationStatus_Rejected;
  15914. }
  15915. else
  15916. {
  15917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15918. isSuccess = ConfigurationStatus_Accepted;
  15919. }
  15920. }
  15921. else
  15922. {
  15923. isSuccess = ConfigurationStatus_Rejected;
  15924. }
  15925. }
  15926. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15927. {
  15928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15929. {
  15930. strcpy(str, (const char*)value);
  15931. for(int i = 0; str[i]; i++)
  15932. {
  15933. str[i] = tolower(str[i]);
  15934. }
  15935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15936. isSuccess = ConfigurationStatus_Accepted;
  15937. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15938. }
  15939. else
  15940. {
  15941. isSuccess = ConfigurationStatus_Rejected;
  15942. }
  15943. }
  15944. if(strcmp(key, "LocalPreAuthorize") == 0)
  15945. {
  15946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15947. {
  15948. strcpy(str, (const char*)value);
  15949. for(int i = 0; str[i]; i++)
  15950. {
  15951. str[i] = tolower(str[i]);
  15952. }
  15953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15954. isSuccess = ConfigurationStatus_Accepted;
  15955. }
  15956. else
  15957. {
  15958. isSuccess = ConfigurationStatus_Rejected;
  15959. }
  15960. }
  15961. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15962. {
  15963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15964. {
  15965. check_ascii = value[0];
  15966. if( (check_ascii < 48) || (check_ascii > 57) )
  15967. {
  15968. isSuccess = ConfigurationStatus_Rejected;
  15969. }
  15970. else
  15971. {
  15972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15973. isSuccess = ConfigurationStatus_Accepted;
  15974. }
  15975. }
  15976. else
  15977. {
  15978. isSuccess = ConfigurationStatus_Rejected;
  15979. }
  15980. }
  15981. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15982. {
  15983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15984. {
  15985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15986. isSuccess = ConfigurationStatus_Accepted;
  15987. }
  15988. else
  15989. {
  15990. isSuccess = ConfigurationStatus_Rejected;
  15991. }
  15992. }
  15993. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15994. {
  15995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15996. {
  15997. check_ascii = value[0];
  15998. if( (check_ascii < 48) || (check_ascii > 57) )
  15999. {
  16000. isSuccess = ConfigurationStatus_Rejected;
  16001. }
  16002. else
  16003. {
  16004. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16006. isSuccess = ConfigurationStatus_Accepted;
  16007. }
  16008. }
  16009. else
  16010. {
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. }
  16014. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16015. {
  16016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16017. {
  16018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16019. isSuccess = ConfigurationStatus_Accepted;
  16020. }
  16021. else
  16022. {
  16023. isSuccess = ConfigurationStatus_Rejected;
  16024. }
  16025. }
  16026. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16027. {
  16028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16029. {
  16030. check_ascii = value[0];
  16031. if( (check_ascii < 48) || (check_ascii > 57) )
  16032. {
  16033. isSuccess = ConfigurationStatus_Rejected;
  16034. }
  16035. else
  16036. {
  16037. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16039. isSuccess = ConfigurationStatus_Accepted;
  16040. }
  16041. }
  16042. else
  16043. {
  16044. isSuccess = ConfigurationStatus_Rejected;
  16045. }
  16046. }
  16047. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16048. {
  16049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16050. {
  16051. check_ascii = value[0];
  16052. if( (check_ascii < 48) || (check_ascii > 57) )
  16053. {
  16054. isSuccess = ConfigurationStatus_Rejected;
  16055. }
  16056. else
  16057. {
  16058. if((atoi(value) == 0) || (atoi(value) >= 3))
  16059. {
  16060. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16062. isSuccess = ConfigurationStatus_Accepted;
  16063. }
  16064. else
  16065. {
  16066. isSuccess = ConfigurationStatus_Rejected;
  16067. }
  16068. }
  16069. }
  16070. else
  16071. {
  16072. isSuccess = ConfigurationStatus_Rejected;
  16073. }
  16074. }
  16075. if(strcmp(key, "MinimumStatusDuration") == 0)
  16076. {
  16077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16078. {
  16079. check_ascii = value[0];
  16080. if( (check_ascii < 48) || (check_ascii > 57) )
  16081. {
  16082. isSuccess = ConfigurationStatus_Rejected;
  16083. }
  16084. else
  16085. {
  16086. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16087. {
  16088. isSuccess = ConfigurationStatus_Rejected;
  16089. }
  16090. else
  16091. {
  16092. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16094. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16095. isSuccess = ConfigurationStatus_Accepted;
  16096. }
  16097. }
  16098. }
  16099. else
  16100. {
  16101. isSuccess = ConfigurationStatus_Rejected;
  16102. }
  16103. }
  16104. if(strcmp(key, "NumberOfConnectors") == 0)
  16105. {
  16106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16107. {
  16108. check_ascii = value[0];
  16109. if( (check_ascii < 48) || (check_ascii > 57) )
  16110. {
  16111. isSuccess = ConfigurationStatus_Rejected;
  16112. }
  16113. else
  16114. {
  16115. //Charger.ResetRetries = Integer.parseInt(value);
  16116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16117. isSuccess = ConfigurationStatus_Accepted;
  16118. }
  16119. }
  16120. else
  16121. {
  16122. isSuccess = ConfigurationStatus_Rejected;
  16123. }
  16124. }
  16125. if(strcmp(key, "ResetRetries") == 0)
  16126. {
  16127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16128. {
  16129. check_ascii = value[0];
  16130. if( (check_ascii < 48) || (check_ascii > 57) )
  16131. {
  16132. isSuccess = ConfigurationStatus_Rejected;
  16133. }
  16134. else
  16135. {
  16136. //Charger.ResetRetries = Integer.parseInt(value);
  16137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16138. isSuccess = ConfigurationStatus_Accepted;
  16139. }
  16140. }
  16141. else
  16142. {
  16143. isSuccess = ConfigurationStatus_Rejected;
  16144. }
  16145. }
  16146. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16147. {
  16148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16149. {
  16150. strcpy(str, (const char*)value);
  16151. for(int i = 0; str[i]; i++)
  16152. {
  16153. str[i] = tolower(str[i]);
  16154. }
  16155. if(strcmp(str, "notapplicable")== 0)
  16156. {
  16157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16158. isSuccess = ConfigurationStatus_Accepted;
  16159. }
  16160. else if(strcmp(str, "unknown")== 0)
  16161. {
  16162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16163. isSuccess = ConfigurationStatus_Accepted;
  16164. }
  16165. else if(strcmp(str, "rst")== 0)
  16166. {
  16167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16168. isSuccess = ConfigurationStatus_Accepted;
  16169. }
  16170. else if(strcmp(str, "rts")== 0)
  16171. {
  16172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16173. isSuccess = ConfigurationStatus_Accepted;
  16174. }
  16175. else if(strcmp(str, "srt")== 0)
  16176. {
  16177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16178. isSuccess = ConfigurationStatus_Accepted;
  16179. }
  16180. else if(strcmp(str, "str")== 0)
  16181. {
  16182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16183. isSuccess = ConfigurationStatus_Accepted;
  16184. }
  16185. else if(strcmp(str, "trs")== 0)
  16186. {
  16187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16188. isSuccess = ConfigurationStatus_Accepted;
  16189. }
  16190. else if(strcmp(str, "tsr")== 0)
  16191. {
  16192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16193. isSuccess = ConfigurationStatus_Accepted;
  16194. }
  16195. else
  16196. {
  16197. isSuccess = ConfigurationStatus_Rejected;
  16198. }
  16199. }
  16200. else
  16201. {
  16202. isSuccess = ConfigurationStatus_Rejected;
  16203. }
  16204. }
  16205. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16206. {
  16207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16208. {
  16209. check_ascii = value[0];
  16210. if( (check_ascii < 48) || (check_ascii > 57) )
  16211. {
  16212. isSuccess = ConfigurationStatus_Rejected;
  16213. }
  16214. else
  16215. {
  16216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16217. isSuccess = ConfigurationStatus_Accepted;
  16218. }
  16219. }
  16220. else
  16221. {
  16222. isSuccess = ConfigurationStatus_Rejected;
  16223. }
  16224. }
  16225. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16226. {
  16227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16228. {
  16229. strcpy(str, (const char*)value);
  16230. for(int i = 0; str[i]; i++)
  16231. {
  16232. str[i] = tolower(str[i]);
  16233. }
  16234. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16236. isSuccess = ConfigurationStatus_Accepted;
  16237. }
  16238. else
  16239. {
  16240. isSuccess = ConfigurationStatus_Rejected;
  16241. }
  16242. }
  16243. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16244. {
  16245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16246. {
  16247. strcpy(str, (const char*)value);
  16248. for(int i = 0; str[i]; i++)
  16249. {
  16250. str[i] = tolower(str[i]);
  16251. }
  16252. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16254. isSuccess = ConfigurationStatus_Accepted;
  16255. }
  16256. else
  16257. {
  16258. isSuccess = ConfigurationStatus_Rejected;
  16259. }
  16260. }
  16261. if(strcmp(key, "StopTxnAlignedData") == 0)
  16262. {
  16263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16264. {
  16265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16266. isSuccess = ConfigurationStatus_Accepted;
  16267. }
  16268. else
  16269. {
  16270. isSuccess = ConfigurationStatus_Rejected;
  16271. }
  16272. }
  16273. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16274. {
  16275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16276. {
  16277. check_ascii = value[0];
  16278. if( (check_ascii < 48) || (check_ascii > 57) )
  16279. {
  16280. isSuccess = ConfigurationStatus_Rejected;
  16281. }
  16282. else
  16283. {
  16284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16285. isSuccess = ConfigurationStatus_Accepted;
  16286. }
  16287. }
  16288. else
  16289. {
  16290. isSuccess = ConfigurationStatus_Rejected;
  16291. }
  16292. }
  16293. if(strcmp(key, "StopTxnSampledData") == 0)
  16294. {
  16295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16296. {
  16297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16298. isSuccess = ConfigurationStatus_Accepted;
  16299. }
  16300. else
  16301. {
  16302. isSuccess = ConfigurationStatus_Rejected;
  16303. }
  16304. }
  16305. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16306. {
  16307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16308. {
  16309. check_ascii = value[0];
  16310. if( (check_ascii < 48) || (check_ascii > 57) )
  16311. {
  16312. isSuccess = ConfigurationStatus_Rejected;
  16313. }
  16314. else
  16315. {
  16316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16317. isSuccess = ConfigurationStatus_Accepted;
  16318. }
  16319. }
  16320. else
  16321. {
  16322. isSuccess = ConfigurationStatus_Rejected;
  16323. }
  16324. }
  16325. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16326. {
  16327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16328. {
  16329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16330. isSuccess = ConfigurationStatus_Accepted;
  16331. }
  16332. else
  16333. {
  16334. isSuccess = ConfigurationStatus_Rejected;
  16335. }
  16336. }
  16337. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16338. {
  16339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16340. {
  16341. check_ascii = value[0];
  16342. if( (check_ascii < 48) || (check_ascii > 57) )
  16343. {
  16344. isSuccess = ConfigurationStatus_Rejected;
  16345. }
  16346. else
  16347. {
  16348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16349. isSuccess = ConfigurationStatus_Accepted;
  16350. }
  16351. }
  16352. else
  16353. {
  16354. isSuccess = ConfigurationStatus_Rejected;
  16355. }
  16356. }
  16357. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16358. {
  16359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16360. {
  16361. check_ascii = value[0];
  16362. if( (check_ascii < 48) || (check_ascii > 57) )
  16363. {
  16364. isSuccess = ConfigurationStatus_Rejected;
  16365. }
  16366. else
  16367. {
  16368. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16370. TransactionMessageAttemptsValue = atoi(value);
  16371. isSuccess = ConfigurationStatus_Accepted;
  16372. }
  16373. }
  16374. else
  16375. {
  16376. isSuccess = ConfigurationStatus_Rejected;
  16377. }
  16378. }
  16379. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16380. {
  16381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16382. {
  16383. check_ascii = value[0];
  16384. if( (check_ascii < 48) || (check_ascii > 57) )
  16385. {
  16386. isSuccess = ConfigurationStatus_Rejected;
  16387. }
  16388. else
  16389. {
  16390. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16392. TransactionMessageRetryIntervalValue = atoi(value);
  16393. isSuccess = ConfigurationStatus_Accepted;
  16394. }
  16395. }
  16396. else
  16397. {
  16398. isSuccess = ConfigurationStatus_Rejected;
  16399. }
  16400. }
  16401. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16402. {
  16403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16404. {
  16405. strcpy(str, (const char*)value);
  16406. for(int i = 0; str[i]; i++)
  16407. {
  16408. str[i] = tolower(str[i]);
  16409. }
  16410. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16412. isSuccess = ConfigurationStatus_Accepted;
  16413. }
  16414. else
  16415. {
  16416. isSuccess = ConfigurationStatus_Rejected;
  16417. }
  16418. }
  16419. if(strcmp(key, "WebSocketPingInterval") == 0)
  16420. {
  16421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16422. {
  16423. check_ascii = value[0];
  16424. if( (check_ascii < 48) || (check_ascii > 57) )
  16425. {
  16426. isSuccess = ConfigurationStatus_Rejected;
  16427. }
  16428. else
  16429. {
  16430. if((atoi(value) == 0) || (atoi(value) >= 10))
  16431. {
  16432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16433. isSuccess = ConfigurationStatus_Accepted;
  16434. }
  16435. else
  16436. isSuccess = ConfigurationStatus_Rejected;
  16437. }
  16438. }
  16439. else
  16440. {
  16441. isSuccess = ConfigurationStatus_Rejected;
  16442. }
  16443. }
  16444. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16445. {
  16446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16447. {
  16448. strcpy(str, (const char*)value);
  16449. for(int i = 0; str[i]; i++)
  16450. {
  16451. str[i] = tolower(str[i]);
  16452. }
  16453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16454. isSuccess = ConfigurationStatus_Accepted;
  16455. }
  16456. else
  16457. {
  16458. isSuccess = ConfigurationStatus_Rejected;
  16459. }
  16460. }
  16461. if(strcmp(key, "AuthorizationKey") == 0)
  16462. {
  16463. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16464. {
  16465. strcpy(str, (const char*)value);
  16466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16467. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16468. isSuccess = ConfigurationStatus_Accepted;
  16469. }
  16470. else
  16471. {
  16472. isSuccess = ConfigurationStatus_Rejected;
  16473. }
  16474. }
  16475. if(strcmp(key, "SecurityProfile") == 0)
  16476. {
  16477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16478. {
  16479. check_ascii = value[0];
  16480. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16481. {
  16482. isSuccess = ConfigurationStatus_Rejected;
  16483. }
  16484. else if(check_ascii == 0x33)
  16485. {
  16486. isSuccess = NotSupported;
  16487. }
  16488. else
  16489. {
  16490. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16491. {
  16492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16493. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16494. isSuccess = ConfigurationStatus_Accepted;
  16495. }
  16496. else
  16497. isSuccess = ConfigurationStatus_Rejected;
  16498. }
  16499. }
  16500. else
  16501. {
  16502. isSuccess = ConfigurationStatus_Rejected;
  16503. }
  16504. }
  16505. if(strcmp(key, "DefaultPrice") == 0)
  16506. {
  16507. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16508. {
  16509. strcpy(str, (const char*)value);
  16510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16511. isSuccess = ConfigurationStatus_Accepted;
  16512. }
  16513. else
  16514. {
  16515. isSuccess = ConfigurationStatus_Rejected;
  16516. }
  16517. }
  16518. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16519. {
  16520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16521. {
  16522. strcpy(str, (const char*)value);
  16523. for(int i = 0; str[i]; i++)
  16524. {
  16525. str[i] = tolower(str[i]);
  16526. }
  16527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16528. isSuccess = ConfigurationStatus_Accepted;
  16529. }
  16530. else
  16531. {
  16532. isSuccess = ConfigurationStatus_Rejected;
  16533. }
  16534. }
  16535. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16536. {
  16537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16538. {
  16539. strcpy(str, (const char*)value);
  16540. for(int i = 0; str[i]; i++)
  16541. {
  16542. str[i] = tolower(str[i]);
  16543. }
  16544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16545. isSuccess = ConfigurationStatus_Accepted;
  16546. }
  16547. else
  16548. {
  16549. isSuccess = ConfigurationStatus_Rejected;
  16550. }
  16551. }
  16552. if(strcmp(key, "TimeOffset") == 0)
  16553. {
  16554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16555. {
  16556. strcpy(str, (const char*)value);
  16557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16558. isSuccess = ConfigurationStatus_Accepted;
  16559. }
  16560. else
  16561. {
  16562. isSuccess = ConfigurationStatus_Rejected;
  16563. }
  16564. }
  16565. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16566. {
  16567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16568. {
  16569. strcpy(str, (const char*)value);
  16570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16571. isSuccess = ConfigurationStatus_Accepted;
  16572. }
  16573. else
  16574. {
  16575. isSuccess = ConfigurationStatus_Rejected;
  16576. }
  16577. }
  16578. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16579. {
  16580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16581. {
  16582. strcpy(str, (const char*)value);
  16583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16584. isSuccess = ConfigurationStatus_Accepted;
  16585. }
  16586. else
  16587. {
  16588. isSuccess = ConfigurationStatus_Rejected;
  16589. }
  16590. }
  16591. if(strcmp(key, "SystemUptimeSec") == 0)
  16592. {
  16593. isSuccess = NotSupported;
  16594. }
  16595. if(strcmp(key, "FreeVend") == 0)
  16596. {
  16597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16598. {
  16599. strcpy(str, (const char*)value);
  16600. for(int i = 0; str[i]; i++)
  16601. {
  16602. str[i] = tolower(str[i]);
  16603. }
  16604. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16606. isSuccess = ConfigurationStatus_Accepted;
  16607. }
  16608. else
  16609. {
  16610. isSuccess = ConfigurationStatus_Rejected;
  16611. }
  16612. }
  16613. if(strcmp(key, "FreeVendIdtag") == 0)
  16614. {
  16615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16616. {
  16617. strcpy(str, (const char*)value);
  16618. if(strlen(str) <= 20)
  16619. {
  16620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16621. isSuccess = ConfigurationStatus_Accepted;
  16622. }
  16623. else
  16624. {
  16625. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16626. isSuccess = ConfigurationStatus_Rejected;
  16627. }
  16628. }
  16629. else
  16630. {
  16631. isSuccess = ConfigurationStatus_Rejected;
  16632. }
  16633. }
  16634. if(strcmp(key, "OcppServer") == 0)
  16635. {
  16636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16637. {
  16638. strcpy(str, (const char*)value);
  16639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16640. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16641. isSuccess = ConfigurationStatus_Accepted;
  16642. }
  16643. else
  16644. {
  16645. isSuccess = ConfigurationStatus_Rejected;
  16646. }
  16647. }
  16648. if(strcmp(key, "MaintainServer") == 0)
  16649. {
  16650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16651. {
  16652. strcpy(str, (const char*)value);
  16653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16654. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16655. isSuccess = ConfigurationStatus_Accepted;
  16656. }
  16657. else
  16658. {
  16659. isSuccess = ConfigurationStatus_Rejected;
  16660. }
  16661. }
  16662. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16663. {
  16664. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16665. {
  16666. strcpy(str, (const char*)value);
  16667. for(int i = 0; str[i]; i++)
  16668. {
  16669. str[i] = tolower(str[i]);
  16670. }
  16671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16672. isSuccess = ConfigurationStatus_Accepted;
  16673. }
  16674. else
  16675. {
  16676. isSuccess = ConfigurationStatus_Rejected;
  16677. }
  16678. }
  16679. if(strcmp(key, "StatusNotificationInterval") == 0)
  16680. {
  16681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16682. {
  16683. check_ascii = value[0];
  16684. if( (check_ascii < 48) || (check_ascii > 57) )
  16685. {
  16686. isSuccess = ConfigurationStatus_Rejected;
  16687. }
  16688. else
  16689. {
  16690. if((atoi(value) == 0) || (atoi(value) >= 10))
  16691. {
  16692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16693. isSuccess = ConfigurationStatus_Accepted;
  16694. }
  16695. else
  16696. isSuccess = ConfigurationStatus_Rejected;
  16697. }
  16698. }
  16699. else
  16700. {
  16701. isSuccess = ConfigurationStatus_Rejected;
  16702. }
  16703. }
  16704. #if 0
  16705. //For OCPP Test Case
  16706. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16707. {
  16708. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16709. {
  16710. strcpy(str, (const char*)value);
  16711. for(int i = 0; str[i]; i++)
  16712. {
  16713. str[i] = tolower(str[i]);
  16714. }
  16715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16716. isSuccess = ConfigurationStatus_Accepted;
  16717. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16718. }
  16719. else
  16720. {
  16721. isSuccess = ConfigurationStatus_Rejected;
  16722. }
  16723. }
  16724. #endif
  16725. #if 1
  16726. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16727. {
  16728. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16729. {
  16730. strcpy(str, (const char*)value);
  16731. for(int i = 0; str[i]; i++)
  16732. {
  16733. str[i] = tolower(str[i]);
  16734. }
  16735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16736. isSuccess = ConfigurationStatus_Accepted;
  16737. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16738. }
  16739. else
  16740. {
  16741. isSuccess = ConfigurationStatus_Rejected;
  16742. }
  16743. }
  16744. #endif
  16745. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16746. {
  16747. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16748. {
  16749. check_ascii = value[0];
  16750. if( (check_ascii < 48) || (check_ascii > 57) )
  16751. {
  16752. isSuccess = ConfigurationStatus_Rejected;
  16753. }
  16754. else
  16755. {
  16756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16757. isSuccess = ConfigurationStatus_Accepted;
  16758. }
  16759. }
  16760. else
  16761. {
  16762. isSuccess = ConfigurationStatus_Rejected;
  16763. }
  16764. }
  16765. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16766. {
  16767. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16768. {
  16769. check_ascii = value[0];
  16770. if( (check_ascii < 48) || (check_ascii > 57) )
  16771. {
  16772. isSuccess = ConfigurationStatus_Rejected;
  16773. }
  16774. else
  16775. {
  16776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16777. isSuccess = ConfigurationStatus_Accepted;
  16778. }
  16779. }
  16780. else
  16781. {
  16782. isSuccess = ConfigurationStatus_Rejected;
  16783. }
  16784. }
  16785. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16786. {
  16787. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16788. {
  16789. strcpy(str, (const char*)value);
  16790. for(int i = 0; str[i]; i++)
  16791. {
  16792. str[i] = tolower(str[i]);
  16793. }
  16794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16795. isSuccess = ConfigurationStatus_Accepted;
  16796. }
  16797. else
  16798. {
  16799. isSuccess = ConfigurationStatus_Rejected;
  16800. }
  16801. }
  16802. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16803. {
  16804. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16805. {
  16806. check_ascii = value[0];
  16807. if( (check_ascii < 48) || (check_ascii > 57) )
  16808. {
  16809. isSuccess = ConfigurationStatus_Rejected;
  16810. }
  16811. else
  16812. {
  16813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16814. isSuccess = ConfigurationStatus_Accepted;
  16815. }
  16816. }
  16817. else
  16818. {
  16819. isSuccess = ConfigurationStatus_Rejected;
  16820. }
  16821. }
  16822. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16823. {
  16824. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16825. {
  16826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16827. isSuccess = ConfigurationStatus_Accepted;
  16828. }
  16829. else
  16830. {
  16831. isSuccess = ConfigurationStatus_Rejected;
  16832. }
  16833. }
  16834. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16835. {
  16836. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16837. {
  16838. check_ascii = value[0];
  16839. if( (check_ascii < 48) || (check_ascii > 57) )
  16840. {
  16841. isSuccess = ConfigurationStatus_Rejected;
  16842. }
  16843. else
  16844. {
  16845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16846. isSuccess = ConfigurationStatus_Accepted;
  16847. }
  16848. }
  16849. else
  16850. {
  16851. isSuccess = ConfigurationStatus_Rejected;
  16852. }
  16853. }
  16854. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16855. {
  16856. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16857. {
  16858. strcpy(str, (const char*)value);
  16859. for(int i = 0; str[i]; i++)
  16860. {
  16861. str[i] = tolower(str[i]);
  16862. }
  16863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16864. isSuccess = ConfigurationStatus_Accepted;
  16865. }
  16866. else
  16867. {
  16868. isSuccess = ConfigurationStatus_Rejected;
  16869. }
  16870. }
  16871. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16872. {
  16873. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16874. {
  16875. check_ascii = value[0];
  16876. if( (check_ascii < 48) || (check_ascii > 57) )
  16877. {
  16878. isSuccess = ConfigurationStatus_Rejected;
  16879. }
  16880. else
  16881. {
  16882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16883. isSuccess = ConfigurationStatus_Accepted;
  16884. }
  16885. }
  16886. else
  16887. {
  16888. isSuccess = ConfigurationStatus_Rejected;
  16889. }
  16890. }
  16891. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16892. return isSuccess;
  16893. }
  16894. int TransactionMessageAttemptsGet(void)
  16895. {
  16896. return TransactionMessageAttemptsValue;
  16897. }
  16898. int FirstHeartBeatResponse(void)
  16899. {
  16900. return FirstHeartBeat;
  16901. }
  16902. int TransactionMessageRetryIntervalGet(void)
  16903. {
  16904. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16905. }
  16906. int ReadHttpStatus(int sock)
  16907. {
  16908. //char c;
  16909. char buff[1024]="",*ptr=buff+1;
  16910. int bytes_received, status;
  16911. DEBUG_INFO("Begin Response ..\n");
  16912. while((bytes_received = recv(sock, ptr, 1, 0))){
  16913. if(bytes_received==-1){
  16914. perror("ReadHttpStatus");
  16915. exit(1);
  16916. }
  16917. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16918. ptr++;
  16919. }
  16920. *ptr=0;
  16921. ptr=buff+1;
  16922. sscanf(ptr,"%*s %d ", &status);
  16923. DEBUG_INFO("%s\n",ptr);
  16924. DEBUG_INFO("status=%d\n",status);
  16925. DEBUG_INFO("End Response ..\n");
  16926. return (bytes_received>0)?status:0;
  16927. }
  16928. //the only filed that it parsed is 'Content-Length'
  16929. int ParseHeader(int sock)
  16930. {
  16931. //char c;
  16932. char buff[1024]="",*ptr=buff+4;
  16933. int bytes_received;
  16934. DEBUG_INFO("Begin HEADER ..\n");
  16935. while((bytes_received = recv(sock, ptr, 1, 0))){
  16936. if(bytes_received==-1){
  16937. perror("Parse Header");
  16938. exit(1);
  16939. }
  16940. if(
  16941. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16942. (ptr[-1]=='\r') && (*ptr=='\n' )
  16943. ) break;
  16944. ptr++;
  16945. }
  16946. *ptr=0;
  16947. ptr=buff+4;
  16948. //printf("%s",ptr);
  16949. if(bytes_received){
  16950. ptr=strstr(ptr,"Content-Length:");
  16951. if(ptr){
  16952. sscanf(ptr,"%*s %d",&bytes_received);
  16953. }else
  16954. bytes_received=-1; //unknown size
  16955. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16956. }
  16957. DEBUG_INFO("End HEADER ..\n");
  16958. return bytes_received ;
  16959. }
  16960. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16961. {
  16962. int result = TRUE;
  16963. char rmFileCmd[100]={0};
  16964. char FilePath[100]={0};
  16965. char ftpbuf[200];
  16966. int systemresult;
  16967. sprintf(FilePath,"/mnt/%s",filename);
  16968. system("ping 8.8.8.8 &");
  16969. if((access(FilePath,F_OK))!=-1)
  16970. {
  16971. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16972. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16973. system(rmFileCmd);
  16974. }
  16975. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16976. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16977. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16978. systemresult = system(ftpbuf);
  16979. if(systemresult != 0)
  16980. {
  16981. DEBUG_INFO("http DownLoad error!\n");
  16982. result = FALSE;
  16983. }
  16984. system("pkill ping");
  16985. return result;
  16986. }
  16987. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16988. {
  16989. int result = TRUE;
  16990. char rmFileCmd[100]={0};
  16991. char FilePath[100]={0};
  16992. char ftpbuf[200];
  16993. int systemresult;
  16994. sprintf(FilePath,"/mnt/%s",filename);
  16995. system("ping 8.8.8.8 &");
  16996. if((access(FilePath,F_OK))!=-1)
  16997. {
  16998. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16999. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17000. system(rmFileCmd);
  17001. }
  17002. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17003. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17004. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17005. systemresult = system(ftpbuf);
  17006. if(systemresult != 0)
  17007. {
  17008. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17009. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17010. systemresult = system(ftpbuf);
  17011. if(systemresult != 0)
  17012. {
  17013. DEBUG_WARN("wget error!\n");
  17014. result = FALSE;
  17015. }
  17016. }
  17017. system("pkill ping");
  17018. return result;
  17019. }
  17020. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17021. {
  17022. char rmFileCmd[100]={0};
  17023. char FilePath[100]={0};
  17024. char buf[512];
  17025. int systemresult = 0;
  17026. //DEBUG_INFO("filename=%s\n",filename);
  17027. //DEBUG_INFO("url=%s\n",url);
  17028. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17029. if((access(FilePath,F_OK))!=-1)
  17030. {
  17031. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17032. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17033. system(rmFileCmd);
  17034. }
  17035. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17036. if(fp == NULL)
  17037. {
  17038. DEBUG_INFO("log is NULL\n");
  17039. return FALSE;
  17040. }
  17041. else
  17042. {
  17043. fprintf(fp, "%s\n", url);
  17044. fprintf(fp, "%s\n", filename);
  17045. fclose(fp);
  17046. }
  17047. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17048. if(phpFP == NULL)
  17049. {
  17050. DEBUG_INFO("PHP upload fail.\n");
  17051. return FALSE;
  17052. }
  17053. else
  17054. {
  17055. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17056. {
  17057. if(strstr(buf, "result") != NULL)
  17058. {
  17059. sscanf(buf, "result: %d", &systemresult);
  17060. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17061. }
  17062. }
  17063. pclose(phpFP);
  17064. }
  17065. if(systemresult != 1)
  17066. {
  17067. DEBUG_INFO("HTTP upload error!\n");
  17068. return FALSE;
  17069. }
  17070. return TRUE;
  17071. }
  17072. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17073. {
  17074. int result = FALSE;
  17075. char ftpbuf[200];
  17076. int systemresult;
  17077. /*
  17078. // Domaind name transfer to IP address
  17079. struct hostent* server;
  17080. char *IPbuffer;
  17081. server = gethostbyname(location);
  17082. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17083. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17084. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17085. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17086. systemresult = system(ftpbuf);
  17087. if(systemresult != 0)
  17088. {
  17089. DEBUG_INFO("ftpput error!\n");
  17090. }
  17091. else
  17092. {
  17093. result = TRUE;
  17094. DEBUG_INFO("ftpput OK!\n");
  17095. }
  17096. return result;
  17097. }
  17098. int GetOcppServerURL()
  17099. {
  17100. int result = FALSE;
  17101. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17102. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17103. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17104. struct yuarel url;
  17105. char urlStr[512];
  17106. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17107. {
  17108. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17109. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17110. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17111. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17112. if(yuarel_parse(&url, urlStr) != -1)
  17113. {
  17114. sprintf(OcppProtocol, "%s", url.scheme);
  17115. sprintf(OcppHost, "%s", url.host);
  17116. if(url.path == NULL)
  17117. OcppTempPath[0] = '\0';
  17118. else
  17119. {
  17120. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17121. {
  17122. sprintf(OcppTempPath, "%s/", url.path);
  17123. }
  17124. else
  17125. {
  17126. sprintf(OcppTempPath, "%s", url.path);
  17127. }
  17128. }
  17129. if(url.port == 0)
  17130. {
  17131. if(strcmp(OcppProtocol, "wss") == 0)
  17132. OcppPort = 443;
  17133. else
  17134. OcppPort = 80;
  17135. }
  17136. else
  17137. OcppPort = url.port;
  17138. result = TRUE;
  17139. }
  17140. }
  17141. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17142. {
  17143. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17144. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17145. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17146. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17147. if(yuarel_parse(&url, urlStr) != -1)
  17148. {
  17149. sprintf(OcppProtocol, "%s", url.scheme);
  17150. sprintf(OcppHost, "%s", url.host);
  17151. if(url.path == NULL)
  17152. OcppTempPath[0] = '\0';
  17153. else
  17154. sprintf(OcppTempPath, "%s", url.path);
  17155. if(url.port == 0)
  17156. {
  17157. if(strcmp(OcppProtocol, "wss") == 0)
  17158. OcppPort = 443;
  17159. else
  17160. OcppPort = 80;
  17161. }
  17162. else
  17163. OcppPort = url.port;
  17164. result = TRUE;
  17165. }
  17166. }
  17167. else
  17168. {
  17169. strcpy(OcppHost,"");
  17170. }
  17171. return result;
  17172. }
  17173. int GetOcppPath()
  17174. {
  17175. int result = FALSE;
  17176. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17177. {
  17178. if(OcppTempPath == NULL)
  17179. {
  17180. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17181. }
  17182. else
  17183. {
  17184. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17185. }
  17186. result = TRUE;
  17187. goto End;
  17188. }
  17189. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17190. {
  17191. if(OcppTempPath == NULL)
  17192. {
  17193. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17194. }
  17195. else
  17196. {
  17197. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17198. }
  17199. result = TRUE;
  17200. goto End;
  17201. }
  17202. else
  17203. {
  17204. strcpy(OcppPath,"");
  17205. }
  17206. End:
  17207. return result;
  17208. }
  17209. int GetOcppPort()
  17210. {
  17211. return OcppPort;
  17212. }
  17213. int GetOcppConnStatus(void)
  17214. {
  17215. return ShmOCPP16Data->OcppConnStatus;
  17216. }
  17217. void SetOcppConnStatus(uint8_t status)
  17218. {
  17219. ShmOCPP16Data->OcppConnStatus = status;
  17220. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17221. }
  17222. int GetHeartBeatWithNOResponse(void)
  17223. {
  17224. return HeartBeatWithNOResponse;
  17225. }
  17226. void SetHeartBeatWithNOResponse(void)
  17227. {
  17228. HeartBeatWithNOResponse = 0;
  17229. }
  17230. void GetStartTransactionIdTag(int gun_index)
  17231. {
  17232. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17233. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17234. }
  17235. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17236. {
  17237. char ch;
  17238. FILE *fptr1;
  17239. int temptransactionId;
  17240. char str[100]={0};
  17241. temptransactionId = 0;
  17242. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17243. {
  17244. DEBUG_INFO("IdTag is empty.\n");
  17245. return temptransactionId;
  17246. }
  17247. /*------ Read the file ----------------*/
  17248. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17249. if (!fptr1)
  17250. {
  17251. DEBUG_INFO("QueueTransactionId file open error.\n");
  17252. //printf(" File not found or unable to open the input file!!\n");
  17253. return temptransactionId;
  17254. }
  17255. ch=fgetc(fptr1);
  17256. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17257. rewind(fptr1);
  17258. if(ch!=EOF)
  17259. {
  17260. // printf("%c",ch);
  17261. while (fgets(str, 100, fptr1) != NULL)
  17262. {
  17263. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17264. if(str[0]=='\0')
  17265. {
  17266. break;
  17267. }
  17268. char *revbuf[8] = {0}; // Variable store string split
  17269. int num = 0;// Quantity after string split
  17270. DEBUG_INFO("Transaction queue data= %s\n", str);
  17271. splitstring(str,",",revbuf,&num); // String split
  17272. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17273. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17274. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17275. DEBUG_INFO("------------------------------\n");
  17276. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17277. {
  17278. if(isStopTransaction)
  17279. {
  17280. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17281. {
  17282. temptransactionId = atoi(revbuf[2]);
  17283. //break;
  17284. }
  17285. }
  17286. else
  17287. {
  17288. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17289. {
  17290. temptransactionId = atoi(revbuf[2]);
  17291. //break;
  17292. }
  17293. }
  17294. }
  17295. }
  17296. }
  17297. else
  17298. DEBUG_INFO("EOF\n");
  17299. fclose(fptr1);
  17300. /*------- End of reading ---------------*/
  17301. return temptransactionId;
  17302. }
  17303. void SetTransactionIdZero(int transactionId)
  17304. {
  17305. char ch;
  17306. FILE *fptr1, *fptr2;
  17307. int temptransactionId = 0;
  17308. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17309. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17310. if (!fptr1)
  17311. {
  17312. //printf(" File not found or unable to open the input file!!\n");
  17313. return ;
  17314. }
  17315. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17316. if (!fptr2)
  17317. {
  17318. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17319. fclose(fptr1);
  17320. return ;
  17321. }
  17322. ch=fgetc(fptr1);
  17323. rewind(fptr1);
  17324. if(ch!=EOF)
  17325. {
  17326. // copy all contents to the temporary file except the specific line
  17327. while (fgets(str, 100, fptr1) != NULL)
  17328. {
  17329. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17330. if(str[0]=='\0')
  17331. {
  17332. break;
  17333. }
  17334. char *revbuf[8] = {0};
  17335. int num = 0;
  17336. strcpy(strtemp, str);
  17337. splitstring(str,",",revbuf,&num);
  17338. if(revbuf[2][0] != '\0')
  17339. {
  17340. temptransactionId = atoi(revbuf[2]);
  17341. if(transactionId != temptransactionId)
  17342. {
  17343. fprintf(fptr2, "%s\n", strtemp);
  17344. }
  17345. }
  17346. }
  17347. }
  17348. fclose(fptr1);
  17349. fclose(fptr2);
  17350. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17351. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17352. /*------ Read the file ----------------*/
  17353. }
  17354. int InternetDisconnect(void)
  17355. {
  17356. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17357. }
  17358. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17359. void storeTempStopTransaction(int gun_index)
  17360. {
  17361. char guid[37]={0};
  17362. int tempIndex = 0;
  17363. char TempStopTransaction[256];
  17364. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17365. DEBUG_INFO("storeTempStopTransaction...\n");
  17366. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17367. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17368. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17369. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17371. {
  17372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17373. {
  17374. tempIndex = ((gun_index==2) ? 1: 0);
  17375. }
  17376. else
  17377. {
  17378. tempIndex = gun_index;
  17379. }
  17380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17381. {
  17382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17383. {
  17384. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17385. }
  17386. }// END OF CHAdeMO_QUANTITY
  17387. }
  17388. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17389. {
  17390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17391. {
  17392. tempIndex = ((gun_index==2) ? 1: 0);
  17393. }
  17394. else
  17395. {
  17396. tempIndex = gun_index;
  17397. }
  17398. for (int index = 0; index < CCS_QUANTITY; index++)
  17399. {
  17400. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17401. {
  17402. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17403. }
  17404. }// END OF CCS_QUANTITY
  17405. }
  17406. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17407. {
  17408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17409. {
  17410. tempIndex = ((gun_index==2) ? 1: 0);
  17411. }
  17412. else
  17413. {
  17414. tempIndex = gun_index;
  17415. }
  17416. for (int index = 0; index < GB_QUANTITY; index++)
  17417. {
  17418. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17419. {
  17420. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17421. }
  17422. }// END OF GB_QUANTITY
  17423. }
  17424. else if(gunType[gun_index] == GUN_TYPE_DO)
  17425. {
  17426. tempIndex = gun_index;
  17427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17428. {
  17429. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17430. {
  17431. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17432. }
  17433. }
  17434. }
  17435. else
  17436. {
  17437. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17438. {
  17439. tempIndex = 2;
  17440. }
  17441. else
  17442. {
  17443. tempIndex = gun_index;
  17444. }
  17445. for (int index = 0; index < AC_QUANTITY; index++)
  17446. {
  17447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17448. {
  17449. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17450. }
  17451. }// END OF AC_QUANTITY
  17452. }
  17453. //Stop Transaction Time
  17454. struct timeval tmnow;
  17455. struct tm *tm;
  17456. char buf[28];//, usec_buf[6];
  17457. gettimeofday(&tmnow, NULL);
  17458. time_t t;
  17459. t = time(NULL);
  17460. /*UTC time and date*/
  17461. tm = gmtime(&t);
  17462. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17464. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17466. random_uuid(guid);
  17467. /***********************************transactionData******************************************************/
  17468. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17470. //=================================
  17471. //1. Transaction_Begin
  17472. //=================================
  17473. //============================== Energy.Active.Import.Interval ===========================================
  17474. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17475. {
  17476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17479. 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*/]);
  17480. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17481. 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))
  17482. {
  17483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17484. }
  17485. else
  17486. {
  17487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17488. }
  17489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17491. }
  17492. //=================================
  17493. //2. Transaction_End
  17494. //=================================
  17495. //2.1====================================== Current.Import L1 ==============================================
  17496. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17497. {
  17498. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17499. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17500. {
  17501. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17502. {
  17503. tempIndex = ((gun_index==2) ? 1: 0);
  17504. }
  17505. else
  17506. {
  17507. tempIndex = gun_index;
  17508. }
  17509. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17510. {
  17511. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17512. {
  17513. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17514. }
  17515. }// End of for CHAdeMO_QUANTITY
  17516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17517. }
  17518. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17519. {
  17520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17521. {
  17522. tempIndex = ((gun_index==2) ? 1: 0);
  17523. }
  17524. else
  17525. {
  17526. tempIndex = gun_index;
  17527. }
  17528. for (int index = 0; index < CCS_QUANTITY; index++)
  17529. {
  17530. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17531. {
  17532. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17533. }
  17534. }// End of for CCS_QUANTITY
  17535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17536. }
  17537. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17538. {
  17539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17540. {
  17541. tempIndex = ((gun_index==2) ? 1: 0);
  17542. }
  17543. else
  17544. {
  17545. tempIndex = gun_index;
  17546. }
  17547. for (int index = 0; index < GB_QUANTITY; index++)
  17548. {
  17549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17550. {
  17551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17552. }
  17553. }// End of for GB_QUANTITY
  17554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17555. }
  17556. else if(gunType[gun_index] == GUN_TYPE_DO)
  17557. {
  17558. tempIndex = gun_index;
  17559. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17560. {
  17561. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17562. {
  17563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17564. }
  17565. }
  17566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17567. }
  17568. else
  17569. {
  17570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17571. {
  17572. tempIndex = 2;
  17573. }
  17574. else
  17575. {
  17576. tempIndex = gun_index;
  17577. }
  17578. for (int index = 0; index < AC_QUANTITY; index++)
  17579. {
  17580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17581. {
  17582. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17583. }
  17584. }// End of for AC_QUANTITY
  17585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17586. }
  17587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17590. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17593. }
  17594. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17595. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17596. {
  17597. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17598. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17599. {
  17600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17601. {
  17602. tempIndex = ((gun_index==2) ? 1: 0);
  17603. }
  17604. else
  17605. {
  17606. tempIndex = gun_index;
  17607. }
  17608. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17609. {
  17610. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17611. {
  17612. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17613. }
  17614. }// END OF CHAdeMO_QUANTITY
  17615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17616. }
  17617. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17618. {
  17619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17620. {
  17621. tempIndex = ((gun_index==2) ? 1: 0);
  17622. }
  17623. else
  17624. {
  17625. tempIndex = gun_index;
  17626. }
  17627. for (int index = 0; index < CCS_QUANTITY; index++)
  17628. {
  17629. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17630. {
  17631. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17632. }
  17633. }// END OF CCS_QUANTITY
  17634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17635. }
  17636. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17637. {
  17638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17639. {
  17640. tempIndex = ((gun_index==2) ? 1: 0);
  17641. }
  17642. else
  17643. {
  17644. tempIndex = gun_index;
  17645. }
  17646. for (int index = 0; index < GB_QUANTITY; index++)
  17647. {
  17648. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17649. {
  17650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17651. }
  17652. }// END OF GB_QUANTITY
  17653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17654. }
  17655. else if(gunType[gun_index] == GUN_TYPE_DO)
  17656. {
  17657. tempIndex = gun_index;
  17658. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17659. {
  17660. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17661. {
  17662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17663. }
  17664. }
  17665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17666. }
  17667. else
  17668. {
  17669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17670. {
  17671. tempIndex = 2;
  17672. }
  17673. else
  17674. {
  17675. tempIndex = gun_index;
  17676. }
  17677. for (int index = 0; index < AC_QUANTITY; index++)
  17678. {
  17679. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17680. {
  17681. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17682. }
  17683. }// END OF AC_QUANTITY
  17684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17685. }
  17686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17689. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17692. }
  17693. //2.3====================================== Power.Active.Import =========================================
  17694. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17695. {
  17696. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17697. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17698. {
  17699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17700. {
  17701. tempIndex = ((gun_index==2) ? 1: 0);
  17702. }
  17703. else
  17704. {
  17705. tempIndex = gun_index;
  17706. }
  17707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17708. {
  17709. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17710. {
  17711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17712. }
  17713. } // End for CHAdeMO_QUANTITY
  17714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17715. }
  17716. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17717. {
  17718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17719. {
  17720. tempIndex = ((gun_index==2) ? 1: 0);
  17721. }
  17722. else
  17723. {
  17724. tempIndex = gun_index;
  17725. }
  17726. for (int index = 0; index < CCS_QUANTITY; index++)
  17727. {
  17728. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17729. {
  17730. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17731. }
  17732. } // END for CCS_QUANTITY
  17733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17734. }
  17735. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17736. {
  17737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17738. {
  17739. tempIndex = ((gun_index==2) ? 1: 0);
  17740. }
  17741. else
  17742. {
  17743. tempIndex = gun_index;
  17744. }
  17745. for (int index = 0; index < GB_QUANTITY; index++)
  17746. {
  17747. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17748. {
  17749. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17750. }
  17751. }// END for GB_QUANTITY
  17752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17753. }
  17754. else if(gunType[gun_index] == GUN_TYPE_DO)
  17755. {
  17756. tempIndex = gun_index;
  17757. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17758. {
  17759. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17760. {
  17761. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17762. }
  17763. }
  17764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17765. }
  17766. else
  17767. {
  17768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17769. {
  17770. tempIndex = 2;
  17771. }
  17772. else
  17773. {
  17774. tempIndex = gun_index;
  17775. }
  17776. for (int index = 0; index < AC_QUANTITY; index++)
  17777. {
  17778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17779. {
  17780. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17781. }
  17782. } // END for AC_QUANTITY
  17783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17784. }
  17785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17788. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17791. }
  17792. //2.4====================================== Voltage L1 ====================================================
  17793. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17794. {
  17795. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17796. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17797. {
  17798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17799. {
  17800. tempIndex = ((gun_index==2) ? 1: 0);
  17801. }
  17802. else
  17803. {
  17804. tempIndex = gun_index;
  17805. }
  17806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17807. {
  17808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17809. {
  17810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17811. }
  17812. } // END OF FOR CHAdeMO_QUANTITY
  17813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17814. }
  17815. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17816. {
  17817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17818. {
  17819. tempIndex = ((gun_index==2) ? 1: 0);
  17820. }
  17821. else
  17822. {
  17823. tempIndex = gun_index;
  17824. }
  17825. for (int index = 0; index < CCS_QUANTITY; index++)
  17826. {
  17827. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17828. {
  17829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17830. }
  17831. } // END OF FOR CCS_QUANTITY
  17832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17833. }
  17834. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17835. {
  17836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17837. {
  17838. tempIndex = ((gun_index==2) ? 1: 0);
  17839. }
  17840. else
  17841. {
  17842. tempIndex = gun_index;
  17843. }
  17844. for (int index = 0; index < GB_QUANTITY; index++)
  17845. {
  17846. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17847. {
  17848. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17849. }
  17850. } // END OF FOR GB_QUANTITY
  17851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17852. }
  17853. else if(gunType[gun_index] == GUN_TYPE_DO)
  17854. {
  17855. tempIndex = gun_index;
  17856. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17857. {
  17858. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17859. {
  17860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17861. }
  17862. }
  17863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17864. }
  17865. else
  17866. {
  17867. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17868. {
  17869. tempIndex = 2;
  17870. }
  17871. else
  17872. {
  17873. tempIndex = gun_index;
  17874. }
  17875. for (int index = 0; index < AC_QUANTITY; index++)
  17876. {
  17877. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17878. {
  17879. 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
  17880. }
  17881. } // END OF FOR AC_QUANTITY
  17882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17883. }
  17884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17887. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17890. }
  17891. //2.5============================================== End SoC =========================================================
  17892. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17893. {
  17894. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17895. 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))
  17896. {
  17897. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17898. {
  17899. tempIndex = ((gun_index==2) ? 1: 0);
  17900. }
  17901. else
  17902. {
  17903. tempIndex = gun_index;
  17904. }
  17905. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17906. {
  17907. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17908. {
  17909. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17910. {
  17911. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17912. }
  17913. }
  17914. }
  17915. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17916. {
  17917. for (int index = 0; index < CCS_QUANTITY; index++)
  17918. {
  17919. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17920. {
  17921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17922. }
  17923. }
  17924. }
  17925. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17926. {
  17927. for (int index = 0; index < GB_QUANTITY; index++)
  17928. {
  17929. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17930. {
  17931. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17932. }
  17933. }
  17934. }
  17935. else if(gunType[gun_index] == GUN_TYPE_DO)
  17936. {
  17937. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17938. {
  17939. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17940. {
  17941. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17942. }
  17943. }
  17944. }
  17945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17951. } // END FOR DC CASE
  17952. }
  17953. //2.6====================================== Current.Import L2 ==============================================
  17954. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17955. {
  17956. // AC 3 phase L2 current
  17957. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17958. {
  17959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17960. {
  17961. tempIndex = 2;
  17962. }
  17963. else
  17964. {
  17965. tempIndex = gun_index;
  17966. }
  17967. for (int index = 0; index < AC_QUANTITY; index++)
  17968. {
  17969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17970. {
  17971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17972. }
  17973. }// End of for AC_QUANTITY
  17974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17975. }
  17976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17981. }
  17982. //2.7====================================== Current.Import L3 ==============================================
  17983. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17984. {
  17985. // AC 3 phase L3 current
  17986. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17987. {
  17988. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17989. {
  17990. tempIndex = 2;
  17991. }
  17992. else
  17993. {
  17994. tempIndex = gun_index;
  17995. }
  17996. for (int index = 0; index < AC_QUANTITY; index++)
  17997. {
  17998. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17999. {
  18000. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18001. }
  18002. }// End of for AC_QUANTITY
  18003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18004. }
  18005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18010. }
  18011. //2.9====================================== Voltage L2 ====================================================
  18012. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18013. {
  18014. // AC 3 phase L2 volatge
  18015. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18016. {
  18017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18018. {
  18019. tempIndex = 2;
  18020. }
  18021. else
  18022. {
  18023. tempIndex = gun_index;
  18024. }
  18025. for (int index = 0; index < AC_QUANTITY; index++)
  18026. {
  18027. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18028. {
  18029. 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
  18030. }
  18031. } // END OF FOR AC_QUANTITY
  18032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18033. }
  18034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18039. }
  18040. //2.10====================================== Voltage L3 ====================================================
  18041. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18042. {
  18043. // AC 3 phase L3 volatge
  18044. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18045. {
  18046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18047. {
  18048. tempIndex = 2;
  18049. }
  18050. else
  18051. {
  18052. tempIndex = gun_index;
  18053. }
  18054. for (int index = 0; index < AC_QUANTITY; index++)
  18055. {
  18056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18057. {
  18058. 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
  18059. }
  18060. } // END OF FOR AC_QUANTITY
  18061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18062. }
  18063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18068. }
  18069. //====================== Start SoC ================================
  18070. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18071. {
  18072. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18073. 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))
  18074. {
  18075. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18076. {
  18077. tempIndex = ((gun_index==2) ? 1: 0);
  18078. }
  18079. else
  18080. {
  18081. tempIndex = gun_index;
  18082. }
  18083. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18084. {
  18085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18086. {
  18087. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18088. {
  18089. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18090. }
  18091. }
  18092. }
  18093. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18094. {
  18095. for (int index = 0; index < CCS_QUANTITY; index++)
  18096. {
  18097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18098. {
  18099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18100. }
  18101. }
  18102. }
  18103. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18104. {
  18105. for (int index = 0; index < GB_QUANTITY; index++)
  18106. {
  18107. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18108. {
  18109. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18110. }
  18111. }
  18112. }
  18113. else if(gunType[gun_index] == GUN_TYPE_DO)
  18114. {
  18115. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18116. {
  18117. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18118. {
  18119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18120. }
  18121. }
  18122. }
  18123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18129. } // END FOR DC CASE
  18130. }
  18131. //======================================== Message create ==============================================
  18132. json_object *StopTransaction = json_object_new_object();
  18133. json_object *transactionDatas = json_object_new_array();
  18134. json_object *sampledValues = json_object_new_array();
  18135. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18136. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18137. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18138. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18139. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18140. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18141. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18142. {
  18143. json_object *transactionData = json_object_new_object();
  18144. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18145. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18146. {
  18147. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18148. {
  18149. json_object *sampledValue = json_object_new_object();
  18150. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18151. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18152. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18153. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18154. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18155. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18156. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18157. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18158. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18159. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18160. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18161. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18162. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18163. json_object_array_add(sampledValues, sampledValue);
  18164. }
  18165. }
  18166. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18167. json_object_array_add(transactionDatas, transactionData);
  18168. }
  18169. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18170. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18171. ,MESSAGE_TYPE_CALL
  18172. ,guid
  18173. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18174. json_object_put(StopTransaction);
  18175. // Check File "TempStopTransaction" Exist
  18176. if((access(TempStopTransaction,F_OK))!=-1)
  18177. {
  18178. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18179. fclose(fopen(TempStopTransaction, "w"));
  18180. }
  18181. else
  18182. {
  18183. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18184. FILE *log = fopen(TempStopTransaction, "w+");
  18185. if(log == NULL)
  18186. {
  18187. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18188. return ;
  18189. }
  18190. else
  18191. {
  18192. fclose(log);
  18193. }
  18194. }
  18195. //Add TempStopTransaction | Update TempStopTransaction
  18196. // open file for writing
  18197. FILE *outfile;
  18198. outfile = fopen (TempStopTransaction, "a");
  18199. //DEBUG_INFO("data = %s\n", queuedata);
  18200. fputs(queuedata, outfile);
  18201. fputs("\n", outfile);
  18202. fclose (outfile);
  18203. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18204. OCPP_updatePeriodEnergy(gun_index);
  18205. }
  18206. void checkTempStopTransaction(int gun_index)
  18207. {
  18208. FILE *fptr1;
  18209. char ch;
  18210. char str[QUEUE_MESSAGE_LENGTH]={0};
  18211. char guid[37]={0};
  18212. char tempdata[65]={0};
  18213. char connectorStr[2]={0};
  18214. char TempStopTransaction[256];
  18215. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18216. fptr1 = fopen(TempStopTransaction, "r");
  18217. //TempStopTransaction格式: 槍號,StopTransaction封包
  18218. if (!fptr1)
  18219. {
  18220. //printf(" File not found or unable to open the input file!!\n");
  18221. return ;
  18222. }
  18223. ch=fgetc(fptr1);
  18224. //printf(" Now the content of the file %s is : \n",fname);
  18225. rewind(fptr1);
  18226. if(ch!=EOF)
  18227. {
  18228. // copy all contents to the temporary file except the specific line
  18229. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18230. {
  18231. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18232. if(str[0]=='\0')
  18233. {
  18234. break;
  18235. }
  18236. //TempStopTransaction格式: 槍號,StopTransaction封包
  18237. strncpy(connectorStr, str, 1);
  18238. if(atoi(connectorStr) != (gun_index+1))
  18239. {
  18240. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18241. fclose(fptr1);
  18242. return ;
  18243. }
  18244. //random_uuid(guid);
  18245. strncpy(guid, str+6, 36); //copy guid
  18246. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18247. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18248. {
  18249. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18250. }
  18251. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18252. OCPP_insert_transaction_msg(NO, str);
  18253. memset(str,0,ARRAY_SIZE(str));
  18254. }
  18255. }
  18256. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18257. fclose(fptr1);
  18258. remove(TempStopTransaction); // remove the original file
  18259. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18260. }
  18261. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18262. {
  18263. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18264. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18265. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18266. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18267. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18268. }
  18269. int GetWebSocketPingInterval(void)
  18270. {
  18271. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18272. }
  18273. int GetServerSign(void)
  18274. {
  18275. return server_sign;
  18276. }
  18277. uint8_t GetOcppSecurityProfile()
  18278. {
  18279. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18280. }
  18281. void GetOcppChargerBoxId(uint8_t *data)
  18282. {
  18283. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18284. }
  18285. void GetOcppSecurityPassword(uint8_t *data)
  18286. {
  18287. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18288. }
  18289. void SetOcppVersion(uint8_t *version)
  18290. {
  18291. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18292. DEBUG_INFO("ocpp version: %s\n", version);
  18293. if(strstr((char*)version, "ocpp1.6") != NULL)
  18294. {
  18295. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18296. }
  18297. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18298. {
  18299. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18300. system("pkill OcppBackend");
  18301. }
  18302. }
  18303. void SetServerSign(int value)
  18304. {
  18305. server_sign = value;
  18306. }
  18307. int GetBootNotificationInterval(void)
  18308. {
  18309. return BootNotificationInterval;
  18310. }
  18311. int GetInternetConn(void)
  18312. {
  18313. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18314. }
  18315. int GetBackendConnectionTimeout(void)
  18316. {
  18317. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18318. }
  18319. int isConnectorInitMode(int gun_index)
  18320. {
  18321. int tempIndex = 0;
  18322. int result = TRUE;
  18323. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18324. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18325. {
  18326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18327. {
  18328. tempIndex = ((gun_index==2) ? 1: 0);
  18329. }
  18330. else
  18331. {
  18332. tempIndex = gun_index;
  18333. }
  18334. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18335. {
  18336. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18337. {
  18338. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18339. } //end of the same index
  18340. }//end of for CHAdeMO_QUANTITY
  18341. }
  18342. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18343. {
  18344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18345. {
  18346. tempIndex = ((gun_index==2) ? 1: 0);
  18347. }
  18348. else
  18349. {
  18350. tempIndex = gun_index;
  18351. }
  18352. for (int index = 0; index < CCS_QUANTITY; index++)
  18353. {
  18354. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18355. {
  18356. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18357. } //end of the same index
  18358. } // end of for CCS_QUANTITY
  18359. }
  18360. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18361. {
  18362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18363. {
  18364. tempIndex = ((gun_index==2) ? 1: 0);
  18365. }
  18366. else
  18367. {
  18368. tempIndex = gun_index;
  18369. }
  18370. for (int index = 0; index < GB_QUANTITY; index++)
  18371. {
  18372. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18373. {
  18374. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18375. } //end of the same index
  18376. } // end of for GB_QUANTITY
  18377. }
  18378. else if(gunType[gun_index] == GUN_TYPE_DO)
  18379. {
  18380. tempIndex = gun_index;
  18381. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18382. {
  18383. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18384. {
  18385. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18386. } //end of the same index
  18387. }
  18388. }
  18389. else
  18390. {
  18391. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18392. {
  18393. tempIndex = 2;
  18394. }
  18395. else
  18396. {
  18397. tempIndex = gun_index;
  18398. }
  18399. for (int index = 0; index < AC_QUANTITY; index++)
  18400. {
  18401. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18402. {
  18403. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18404. }//end of the same index
  18405. }//end of for AC_QUANTITY
  18406. }
  18407. return result;
  18408. }
  18409. void refreshProcDogTimer()
  18410. {
  18411. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18412. }
  18413. void InitialSystemValue(void)
  18414. {
  18415. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18416. locallistVersion=0;
  18417. BootNotificationInterval = 0;
  18418. authorizeRetryTimes = 0;
  18419. GunStatusInterval = 10;
  18420. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18421. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18422. //Hear Beat
  18423. HeartBeatWithNOResponse = 0;
  18424. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18425. FirstHeartBeat = 0;
  18426. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18427. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18428. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18429. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18430. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18431. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18432. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18433. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18434. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18435. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18436. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18437. //Status && ConnectorPlugIn Setting
  18438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18439. {
  18440. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18441. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18442. }
  18443. for (int index = 0; index < CCS_QUANTITY; index++)
  18444. {
  18445. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18446. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18447. }
  18448. for (int index = 0; index < GB_QUANTITY; index++)
  18449. {
  18450. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18451. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18452. }
  18453. for (int index = 0; index < AC_QUANTITY; index++)
  18454. {
  18455. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18456. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18457. }
  18458. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18459. {
  18460. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18461. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18462. }
  18463. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18464. {
  18465. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18466. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18467. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18468. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18469. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18470. }
  18471. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18472. refreshStartTimer(&clientTime.Heartbeat);
  18473. sleep(1);
  18474. }
  18475. void LWS_Send(char *str)
  18476. {
  18477. //=====================================================
  18478. // Check InternetConn 0: disconnected, 1: connected
  18479. //====================================================
  18480. if(GetOcppConnStatus() == 0)
  18481. {
  18482. DEBUG_INFO("offline now !!!\n");
  18483. return;
  18484. }
  18485. // Only disable isWebsocketSendable operation initiated by charger
  18486. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18487. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18488. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18489. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18490. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18491. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18492. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18493. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18494. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18495. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18496. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18497. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18498. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18499. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18500. {
  18501. isWebsocketSendable = 0;
  18502. }
  18503. pthread_mutex_lock(&lock_send);
  18504. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18505. sprintf((char *)SendBuffer, "%s", str);
  18506. SendBufLen = strlen(str);
  18507. pthread_mutex_unlock(&lock_send);
  18508. lws_callback_on_writable(wsi_client);
  18509. //lws_service(context, 0);
  18510. //sleep(1);
  18511. }
  18512. void LWS_SendNow(char *str)
  18513. {
  18514. //=====================================================
  18515. // Check InternetConn 0: disconnected, 1: connected
  18516. //====================================================
  18517. if(GetOcppConnStatus() == 0)
  18518. {
  18519. DEBUG_INFO("offline now !!!\n");
  18520. return;
  18521. }
  18522. // Only disable isWebsocketSendable operation initiated by charger
  18523. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18524. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18525. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18526. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18527. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18528. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18529. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18530. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18531. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18532. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18533. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18534. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18535. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18536. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18537. {
  18538. isWebsocketSendable = 0;
  18539. }
  18540. pthread_mutex_lock(&lock_send);
  18541. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18542. sprintf((char *)SendBuffer, "%s", str);
  18543. SendBufLen = strlen(str);
  18544. pthread_mutex_unlock(&lock_send);
  18545. lws_callback_on_writable(wsi_client);
  18546. lws_service(context, 0);
  18547. //sleep(1);
  18548. }