MessageHandler.c 929 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204
  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_DisplayLcdPage") != 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, "Page_Index") != NULL)
  9454. {
  9455. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9456. }
  9457. if(json_object_object_get(data, "Duration") != NULL)
  9458. {
  9459. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9460. }
  9461. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9462. }
  9463. else
  9464. {
  9465. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9466. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9467. }
  9468. json_object_put(data);
  9469. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9470. json_object_put(response);
  9471. }
  9472. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9473. {
  9474. json_object *data;
  9475. data = json_tokener_parse(tempdata);
  9476. if(!is_error(data))
  9477. {
  9478. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9479. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9480. {
  9481. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9482. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9483. else
  9484. {
  9485. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9486. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9487. }
  9488. }
  9489. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9490. {
  9491. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9492. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9493. else
  9494. {
  9495. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9496. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9497. }
  9498. }
  9499. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9500. {
  9501. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9502. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9503. else
  9504. {
  9505. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9506. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9507. }
  9508. }
  9509. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9510. {
  9511. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9512. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9513. else
  9514. {
  9515. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9516. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9517. }
  9518. }
  9519. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9520. {
  9521. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9522. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9523. else
  9524. {
  9525. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9526. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9527. }
  9528. }
  9529. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9530. {
  9531. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9532. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9533. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9534. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9535. else
  9536. {
  9537. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9538. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9539. }
  9540. }
  9541. if(json_object_object_get(data, "isAuthentication") != NULL)
  9542. {
  9543. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9544. {
  9545. case 0:
  9546. case 1:
  9547. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9548. break;
  9549. default:
  9550. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9551. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9552. break;
  9553. }
  9554. }
  9555. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9556. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9557. }
  9558. else
  9559. {
  9560. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9561. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9562. }
  9563. json_object_put(data);
  9564. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9565. json_object_put(response);
  9566. }
  9567. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9568. {
  9569. json_object *data;
  9570. data = json_tokener_parse(tempdata);
  9571. if(!is_error(data))
  9572. {
  9573. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9574. {
  9575. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9576. {
  9577. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9578. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9579. }
  9580. else
  9581. {
  9582. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9583. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9584. }
  9585. }
  9586. else
  9587. {
  9588. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9589. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9590. }
  9591. }
  9592. else
  9593. {
  9594. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9595. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9596. }
  9597. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9598. json_object_put(response);
  9599. }
  9600. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9601. {
  9602. json_object *data;
  9603. data = json_tokener_parse(tempdata);
  9604. if(!is_error(data))
  9605. {
  9606. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9607. if(json_object_object_get(data, "stationName") != NULL)
  9608. {
  9609. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9610. }
  9611. else
  9612. {
  9613. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9614. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9615. }
  9616. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9617. {
  9618. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9619. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9620. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9621. }
  9622. }
  9623. else
  9624. {
  9625. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9626. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9627. }
  9628. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9629. json_object_put(response);
  9630. }
  9631. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9632. {
  9633. json_object *data;
  9634. data = json_tokener_parse(tempdata);
  9635. if(!is_error(data))
  9636. {
  9637. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9638. if(json_object_object_get(data, "weatherId") != NULL)
  9639. {
  9640. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9641. }
  9642. else
  9643. {
  9644. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9645. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9646. }
  9647. if(json_object_object_get(data, "Temperature") != NULL)
  9648. {
  9649. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9650. }
  9651. else
  9652. {
  9653. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9654. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9655. }
  9656. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9657. {
  9658. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9659. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9660. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9661. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9662. );
  9663. }
  9664. }
  9665. else
  9666. {
  9667. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9668. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9669. }
  9670. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9671. json_object_put(response);
  9672. }
  9673. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9674. {
  9675. json_object *data;
  9676. data = json_tokener_parse(tempdata);
  9677. if(!is_error(data))
  9678. {
  9679. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9680. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9681. {
  9682. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9683. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9684. }
  9685. else
  9686. {
  9687. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9688. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9689. }
  9690. }
  9691. else
  9692. {
  9693. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9694. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9695. }
  9696. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9697. json_object_put(response);
  9698. }
  9699. else
  9700. {
  9701. // Can not find valid message id
  9702. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9703. }
  9704. }
  9705. else
  9706. {
  9707. // Payload is null
  9708. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9709. }
  9710. LWS_Send(message);
  9711. return result;
  9712. }
  9713. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9714. {
  9715. mtrace();
  9716. int result = FAIL;
  9717. int connectorIdInt, durationInt;
  9718. char chargingRateUnitStr[4]={0};
  9719. char comfirmstr[20];
  9720. int confirmPeriods = 0;
  9721. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9722. json_object *GetCompositeSchedule;
  9723. GetCompositeSchedule = json_tokener_parse(payload);
  9724. if(!is_error(GetCompositeSchedule))
  9725. {
  9726. // Required data
  9727. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9728. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9729. else
  9730. connectorIdInt = -1;
  9731. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9732. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9733. else
  9734. durationInt = 86400;
  9735. // Optional data
  9736. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9737. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9738. }
  9739. json_object_put(GetCompositeSchedule);
  9740. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9741. if((connectorIdInt == 0) ||
  9742. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9743. {
  9744. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9745. struct StructChargingProfile tmpProfile[1];
  9746. if(strstr(chargingRateUnitStr, "W") != NULL)
  9747. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9748. else
  9749. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9750. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9751. {
  9752. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9753. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9754. }
  9755. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9756. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9757. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9758. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9759. {
  9760. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9761. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9762. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9763. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9764. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9765. {
  9766. confirmPeriods = idx;
  9767. break;
  9768. }
  9769. }
  9770. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9771. {
  9772. confirmPeriods += 1;
  9773. }
  9774. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9775. }
  9776. else
  9777. {
  9778. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9779. }
  9780. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9781. return result;
  9782. }
  9783. int handleGetConfigurationRequest(char *uuid, char *payload)
  9784. {
  9785. mtrace();
  9786. int result = FAIL;
  9787. int MaxKeySupported = 0;
  9788. int n_keys = 0;
  9789. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9790. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9791. json_object *GetConfiguration;
  9792. GetConfiguration = json_tokener_parse(payload);
  9793. if(!is_error(GetConfiguration))
  9794. {
  9795. // Optional data
  9796. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9797. {
  9798. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9799. {
  9800. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9801. n_keys = idx + 1;
  9802. }
  9803. }
  9804. }
  9805. json_object_put(GetConfiguration);
  9806. UnknownKeynum = 0;
  9807. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9808. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9809. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9810. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9811. if(n_keys != 0)
  9812. {
  9813. for(int i=0;i<n_keys;i++)
  9814. {
  9815. getKeyValue(requestKey[i]);
  9816. }
  9817. }
  9818. else
  9819. {
  9820. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9821. getKeyValue("");
  9822. }
  9823. processUnkownKey();
  9824. sendGetConfigurationConfirmation(uuid);
  9825. return result;
  9826. }
  9827. static char fnamePlusPath[100]={0};
  9828. static char fnamePWithNoPath[60]={0};
  9829. void checkUploadLog(void)
  9830. {
  9831. FILE *fp;
  9832. /* Open the command for reading. */
  9833. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9834. if (fp == NULL) {
  9835. DEBUG_WARN("Failed to run command\n" );
  9836. exit(1);
  9837. }
  9838. int ftppathlen = 0;
  9839. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9840. int i = 0;
  9841. /* Read the output a line at a time - output it. */
  9842. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9843. if(i==0)
  9844. {
  9845. ftppathlen = strlen(fnamePlusPath);
  9846. DEBUG_INFO("%s\n", fnamePlusPath);
  9847. fnamePlusPath[ftppathlen]='\0';
  9848. break;
  9849. }
  9850. i= i+1;
  9851. }
  9852. /* close */
  9853. pclose(fp);
  9854. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9855. {
  9856. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9857. {
  9858. fnamePlusPath[k]='\0';
  9859. }
  9860. }
  9861. i=1;
  9862. //char fname[60]={0};
  9863. while(i < ftppathlen)
  9864. {
  9865. int len=ftppathlen-i;
  9866. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9867. {
  9868. DEBUG_INFO("compare '/' all right\n");
  9869. break;
  9870. }
  9871. i=i+1;
  9872. }
  9873. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9874. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9875. fnamePWithNoPath[i+1] = '\0';
  9876. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9877. {
  9878. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9879. {
  9880. fnamePWithNoPath[j]='\0';
  9881. }
  9882. }
  9883. FILE* fp1 = fopen(fnamePlusPath, "r");
  9884. if (fp1)
  9885. {
  9886. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9887. // file exists
  9888. fclose(fp1);
  9889. }
  9890. else
  9891. {
  9892. // file doesn't exist
  9893. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9894. }
  9895. }
  9896. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9897. {
  9898. mtrace();
  9899. int result = FAIL;
  9900. time_t CurrentTime;
  9901. struct tm *tm;
  9902. pthread_t th_Status;
  9903. CurrentTime = time(NULL);
  9904. tm = localtime(&CurrentTime);
  9905. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9906. 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);
  9907. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9908. if(!interLock.isGetDiagnosticGoing)
  9909. {
  9910. interLock.isGetDiagnosticGoing = 1;
  9911. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9912. sleep(1);
  9913. }
  9914. else
  9915. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9916. return result;
  9917. }
  9918. void* GetDiagnosticsProcess(void* data)
  9919. {
  9920. pthread_detach(pthread_self());
  9921. mtrace();
  9922. int retriesInt=0, retryIntervalInt=0;
  9923. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9924. 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};
  9925. int port=0;
  9926. int isSuccess = FALSE;
  9927. char cmdBuf[2048];
  9928. struct tm *tmNow;
  9929. time_t CurrentTime;
  9930. struct tm tmStart;
  9931. struct tm tmStop;
  9932. CurrentTime = time(NULL);
  9933. tmNow=localtime(&CurrentTime);
  9934. uint16_t targetYear, targetMonth;
  9935. json_object *GetDiagnostics;
  9936. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9937. GetDiagnostics = json_tokener_parse(data);
  9938. if(!is_error(GetDiagnostics))
  9939. {
  9940. // Required data
  9941. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9942. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9943. // Optional data
  9944. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9945. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9946. else
  9947. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9948. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9949. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9950. else
  9951. retryIntervalInt = 30;
  9952. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9953. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9954. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9955. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9956. }
  9957. json_object_put(GetDiagnostics);
  9958. // Pack log to compress file
  9959. 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) &&
  9960. (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))
  9961. {
  9962. // Pack system log
  9963. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9964. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9965. targetYear = tmStart.tm_year;
  9966. targetMonth = tmStart.tm_mon;
  9967. do
  9968. {
  9969. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9970. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9971. if(targetMonth+1>=13)
  9972. {
  9973. targetYear += 1;
  9974. targetMonth = 1;
  9975. }
  9976. else
  9977. {
  9978. targetMonth += 1;
  9979. }
  9980. }while((targetYear < (tmNow->tm_year+1900)) ||
  9981. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9982. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9983. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9984. system(cmdBuf);
  9985. // Pack charging & event log
  9986. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9987. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9988. targetYear = tmStart.tm_year;
  9989. targetMonth = tmStart.tm_mon;
  9990. do
  9991. {
  9992. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9993. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9994. if(targetMonth+1>=13)
  9995. {
  9996. targetYear += 1;
  9997. targetMonth = 1;
  9998. }
  9999. else
  10000. {
  10001. targetMonth += 1;
  10002. }
  10003. }while((targetYear < (tmNow->tm_year+1900)) ||
  10004. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10005. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10006. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10007. system(cmdBuf);
  10008. // Combine log file
  10009. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10010. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10011. }
  10012. else
  10013. {
  10014. system("exec /root/logPackTools 'log' 6");
  10015. }
  10016. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10017. system(cmdBuf);
  10018. checkUploadLog();
  10019. //****************location*******************/
  10020. if(strcmp(locationstr,"")==0)
  10021. {
  10022. DEBUG_INFO("location is <Empty>!\n");
  10023. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10024. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10025. goto end;
  10026. }
  10027. memset(protocol, 0, ARRAY_SIZE(protocol));
  10028. memset(user, 0, ARRAY_SIZE(user) );
  10029. memset(password, 0, ARRAY_SIZE(password));
  10030. memset(host, 0, ARRAY_SIZE(host));
  10031. memset(path, 0, ARRAY_SIZE(path));
  10032. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10033. memset(host1, 0, ARRAY_SIZE(host1));
  10034. memset(path1, 0, ARRAY_SIZE(path1));
  10035. /*location: ftp://user:password@host:port/path*/
  10036. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10037. if((access(fnamePlusPath,F_OK))!=-1)
  10038. {
  10039. DEBUG_INFO("fnamePlusPath exist.\n");
  10040. }
  10041. else
  10042. {
  10043. DEBUG_INFO("fnamePlusPath not exist!\n");
  10044. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10045. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10046. goto end;
  10047. }
  10048. if(strchr(locationstr,'@')==NULL)
  10049. {
  10050. sscanf(locationstr,
  10051. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10052. protocol, host, &port, path);
  10053. strcpy(user,"anonymous");
  10054. strcpy(password,"");
  10055. }
  10056. else
  10057. {
  10058. //DEBUG_INFO("pch=%s\n", pch);
  10059. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10060. protocol, user, password, host, &port, path);
  10061. }
  10062. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10063. {
  10064. DEBUG_INFO("protocol is not ftp/http ! \n");
  10065. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10066. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10067. goto end;
  10068. }
  10069. if(strncmp(locationstr,"http", 4) == 0)
  10070. {
  10071. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10072. sprintf(ftppath,"/%s", path);
  10073. do
  10074. {
  10075. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10076. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10077. sleep(3);
  10078. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10079. if(!isSuccess)
  10080. {
  10081. DEBUG_INFO("Diagnostics fail.\n");
  10082. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10083. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10084. sleep(retryIntervalInt);
  10085. }
  10086. else
  10087. {
  10088. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10089. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10090. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10091. }
  10092. retriesInt--;
  10093. }while((isSuccess == 0)&&(retriesInt >= 0));
  10094. }
  10095. else
  10096. {
  10097. sscanf(host,"%[^/]%s",host1, path1);
  10098. if(strlen(path) > 0)
  10099. sprintf(ftppath,"/%s", path);
  10100. else
  10101. sprintf(ftppath,"/%s", path1);
  10102. int ftppathlen=strlen(ftppath);
  10103. int i=1;
  10104. char filenametemp[50];
  10105. while(i < ftppathlen)
  10106. {
  10107. int len=ftppathlen-i;
  10108. if(ftppath[len]== 47) // '/' ascll code: 47
  10109. {
  10110. DEBUG_INFO("find '/' all right\n");
  10111. break;
  10112. }
  10113. i=i+1;
  10114. }
  10115. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10116. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10117. filenametemp[i+1] = 0;
  10118. if(port == 0)
  10119. port = 21;
  10120. do
  10121. {
  10122. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10123. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10124. sleep(3);
  10125. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10126. if(!isSuccess)
  10127. {
  10128. DEBUG_INFO("Diagnostics fail.\n");
  10129. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10130. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10131. sleep(retryIntervalInt);
  10132. }
  10133. else
  10134. {
  10135. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10136. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10137. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10138. }
  10139. retriesInt--;
  10140. }while((!isSuccess)&&(retriesInt >= 0));
  10141. }
  10142. end:
  10143. system("rm -f /mnt/*");
  10144. sleep(5);
  10145. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10146. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10147. interLock.isGetDiagnosticGoing = 0;
  10148. pthread_exit(NULL);
  10149. }
  10150. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10151. {
  10152. mtrace();
  10153. int result = FAIL;
  10154. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10155. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10156. {
  10157. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10158. locallistVersion = -1;
  10159. }
  10160. else
  10161. {
  10162. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10163. OCPP_getListVerion();
  10164. }
  10165. //from db.OCPP_getListVerion
  10166. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10167. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10168. sendGetLocalListVersionConfirmation(uuid,"");
  10169. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10170. return result;
  10171. }
  10172. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10173. {
  10174. mtrace();
  10175. int result = FAIL;
  10176. int connectorIdInt=-1;
  10177. int tempIndex = 0;
  10178. int connectorIdIsNULL, chargingProfileIsNULL;
  10179. char comfirmstr[20]={0};
  10180. char cmdBuf[512];
  10181. json_object *RemoteStartTransaction;
  10182. FILE *fp;
  10183. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10184. if(server_pending == TRUE)
  10185. {
  10186. return 0;
  10187. }
  10188. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10189. RemoteStartTransaction = json_tokener_parse(payload);
  10190. if(!is_error(RemoteStartTransaction))
  10191. {
  10192. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10193. {
  10194. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10195. }
  10196. else
  10197. {
  10198. connectorIdIsNULL = TRUE;
  10199. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10200. {
  10201. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10202. {
  10203. connectorIdIsNULL = FALSE;
  10204. connectorIdInt = (gun_index+1);
  10205. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10206. break;
  10207. }
  10208. }
  10209. }
  10210. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10211. {
  10212. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10213. // Required data
  10214. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10215. // Optional data
  10216. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10217. {
  10218. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10220. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10221. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10222. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10223. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10224. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10225. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10226. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10227. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10228. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10229. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10230. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10231. {
  10232. 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")));
  10233. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10234. 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"));
  10235. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10236. 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"));
  10237. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10238. 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")));
  10239. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10240. {
  10241. 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++)
  10242. {
  10243. 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"));
  10244. 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"));
  10245. 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)
  10246. 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"));
  10247. }
  10248. }
  10249. }
  10250. }
  10251. else
  10252. {
  10253. chargingProfileIsNULL = TRUE;
  10254. }
  10255. }
  10256. }
  10257. else
  10258. {
  10259. connectorIdIsNULL = TRUE;
  10260. }
  10261. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10262. {
  10263. DEBUG_WARN("Connector id is NULL\n.");
  10264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10265. goto end;
  10266. }
  10267. /*
  10268. enum _SYSTEM_STATUS
  10269. {
  10270. S_BOOTING = 0,
  10271. S_IDLE, = 1
  10272. S_AUTHORIZING, = 2
  10273. S_REASSIGN_CHECK, = 3
  10274. S_REASSIGN, = 4
  10275. S_PRECHARGE, = 5
  10276. S_PREPARING_FOR_EV, = 6
  10277. S_PREPARING_FOR_EVSE, = 7
  10278. S_CHARGING, = 8
  10279. S_TERMINATING, = 9
  10280. S_COMPLETE, = 10
  10281. S_ALARM, = 11
  10282. S_FAULT = 12
  10283. }
  10284. */
  10285. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10286. {
  10287. //check Transaction active
  10288. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10289. {
  10290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10291. {
  10292. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10293. }
  10294. else
  10295. {
  10296. tempIndex = connectorIdInt -1;
  10297. }
  10298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10299. {
  10300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10301. {
  10302. 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))
  10303. {
  10304. //Reserved
  10305. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10306. }
  10307. 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))
  10308. {
  10309. //Reserved
  10310. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10311. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10312. goto end;
  10313. }
  10314. else
  10315. {
  10316. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10317. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10318. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10319. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10320. {
  10321. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10322. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10323. goto end;
  10324. }
  10325. }//END FOR ELSE
  10326. }
  10327. }// END FOR CHAdeMO_QUANTITY
  10328. }
  10329. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10330. {
  10331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10332. {
  10333. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10334. }
  10335. else
  10336. {
  10337. tempIndex = connectorIdInt -1;
  10338. }
  10339. for (int index = 0; index < CCS_QUANTITY; index++)
  10340. {
  10341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10342. {
  10343. 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))
  10344. {
  10345. //Reserved
  10346. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10347. }
  10348. 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))
  10349. {
  10350. //Reserved
  10351. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10352. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10353. goto end;
  10354. }
  10355. else
  10356. {
  10357. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10358. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10359. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10360. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10361. {
  10362. DEBUG_WARN("CCS connector not allow start\n.");
  10363. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10364. goto end;
  10365. }
  10366. }// END FOR ELSE
  10367. }
  10368. }// END FOR CCS_QUANTITY
  10369. }
  10370. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10371. {
  10372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10373. {
  10374. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10375. }
  10376. else
  10377. {
  10378. tempIndex = connectorIdInt -1;
  10379. }
  10380. for (int index = 0; index < GB_QUANTITY; index++)
  10381. {
  10382. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10383. {
  10384. 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))
  10385. {
  10386. //Reserved
  10387. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10388. }
  10389. 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))
  10390. {
  10391. //Reserved
  10392. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10393. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10394. goto end;
  10395. }
  10396. else
  10397. {
  10398. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10399. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10400. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10401. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10402. {
  10403. DEBUG_WARN("GB connector not allow start\n.");
  10404. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10405. goto end;
  10406. }
  10407. }// END FOR ELSE
  10408. }
  10409. } // END FOR GB_QUANTITY
  10410. }
  10411. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10412. {
  10413. tempIndex = connectorIdInt -1;
  10414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10415. {
  10416. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10417. {
  10418. 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))
  10419. {
  10420. //Reserved
  10421. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10422. }
  10423. 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))
  10424. {
  10425. //Reserved
  10426. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10427. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10428. goto end;
  10429. }
  10430. else
  10431. {
  10432. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10433. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10434. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10435. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10436. {
  10437. DEBUG_WARN("GB connector not allow start\n.");
  10438. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10439. goto end;
  10440. }
  10441. }// END FOR ELSE
  10442. }
  10443. } // END FOR GB_QUANTITY
  10444. }
  10445. else
  10446. {
  10447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10448. {
  10449. tempIndex = 2;
  10450. }
  10451. else
  10452. {
  10453. tempIndex = connectorIdInt -1;
  10454. }
  10455. for (int index = 0; index < AC_QUANTITY; index++)
  10456. {
  10457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10458. {
  10459. 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))
  10460. {
  10461. //Reserved
  10462. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10463. }
  10464. 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))
  10465. {
  10466. //Reserved
  10467. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10468. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10469. goto end;
  10470. }
  10471. else
  10472. {
  10473. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10474. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10475. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10476. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10477. {
  10478. DEBUG_WARN("AC connector not allow start\n.");
  10479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10480. goto end;
  10481. }
  10482. }//END FOR ELSE
  10483. }
  10484. }// END FOR AC_QUANTITY
  10485. }
  10486. if(chargingProfileIsNULL == FALSE)
  10487. {
  10488. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10489. {
  10490. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10491. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10492. //memset idTag
  10493. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10494. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10495. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10496. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10497. // Save profile to file
  10498. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10499. system(cmdBuf);
  10500. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10501. fp = fopen(cmdBuf, "w");
  10502. 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));
  10503. fclose(fp);
  10504. }
  10505. else
  10506. {
  10507. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10509. }
  10510. }
  10511. else
  10512. {
  10513. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10515. //memset idTag
  10516. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10517. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10518. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10519. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10520. }
  10521. }
  10522. else
  10523. {
  10524. DEBUG_WARN("Connector id over\n.");
  10525. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10526. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10527. }
  10528. end:
  10529. json_object_put(RemoteStartTransaction);
  10530. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10531. {
  10532. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10533. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10534. }
  10535. //OCPP send RemoteStartConfirmation by first.
  10536. sendRemoteStartConfirmation(uuid, comfirmstr);
  10537. return result;
  10538. }
  10539. int handleRemoteStartRequest(char *uuid, char *payload)
  10540. {
  10541. mtrace();
  10542. int result = PASS;
  10543. int connectorIdInt=-1;
  10544. int tempIndex = 0;
  10545. char comfirmstr[20]={0};
  10546. char cmdBuf[512];
  10547. json_object *RemoteStartTransaction;
  10548. FILE *fp;
  10549. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10550. if(server_pending == TRUE)
  10551. {
  10552. result = FAIL;
  10553. }
  10554. RemoteStartTransaction = json_tokener_parse(payload);
  10555. if(!is_error(RemoteStartTransaction))
  10556. {
  10557. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10558. {
  10559. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10560. }
  10561. else
  10562. {
  10563. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10564. {
  10565. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10566. {
  10567. connectorIdInt = (gun_index+1);
  10568. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10569. break;
  10570. }
  10571. }
  10572. }
  10573. if(connectorIdInt == 0)
  10574. {
  10575. DEBUG_WARN("Connector id shall not equal 0.\n");
  10576. result = FAIL;
  10577. }
  10578. else if(connectorIdInt == -1)
  10579. {
  10580. DEBUG_INFO("Connector id does not specific.\n");
  10581. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10582. {
  10583. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10584. // Required data
  10585. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10586. // Optional data
  10587. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10588. {
  10589. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10590. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10591. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10592. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10593. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10594. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10595. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10596. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10597. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10598. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10599. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10600. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10601. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10602. {
  10603. 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")));
  10604. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10605. 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"));
  10606. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10607. 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"));
  10608. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10609. 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")));
  10610. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10611. {
  10612. 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++)
  10613. {
  10614. 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"));
  10615. 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"));
  10616. 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)
  10617. 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"));
  10618. }
  10619. }
  10620. }
  10621. }
  10622. else
  10623. {
  10624. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10625. }
  10626. }
  10627. }
  10628. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10629. {
  10630. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10631. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10632. // Required data
  10633. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10634. // Optional data
  10635. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10636. {
  10637. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10638. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10639. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10640. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10641. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10642. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10643. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10644. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10645. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10646. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10647. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10648. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10649. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10650. {
  10651. 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")));
  10652. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10653. 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"));
  10654. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10655. 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"));
  10656. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10657. 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")));
  10658. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10659. {
  10660. 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++)
  10661. {
  10662. 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"));
  10663. 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"));
  10664. 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)
  10665. 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"));
  10666. }
  10667. }
  10668. }
  10669. }
  10670. else
  10671. {
  10672. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10673. }
  10674. }
  10675. else
  10676. {
  10677. DEBUG_WARN("Connector id is over maximun value.\n");
  10678. result = FAIL;
  10679. }
  10680. }
  10681. if(result == PASS)
  10682. {
  10683. if(connectorIdInt > 0)
  10684. {
  10685. //check Transaction active
  10686. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10687. {
  10688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10689. {
  10690. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10691. }
  10692. else
  10693. {
  10694. tempIndex = connectorIdInt -1;
  10695. }
  10696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10697. {
  10698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10699. {
  10700. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10701. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10702. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10703. {
  10704. //Reserved
  10705. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10706. }
  10707. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10708. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10709. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10710. {
  10711. //Reserved
  10712. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10713. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10714. goto end;
  10715. }
  10716. else
  10717. {
  10718. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10719. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10720. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10721. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10722. {
  10723. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10724. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10725. goto end;
  10726. }
  10727. }//END FOR ELSE
  10728. }
  10729. }// END FOR CHAdeMO_QUANTITY
  10730. }
  10731. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10732. {
  10733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10734. {
  10735. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10736. }
  10737. else
  10738. {
  10739. tempIndex = connectorIdInt -1;
  10740. }
  10741. for (int index = 0; index < CCS_QUANTITY; index++)
  10742. {
  10743. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10744. {
  10745. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10746. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10747. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10748. {
  10749. //Reserved
  10750. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10751. }
  10752. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10753. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10754. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10755. {
  10756. //Reserved
  10757. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10758. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10759. goto end;
  10760. }
  10761. else
  10762. {
  10763. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10764. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10765. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10766. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10767. {
  10768. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10769. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10770. goto end;
  10771. }
  10772. }// END FOR ELSE
  10773. }
  10774. }// END FOR CCS_QUANTITY
  10775. }
  10776. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10777. {
  10778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10779. {
  10780. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10781. }
  10782. else
  10783. {
  10784. tempIndex = connectorIdInt -1;
  10785. }
  10786. for (int index = 0; index < GB_QUANTITY; index++)
  10787. {
  10788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10789. {
  10790. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10791. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10792. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10793. {
  10794. //Reserved
  10795. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10796. }
  10797. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10798. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10799. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10800. {
  10801. //Reserved
  10802. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10803. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10804. goto end;
  10805. }
  10806. else
  10807. {
  10808. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10809. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10810. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10811. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10812. {
  10813. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10815. goto end;
  10816. }
  10817. }// END FOR ELSE
  10818. }
  10819. } // END FOR GB_QUANTITY
  10820. }
  10821. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10822. {
  10823. tempIndex = connectorIdInt -1;
  10824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10825. {
  10826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10827. {
  10828. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10829. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10830. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10831. {
  10832. //Reserved
  10833. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10834. }
  10835. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10836. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10837. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10838. {
  10839. //Reserved
  10840. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10841. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10842. goto end;
  10843. }
  10844. else
  10845. {
  10846. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10847. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10848. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10849. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10850. {
  10851. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10852. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10853. goto end;
  10854. }
  10855. }// END FOR ELSE
  10856. }
  10857. } // END FOR GB_QUANTITY
  10858. }
  10859. else
  10860. {
  10861. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10862. {
  10863. tempIndex = 2;
  10864. }
  10865. else
  10866. {
  10867. tempIndex = connectorIdInt -1;
  10868. }
  10869. for (int index = 0; index < AC_QUANTITY; index++)
  10870. {
  10871. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10872. {
  10873. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10874. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10875. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10876. {
  10877. //Reserved
  10878. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10879. }
  10880. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10881. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10882. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10883. {
  10884. //Reserved
  10885. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10886. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10887. goto end;
  10888. }
  10889. else
  10890. {
  10891. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10892. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10893. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10894. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10895. {
  10896. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10897. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10898. goto end;
  10899. }
  10900. }//END FOR ELSE
  10901. }
  10902. }// END FOR AC_QUANTITY
  10903. }
  10904. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10905. {
  10906. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10907. {
  10908. // Save profile to file
  10909. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10910. system(cmdBuf);
  10911. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10912. fp = fopen(cmdBuf, "w");
  10913. 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));
  10914. fclose(fp);
  10915. }
  10916. else
  10917. {
  10918. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10919. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10920. goto end;
  10921. }
  10922. }
  10923. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10924. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10925. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10926. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10927. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10928. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10929. }
  10930. else
  10931. {
  10932. uint8_t isHasIdleConnector = FALSE;
  10933. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10934. {
  10935. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10936. {
  10937. isHasIdleConnector = TRUE;
  10938. break;
  10939. }
  10940. }
  10941. if(isHasIdleConnector == TRUE)
  10942. {
  10943. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10944. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10945. {
  10946. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10947. {
  10948. // Save profile to file
  10949. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10950. system(cmdBuf);
  10951. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10952. fp = fopen(cmdBuf, "w");
  10953. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10954. fclose(fp);
  10955. refreshStartTimer(&clientTime.RemoteStartWait);
  10956. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10957. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10958. }
  10959. else
  10960. {
  10961. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10962. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10963. }
  10964. }
  10965. else
  10966. {
  10967. refreshStartTimer(&clientTime.RemoteStartWait);
  10968. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10969. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10970. }
  10971. }
  10972. else
  10973. {
  10974. DEBUG_INFO("There is not any connector is idle.\n");
  10975. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10976. }
  10977. }
  10978. }
  10979. else
  10980. {
  10981. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10982. }
  10983. end:
  10984. json_object_put(RemoteStartTransaction);
  10985. sendRemoteStartConfirmation(uuid, comfirmstr);
  10986. return result;
  10987. }
  10988. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10989. {
  10990. mtrace();
  10991. int result = FAIL;
  10992. int match = FALSE;
  10993. int GunNO = 0;
  10994. int tempIndex = 0;
  10995. int transactionIdInt=0;
  10996. int transactionIdIsNULL= TRUE;
  10997. char comfirmstr[20];
  10998. json_object *RemoteStopTransaction;
  10999. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11000. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11001. if(server_pending == TRUE)
  11002. {
  11003. return 0;
  11004. }
  11005. RemoteStopTransaction = json_tokener_parse(payload);
  11006. if(!is_error(RemoteStopTransaction))
  11007. {
  11008. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11009. {
  11010. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11011. transactionIdIsNULL = FALSE;
  11012. }
  11013. }
  11014. json_object_put(RemoteStopTransaction);
  11015. if(transactionIdIsNULL == FALSE)
  11016. {
  11017. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11018. {
  11019. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11020. {
  11021. //check Transaction active
  11022. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11023. {
  11024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11025. {
  11026. tempIndex = ((gun_index==2) ? 1: 0);
  11027. }
  11028. else
  11029. {
  11030. tempIndex = gun_index;
  11031. }
  11032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11033. {
  11034. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11035. {
  11036. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11037. {
  11038. match = TRUE;
  11039. GunNO = gun_index;
  11040. }
  11041. }
  11042. }// END FOR CHAdeMO_QUANTITY
  11043. }
  11044. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11045. {
  11046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11047. {
  11048. tempIndex = ((gun_index==2) ? 1: 0);
  11049. }
  11050. else
  11051. {
  11052. tempIndex = gun_index;
  11053. }
  11054. for (int index = 0; index < CCS_QUANTITY; index++)
  11055. {
  11056. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11057. {
  11058. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11059. {
  11060. match = TRUE;
  11061. GunNO = gun_index;
  11062. }
  11063. }
  11064. }// END FOR CCS_QUANTITY
  11065. }
  11066. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11067. {
  11068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11069. {
  11070. tempIndex = ((gun_index==2) ? 1: 0);
  11071. }
  11072. else
  11073. {
  11074. tempIndex = gun_index;
  11075. }
  11076. for (int index = 0; index < GB_QUANTITY; index++)
  11077. {
  11078. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11079. {
  11080. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11081. {
  11082. match = TRUE;
  11083. GunNO = gun_index;
  11084. }
  11085. }
  11086. }// END FOR GB_QUANTITY
  11087. }
  11088. else if(gunType[gun_index] == GUN_TYPE_DO)
  11089. {
  11090. tempIndex = gun_index;
  11091. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11092. {
  11093. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11094. {
  11095. 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
  11096. {
  11097. match = TRUE;
  11098. GunNO = gun_index;
  11099. }
  11100. }
  11101. }// END FOR GB_QUANTITY
  11102. }
  11103. else
  11104. {
  11105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11106. {
  11107. tempIndex = 2;
  11108. }
  11109. else
  11110. {
  11111. tempIndex = gun_index;
  11112. }
  11113. for (int index = 0; index < AC_QUANTITY; index++)
  11114. {
  11115. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11116. {
  11117. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11118. {
  11119. match = TRUE;
  11120. GunNO = gun_index;
  11121. }
  11122. }
  11123. }// END FOR CHAdeMO_QUANTITY
  11124. } // END FOR AC ELSE
  11125. }// CHECK IF ResponseTransactionId == transactionIdInt
  11126. }//END FOR
  11127. if( match == TRUE)
  11128. {
  11129. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11130. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11131. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11132. }
  11133. else
  11134. {
  11135. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11136. }
  11137. }
  11138. else
  11139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11140. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11141. return result;
  11142. }
  11143. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11144. {
  11145. mtrace();
  11146. int result = FAIL;
  11147. int connectorIdInt=0, reservationIdInt=0;
  11148. int tempIndex = 0;
  11149. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11150. char comfirmstr[20]={0};
  11151. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11152. int c = 0;
  11153. char *loc;
  11154. //char *ptr;
  11155. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11156. strcpy(sstrtemp, stringtrimspace(payload));
  11157. //***(1)connectorId ****/
  11158. c=0;
  11159. loc = strstr(sstrtemp, "connectorId");
  11160. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11161. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11162. {
  11163. sstr[c] = loc[strlen("connectorId")+2+c];
  11164. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11165. c++;
  11166. }
  11167. sstr[c] = '\0';
  11168. connectorIdInt = atoi(sstr);
  11169. //***(2)expiryDate ****/
  11170. loc = strstr(sstrtemp, "expiryDate");
  11171. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11172. c = 0;
  11173. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11174. {
  11175. sstr[c] = loc[3+strlen("expiryDate")+c];
  11176. c++;
  11177. }
  11178. sstr[c] = '\0';
  11179. strcpy(expiryDatestr, sstr);
  11180. //***(3)idTag ****/
  11181. loc = strstr(sstrtemp, "idTag");
  11182. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11183. c = 0;
  11184. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11185. {
  11186. sstr[c] = loc[3+strlen("idTag")+c];
  11187. c++;
  11188. }
  11189. sstr[c] = '\0';
  11190. strcpy(idTagstr, sstr);
  11191. //***(4)parentIdTag ****/
  11192. loc = strstr(sstrtemp, "parentIdTag");
  11193. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11194. c = 0;
  11195. if(loc == NULL)
  11196. {
  11197. strcpy(parentIdTagstr, "");
  11198. }
  11199. else
  11200. {
  11201. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11202. {
  11203. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11204. c++;
  11205. }
  11206. sstr[c] = '\0';
  11207. strcpy(parentIdTagstr, sstr);
  11208. }
  11209. //***(5)reservationId ****/
  11210. c=0;
  11211. loc = strstr(sstrtemp, "reservationId");
  11212. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11213. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11214. {
  11215. sstr[c] = loc[strlen("reservationId")+2+c];
  11216. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11217. c++;
  11218. }
  11219. sstr[c] = '\0';
  11220. reservationIdInt = atoi(sstr);
  11221. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11222. /*
  11223. enum SYSTEM_STATUS
  11224. {
  11225. SYS_MODE_BOOTING = 0,
  11226. SYS_MODE_IDLE = 1,
  11227. SYS_MODE_AUTHORIZING = 2,
  11228. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11229. SYS_MODE_REASSIGN = 4,
  11230. SYS_MODE_PREPARING = 5,
  11231. SYS_MODE_PREPARE_FOR_EV = 6,
  11232. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11233. SYS_MODE_CHARGING = 8,
  11234. SYS_MODE_TERMINATING = 9,
  11235. SYS_MODE_COMPLETE = 10,
  11236. SYS_MODE_ALARM = 11,
  11237. SYS_MODE_FAULT = 12,
  11238. SYS_MODE_RESERVATION = 13,
  11239. SYS_MODE_BOOKING = 14,
  11240. SYS_MODE_MAINTAIN = 15,
  11241. SYS_MODE_DEBUG = 16,
  11242. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11243. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11244. SYS_MODE_UPDATE = 19
  11245. };
  11246. */
  11247. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11248. {
  11249. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11250. goto end;
  11251. }
  11252. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11253. {
  11254. //check Transaction active
  11255. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11256. {
  11257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11258. {
  11259. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11260. }
  11261. else
  11262. {
  11263. tempIndex = connectorIdInt -1;
  11264. }
  11265. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11266. {
  11267. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11268. {
  11269. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11270. {
  11271. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11272. {
  11273. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11274. {
  11275. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11277. }
  11278. 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'))
  11279. {
  11280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11281. }
  11282. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11283. {
  11284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11285. }
  11286. else
  11287. {
  11288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11289. }
  11290. }
  11291. 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
  11292. {
  11293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11294. }
  11295. }
  11296. else
  11297. {
  11298. //replace reservation
  11299. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11301. }
  11302. }
  11303. } // END FOR CHAdeMO_QUANTITY
  11304. }
  11305. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11306. {
  11307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11308. {
  11309. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11310. }
  11311. else
  11312. {
  11313. tempIndex = connectorIdInt -1;
  11314. }
  11315. for (int index = 0; index < CCS_QUANTITY; index++)
  11316. {
  11317. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11318. {
  11319. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11320. {
  11321. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11322. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11323. {
  11324. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[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.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'))
  11330. {
  11331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11332. }
  11333. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[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.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
  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 CCS_QUANTITY
  11355. }
  11356. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  11367. {
  11368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11369. {
  11370. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[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.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11374. {
  11375. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[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.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'))
  11381. {
  11382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11383. }
  11384. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[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.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
  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 GB_QUANTITY
  11406. }
  11407. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11408. {
  11409. tempIndex = connectorIdInt -1;
  11410. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11411. {
  11412. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11413. {
  11414. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11415. {
  11416. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11417. 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
  11418. {
  11419. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11420. {
  11421. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11423. }
  11424. 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'))
  11425. {
  11426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11427. }
  11428. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11429. {
  11430. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11431. }
  11432. else
  11433. {
  11434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11435. }
  11436. }
  11437. 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
  11438. {
  11439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11440. }
  11441. }
  11442. else
  11443. {
  11444. //replace reservation
  11445. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11447. }
  11448. }
  11449. }// END FOR GB_QUANTITY
  11450. }
  11451. else
  11452. {
  11453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11454. {
  11455. tempIndex = 2;
  11456. }
  11457. else
  11458. {
  11459. tempIndex = (connectorIdInt -1);
  11460. }
  11461. for (int index = 0; index < AC_QUANTITY; index++)
  11462. {
  11463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11464. {
  11465. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11466. {
  11467. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11468. {
  11469. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11470. {
  11471. 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))
  11472. {
  11473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11474. }
  11475. else
  11476. {
  11477. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11479. }
  11480. }
  11481. 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'))
  11482. {
  11483. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11484. }
  11485. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11486. {
  11487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11488. }
  11489. else
  11490. {
  11491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11492. }
  11493. }
  11494. 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
  11495. {
  11496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11497. }
  11498. }
  11499. else
  11500. {
  11501. //replace reservation
  11502. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11503. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11504. }
  11505. }
  11506. } // END FOR AC_QUANTITY
  11507. }
  11508. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11509. }
  11510. else if(connectorIdInt == 0)
  11511. {
  11512. //check Transaction active
  11513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11514. {
  11515. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11516. {
  11517. 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'))
  11518. {
  11519. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11520. goto end;
  11521. }
  11522. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11523. {
  11524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11525. goto end;
  11526. }
  11527. 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
  11528. {
  11529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11530. goto end;
  11531. }
  11532. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11533. {
  11534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11535. goto end;
  11536. }
  11537. }
  11538. }// END FOR CHAdeMO_QUANTITY
  11539. for (int index = 0; index < CCS_QUANTITY; index++)
  11540. {
  11541. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11542. {
  11543. 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'))
  11544. {
  11545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11546. goto end;
  11547. }
  11548. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11549. {
  11550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11551. goto end;
  11552. }
  11553. 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
  11554. {
  11555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11556. goto end;
  11557. }
  11558. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11559. {
  11560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11561. goto end;
  11562. }
  11563. }
  11564. } // END FOR CCS_QUANTITY
  11565. for (int index = 0; index < GB_QUANTITY; index++)
  11566. {
  11567. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11568. {
  11569. 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'))
  11570. {
  11571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11572. goto end;
  11573. }
  11574. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11575. {
  11576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11577. goto end;
  11578. }
  11579. 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
  11580. {
  11581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11582. goto end;
  11583. }
  11584. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11585. {
  11586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11587. goto end;
  11588. }
  11589. }
  11590. } // END FOR GB_QUANTITY
  11591. for (int index = 0; index < AC_QUANTITY; index++)
  11592. {
  11593. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11594. {
  11595. 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'))
  11596. {
  11597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11598. goto end;
  11599. }
  11600. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11601. {
  11602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11603. goto end;
  11604. }
  11605. 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
  11606. {
  11607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11608. goto end;
  11609. }
  11610. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11611. {
  11612. 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))
  11613. {
  11614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11615. goto end;
  11616. }
  11617. }
  11618. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11619. {
  11620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11621. goto end;
  11622. }
  11623. }
  11624. }// END FOR AC_QUANTITY
  11625. //The connectorId is 0
  11626. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11628. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11629. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11630. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11631. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11632. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11633. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11634. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11635. result = TRUE;
  11636. return result;
  11637. }
  11638. else
  11639. {
  11640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11641. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11642. }
  11643. if(strcmp(comfirmstr,"Accepted") == 0)
  11644. {
  11645. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11646. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11647. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11648. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11649. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11650. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11651. result = TRUE;
  11652. return result;
  11653. }
  11654. end:
  11655. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11656. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11657. return result;
  11658. }
  11659. int handleResetRequest(char *uuid, char *payload)
  11660. {
  11661. mtrace();
  11662. int result = FAIL;
  11663. char sstr[10]={0},sstrtemp[30]={ 0 };
  11664. char typestr[10]={0};
  11665. char comfirmstr[20]={0};
  11666. int c = 0;
  11667. char *loc;
  11668. DEBUG_INFO("handleResetRequest...\n");
  11669. strcpy(sstrtemp, stringtrimspace(payload));
  11670. loc = strstr(sstrtemp, "type");
  11671. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11672. c = 0;
  11673. while (loc[3+strlen("type")+c] != '\"')
  11674. {
  11675. sstr[c] = loc[3+strlen("type")+c];
  11676. c++;
  11677. }
  11678. sstr[c] = '\0';
  11679. strcpy(typestr,sstr);
  11680. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11681. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11682. {
  11683. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11684. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11685. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11686. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11687. }
  11688. else
  11689. {
  11690. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11691. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11692. result = PASS;
  11693. }
  11694. sendResetConfirmation(uuid, comfirmstr);
  11695. return result;
  11696. }
  11697. int handleSendLocalListRequest(char *uuid, char *payload)
  11698. {
  11699. mtrace();
  11700. int result = FAIL;
  11701. char comfirmstr[20];
  11702. int checkState_Faulted = FALSE;
  11703. json_object *SendLocalList;
  11704. DEBUG_INFO("handleSendLocalListRequest...\n");
  11705. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11706. {
  11707. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11708. goto end;
  11709. }
  11710. //check Charge Point state
  11711. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11712. {
  11713. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11714. {
  11715. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11716. }
  11717. }
  11718. for (int index = 0; index < CCS_QUANTITY; index++)
  11719. {
  11720. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11721. {
  11722. checkState_Faulted = TRUE; //OCPP Status
  11723. }
  11724. }
  11725. for (int index = 0; index < GB_QUANTITY; index++)
  11726. {
  11727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11728. {
  11729. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11730. }
  11731. }
  11732. //check Charge Point state
  11733. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11734. {
  11735. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11736. {
  11737. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11738. }
  11739. }
  11740. //check Charge Point state
  11741. for (int index = 0; index < AC_QUANTITY; index++)
  11742. {
  11743. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11744. {
  11745. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11746. }
  11747. }
  11748. if(checkState_Faulted == TRUE)
  11749. {
  11750. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11751. goto end;
  11752. }
  11753. // Parsing payload
  11754. SendLocalList = json_tokener_parse(payload);
  11755. if(!is_error(SendLocalList))
  11756. {
  11757. // Required data
  11758. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11759. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11760. // Optional data
  11761. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11762. {
  11763. //Check UpdateType
  11764. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11765. {
  11766. //Local list full update
  11767. DEBUG_INFO("Local list full update.\n");
  11768. OCPP_getListVerion();
  11769. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11770. {
  11771. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11772. goto end;
  11773. }
  11774. OCPP_cleanLocalList();
  11775. }
  11776. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11777. {
  11778. //Local list different update
  11779. DEBUG_INFO("Local list different update.\n");
  11780. OCPP_getListVerion();
  11781. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11782. {
  11783. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11784. goto end;
  11785. }
  11786. }
  11787. else
  11788. {
  11789. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11790. goto end;
  11791. }
  11792. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11793. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11794. {
  11795. 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")));
  11796. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11797. {
  11798. 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")));
  11799. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11800. 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")));
  11801. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11802. 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")));
  11803. }
  11804. // Add to db
  11805. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11806. {
  11807. //Local list full update
  11808. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11809. idx,
  11810. ShmOCPP16Data->SendLocalList.ListVersion,
  11811. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11812. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11813. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11814. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11815. // update list
  11816. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11817. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11818. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11819. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11820. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11821. }
  11822. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11823. {
  11824. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11825. idx,
  11826. ShmOCPP16Data->SendLocalList.ListVersion,
  11827. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11828. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11829. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11830. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11831. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11832. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11833. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11834. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11835. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11836. }
  11837. }
  11838. }
  11839. else
  11840. {
  11841. //Check UpdateType
  11842. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11843. {
  11844. //Local list full update
  11845. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11846. OCPP_cleanLocalList();
  11847. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11848. goto end;
  11849. }
  11850. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11851. {
  11852. //Local list different update
  11853. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11854. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11855. goto end;
  11856. }
  11857. }
  11858. result = PASS;
  11859. }
  11860. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11861. end:
  11862. json_object_put(SendLocalList);
  11863. sendSendLocalListConfirmation(uuid, comfirmstr);
  11864. return result;
  11865. }
  11866. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11867. {
  11868. mtrace();
  11869. int result = FAIL;
  11870. struct StructSetChargingProfile SetProfileReq = {0};
  11871. int tempchargingProfileIdInt;
  11872. int chargingSchedulePeriodCount = 0;
  11873. char comfirmstr[20]={0};
  11874. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11875. char rmFileCmd[128]={0};
  11876. int profileQuantity = 0;
  11877. json_object *SetChargingProfile;
  11878. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11879. SetChargingProfile = json_tokener_parse(payload);
  11880. if(!is_error(SetChargingProfile))
  11881. {
  11882. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11883. {
  11884. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11885. }
  11886. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11887. {
  11888. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11889. {
  11890. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11891. }
  11892. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11893. {
  11894. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11895. }
  11896. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11897. {
  11898. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11899. }
  11900. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11901. {
  11902. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11903. }
  11904. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11905. {
  11906. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11907. }
  11908. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11909. {
  11910. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11911. }
  11912. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11913. {
  11914. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11915. }
  11916. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11917. {
  11918. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11919. }
  11920. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11921. {
  11922. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11923. {
  11924. 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")));
  11925. }
  11926. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11927. {
  11928. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11929. }
  11930. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11931. {
  11932. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11933. }
  11934. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11935. {
  11936. 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")));
  11937. }
  11938. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11939. {
  11940. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11941. if(chargingSchedulePeriodCount <= 10)
  11942. {
  11943. 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++)
  11944. {
  11945. 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)
  11946. {
  11947. 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"));
  11948. }
  11949. 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)
  11950. {
  11951. 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"));
  11952. }
  11953. 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)
  11954. {
  11955. 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"));
  11956. }
  11957. }
  11958. }
  11959. }
  11960. }
  11961. }
  11962. }
  11963. // Profile periods quantity check
  11964. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11965. {
  11966. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11967. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11968. goto end;
  11969. }
  11970. // Check invalid limit
  11971. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11972. {
  11973. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11974. {
  11975. 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)))) ||
  11976. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11977. {
  11978. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11979. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11980. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11981. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11982. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11983. goto end;
  11984. }
  11985. }
  11986. }
  11987. else
  11988. {
  11989. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11990. {
  11991. 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))
  11992. {
  11993. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11994. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11995. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11996. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11997. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11998. goto end;
  11999. }
  12000. }
  12001. }
  12002. // Profile purpose info check
  12003. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12004. {
  12005. FILE *fp;
  12006. char dataLine[4096]={0};
  12007. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12008. if(SetProfileReq.ConnectorId != 0)
  12009. {
  12010. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12011. DEBUG_WARN("Profile connector id is not 0.\n");
  12012. goto end;
  12013. }
  12014. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12015. if (!fp)
  12016. {
  12017. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12018. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12019. }
  12020. else
  12021. {
  12022. while(fscanf(fp, "%s", dataLine) != EOF)
  12023. {
  12024. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12025. {
  12026. profileQuantity += 1;
  12027. }
  12028. }
  12029. }
  12030. fclose(fp);
  12031. }
  12032. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12033. {
  12034. FILE *fp;
  12035. char dataLine[4096]={0};
  12036. char filename[128]={0};
  12037. int tmpProfileQuantity;
  12038. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12039. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12040. {
  12041. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12042. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12043. goto end;
  12044. }
  12045. if(SetProfileReq.ConnectorId == 0)
  12046. {
  12047. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12048. {
  12049. tmpProfileQuantity = 0;
  12050. memset(filename, 0, ARRAY_SIZE(filename));
  12051. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12052. fp = fopen(filename, "r");
  12053. if (!fp)
  12054. {
  12055. DEBUG_INFO("%s does not create.\n", filename);
  12056. fp = fopen(filename, "w+");
  12057. }
  12058. else
  12059. {
  12060. while(fscanf(fp, "%s", dataLine) != EOF)
  12061. {
  12062. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12063. {
  12064. tmpProfileQuantity += 1;
  12065. }
  12066. }
  12067. }
  12068. fclose(fp);
  12069. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12070. }
  12071. }
  12072. else
  12073. {
  12074. memset(filename, 0, ARRAY_SIZE(filename));
  12075. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12076. fp = fopen(filename, "r");
  12077. if (!fp)
  12078. {
  12079. DEBUG_INFO("%s does not create.\n", filename);
  12080. fp = fopen(filename, "w+");
  12081. }
  12082. else
  12083. {
  12084. while(fscanf(fp, "%s", dataLine) != EOF)
  12085. {
  12086. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12087. {
  12088. profileQuantity += 1;
  12089. }
  12090. }
  12091. }
  12092. fclose(fp);
  12093. }
  12094. }
  12095. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12096. {
  12097. int isMatchTransactiodId= FALSE;
  12098. FILE *fp;
  12099. char dataLine[4096]={0};
  12100. char filename[128]={0};
  12101. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12102. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12103. if(SetProfileReq.ConnectorId == 0)
  12104. {
  12105. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12106. DEBUG_WARN("Profile connector id is 0.\n");
  12107. goto end;
  12108. }
  12109. int tempIndex = 0;
  12110. //check Transaction active
  12111. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12112. {
  12113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12114. {
  12115. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12116. }
  12117. else
  12118. {
  12119. tempIndex = SetProfileReq.ConnectorId -1;
  12120. }
  12121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12122. {
  12123. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12124. {
  12125. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12126. {
  12127. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12128. {
  12129. isMatchTransactiodId = TRUE;
  12130. break;
  12131. }
  12132. }
  12133. }
  12134. }
  12135. }
  12136. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12137. {
  12138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12139. {
  12140. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12141. }
  12142. else
  12143. {
  12144. tempIndex = SetProfileReq.ConnectorId -1;
  12145. }
  12146. for (int index = 0; index < CCS_QUANTITY; index++)
  12147. {
  12148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12149. {
  12150. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12151. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12152. {
  12153. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12154. {
  12155. isMatchTransactiodId = TRUE;
  12156. break;
  12157. }
  12158. }
  12159. }
  12160. }
  12161. }
  12162. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  12173. {
  12174. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12175. {
  12176. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[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_DO)
  12188. {
  12189. tempIndex = SetProfileReq.ConnectorId -1;
  12190. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12191. {
  12192. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12193. {
  12194. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12195. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12196. {
  12197. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12198. {
  12199. isMatchTransactiodId = TRUE;
  12200. break;
  12201. }
  12202. }
  12203. }
  12204. }
  12205. }
  12206. else
  12207. {
  12208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12209. {
  12210. tempIndex = 2;
  12211. }
  12212. else
  12213. {
  12214. tempIndex = (SetProfileReq.ConnectorId -1);
  12215. }
  12216. for (int index = 0; index < AC_QUANTITY; index++)
  12217. {
  12218. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12219. {
  12220. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12221. {
  12222. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12223. {
  12224. isMatchTransactiodId = TRUE;
  12225. break;
  12226. }
  12227. }
  12228. }
  12229. }
  12230. }
  12231. //check Transaction active
  12232. if(isMatchTransactiodId == FALSE)
  12233. {
  12234. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12235. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12236. goto end;
  12237. }
  12238. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12239. {
  12240. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12241. DEBUG_WARN("Connector id is over max gun number.\n");
  12242. goto end;
  12243. }
  12244. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12245. fp = fopen(filename, "r");
  12246. if (!fp)
  12247. {
  12248. DEBUG_INFO("%s does not create.\n", filename);
  12249. fp = fopen(filename, "w+");
  12250. }
  12251. else
  12252. {
  12253. //Check Charging Profile Count
  12254. while(fscanf(fp, "%s", dataLine) != EOF)
  12255. {
  12256. //DEBUG_INFO("word=%s\n",word);
  12257. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12258. {
  12259. profileQuantity += 1;
  12260. }
  12261. }
  12262. }
  12263. fclose(fp);
  12264. }
  12265. // Check ChargeProfileMaxStackLevel
  12266. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12267. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12268. {
  12269. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12270. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12271. goto end;
  12272. }
  12273. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12274. {
  12275. FILE *fp;
  12276. char dataLine[4096]={0};
  12277. char fnametemp[128]={0};
  12278. int tmpProfileQuantity;
  12279. //Check ChargePointMaxProfile.json exit
  12280. profileQuantity = 0;
  12281. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12282. {
  12283. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12284. //Check Charging Profile Count
  12285. tmpProfileQuantity = 0;
  12286. while(fscanf(fp, "%s", dataLine) != EOF)
  12287. {
  12288. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12289. {
  12290. profileQuantity += 1;
  12291. tmpProfileQuantity += 1;
  12292. }
  12293. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12294. }
  12295. fclose(fp);
  12296. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12297. }
  12298. //Check TxDefaultProfile_%d.json
  12299. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12300. {
  12301. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12302. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12303. if((access(fnametemp,F_OK))!=-1)
  12304. {
  12305. fp = fopen(fnametemp, "r");
  12306. //Check Charging Profile Count
  12307. tmpProfileQuantity = 0;
  12308. while(fscanf(fp, "%s", dataLine) != EOF)
  12309. {
  12310. //DEBUG_INFO("word=%s\n",word);
  12311. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12312. {
  12313. profileQuantity += 1;
  12314. tmpProfileQuantity += 1;
  12315. }
  12316. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12317. }
  12318. fclose(fp);
  12319. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12320. }
  12321. }
  12322. //Check TxProfile_%d.json
  12323. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12324. {
  12325. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12326. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12327. if((access(fnametemp,F_OK))!=-1)
  12328. {
  12329. fp = fopen(fnametemp, "r");
  12330. //Check Charging Profile Count
  12331. tmpProfileQuantity = 0;
  12332. while(fscanf(fp, "%s", dataLine) != EOF)
  12333. {
  12334. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12335. {
  12336. profileQuantity += 1;
  12337. tmpProfileQuantity += 1;
  12338. }
  12339. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12340. }
  12341. fclose(fp);
  12342. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12343. }
  12344. }
  12345. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12346. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12347. {
  12348. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12349. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12350. goto end;
  12351. }
  12352. }
  12353. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12354. //**********************************Write to File********************************************************/
  12355. {
  12356. FILE *infile;
  12357. FILE *outfile;
  12358. char dataLine[4096]={0};
  12359. char filename[128]={0};
  12360. int chkChar=0;
  12361. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12362. {
  12363. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12364. {
  12365. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12366. }
  12367. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12368. {
  12369. if(SetProfileReq.ConnectorId==0)
  12370. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12371. else
  12372. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12373. }
  12374. else
  12375. {
  12376. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12377. }
  12378. infile = fopen (filename, "r");
  12379. outfile = fopen (tempfile, "w");
  12380. chkChar = fgetc(infile);
  12381. rewind(infile);
  12382. if(chkChar == EOF)
  12383. {
  12384. // Profile is empty
  12385. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12386. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12387. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12388. fclose(infile);
  12389. fclose(outfile);
  12390. sprintf(rmFileCmd,"rm -f %s",filename);
  12391. system(rmFileCmd);
  12392. rename(tempfile, filename);
  12393. }
  12394. else
  12395. {
  12396. // Profile is not empty
  12397. int ChargingProfileAdded = FALSE;
  12398. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12399. {
  12400. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12401. json_object *tmpChargingProfile;
  12402. tmpChargingProfile = json_tokener_parse(dataLine);
  12403. if(!is_error(SetChargingProfile))
  12404. {
  12405. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12406. {
  12407. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12408. {
  12409. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12410. }
  12411. }
  12412. }
  12413. json_object_put(tmpChargingProfile);
  12414. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12415. {
  12416. if(ChargingProfileAdded == FALSE)
  12417. {
  12418. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12419. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12420. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12421. ChargingProfileAdded = TRUE;
  12422. }
  12423. }
  12424. else
  12425. {
  12426. fprintf(outfile,"%s\n",dataLine);
  12427. if(ChargingProfileAdded == FALSE)
  12428. {
  12429. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12430. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12431. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12432. ChargingProfileAdded = TRUE;
  12433. }
  12434. }
  12435. } // end of while loop
  12436. fclose(infile);
  12437. fclose(outfile);
  12438. sprintf(rmFileCmd,"rm -f %s",filename);
  12439. system(rmFileCmd);
  12440. rename(tempfile, filename);
  12441. }
  12442. }
  12443. sleep(1);
  12444. result = TRUE;
  12445. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12446. }
  12447. end:
  12448. json_object_put(SetChargingProfile);
  12449. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12450. {
  12451. if(SetProfileReq.ConnectorId == 0)
  12452. {
  12453. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12454. {
  12455. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12456. }
  12457. }
  12458. else
  12459. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12460. }
  12461. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12462. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12463. return result;
  12464. }
  12465. int handleTriggerMessageRequest(char *uuid, char *payload)
  12466. {
  12467. mtrace();
  12468. int result = FAIL;
  12469. int connectorIdIsNULL = FALSE;
  12470. int connectorIdInt =0;
  12471. char sstr[40]={0},sstrtemp[100]={ 0 };
  12472. char requestedMessagestr[40]={0};
  12473. char comfirmstr[20]={0};
  12474. int c = 0;
  12475. char *loc;
  12476. DEBUG_INFO("handleTriggerMessageRequest\n");
  12477. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12478. strcpy(sstrtemp, stringtrimspace(payload));
  12479. c = 0;
  12480. loc = strstr(sstrtemp, "requestedMessage");
  12481. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12482. {
  12483. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12484. c++;
  12485. }
  12486. sstr[c] = '\0';
  12487. strcpy(requestedMessagestr, sstr);
  12488. c = 0;
  12489. loc = strstr(sstrtemp, "connectorId");
  12490. if(loc == NULL)
  12491. {
  12492. connectorIdIsNULL = TRUE;
  12493. }
  12494. else
  12495. {
  12496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12497. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12498. {
  12499. sstr[c] = loc[strlen("connectorId")+2+c];
  12500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12501. c++;
  12502. }
  12503. sstr[c] = '\0';
  12504. connectorIdInt = atoi(sstr);
  12505. }
  12506. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12507. {
  12508. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12509. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12510. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12511. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12512. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12513. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12514. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12515. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12516. {
  12517. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12518. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12519. return TRUE;
  12520. }
  12521. else
  12522. {
  12523. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12524. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12525. }
  12526. }
  12527. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12528. {
  12529. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12530. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12531. return TRUE;
  12532. }
  12533. //==========================
  12534. // Trigger message
  12535. //==========================
  12536. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12537. {
  12538. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12539. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12540. {
  12541. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12542. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12543. }
  12544. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12545. }
  12546. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12547. {
  12548. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12549. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12550. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12551. }
  12552. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12553. {
  12554. //sendBootNotificationRequest();
  12555. server_sign = FALSE;
  12556. }
  12557. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12558. {
  12559. refreshStartTimer(&clientTime.Heartbeat);
  12560. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12561. }
  12562. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12563. {
  12564. if(connectorIdIsNULL == FALSE)
  12565. {
  12566. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12567. {
  12568. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12569. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12570. }
  12571. }
  12572. else
  12573. {
  12574. for(int idx=0;idx< gunTotalNumber;idx++)
  12575. {
  12576. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12577. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12578. }
  12579. }
  12580. }
  12581. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12582. {
  12583. if(connectorIdIsNULL == FALSE)
  12584. {
  12585. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12586. {
  12587. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12588. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12589. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12590. }
  12591. }
  12592. else
  12593. {
  12594. for(int idx=0;idx< gunTotalNumber;idx++)
  12595. {
  12596. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12597. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12598. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12599. }
  12600. }
  12601. }
  12602. return result;
  12603. }
  12604. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12605. {
  12606. mtrace();
  12607. int result = FAIL;
  12608. int connectorIdInt =0;
  12609. char comfirmstr[20]={0};
  12610. int tempIndex = 0;
  12611. json_object *UnlockConnector;
  12612. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12613. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12614. UnlockConnector = json_tokener_parse(payload);
  12615. if(!is_error(UnlockConnector))
  12616. {
  12617. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12618. {
  12619. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12620. }
  12621. }
  12622. json_object_put(UnlockConnector);
  12623. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12624. if(gunTotalNumber == 0)
  12625. {
  12626. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12627. goto end;
  12628. }
  12629. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12630. {
  12631. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12632. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12633. goto end;
  12634. }
  12635. else
  12636. {
  12637. //check Transaction active
  12638. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12639. {
  12640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12641. {
  12642. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12643. }
  12644. else
  12645. {
  12646. tempIndex = connectorIdInt -1;
  12647. }
  12648. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12649. {
  12650. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12651. {
  12652. //stop Transaction
  12653. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12654. }
  12655. }
  12656. }
  12657. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12658. {
  12659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12660. {
  12661. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12662. }
  12663. else
  12664. {
  12665. tempIndex = connectorIdInt -1;
  12666. }
  12667. for (int index = 0; index < CCS_QUANTITY; index++)
  12668. {
  12669. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12670. {
  12671. //stop Transaction
  12672. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12673. }
  12674. }
  12675. }
  12676. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12677. {
  12678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12679. {
  12680. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12681. }
  12682. else
  12683. {
  12684. tempIndex = connectorIdInt -1;
  12685. }
  12686. for (int index = 0; index < GB_QUANTITY; index++)
  12687. {
  12688. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12689. {
  12690. //stop Transaction
  12691. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12692. }
  12693. }
  12694. }
  12695. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12696. {
  12697. tempIndex = connectorIdInt -1;
  12698. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12699. {
  12700. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12701. {
  12702. //stop Transaction
  12703. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12704. }
  12705. }
  12706. }
  12707. else
  12708. {
  12709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12710. {
  12711. tempIndex = 2;
  12712. }
  12713. else
  12714. {
  12715. tempIndex = connectorIdInt-1;
  12716. }
  12717. for (int index = 0; index < AC_QUANTITY; index++)
  12718. {
  12719. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12720. {
  12721. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12722. }
  12723. }
  12724. }
  12725. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12726. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12727. result = TRUE;
  12728. return result;
  12729. }
  12730. end:
  12731. //json_object_put(obj); --- remove temporally
  12732. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12733. return result;
  12734. }
  12735. static char UpdateFirmwarepayloadData[300]={0};
  12736. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12737. {
  12738. mtrace();
  12739. int result = FAIL;
  12740. pthread_t t;
  12741. sendUpdateFirmwareConfirmation(uuid);
  12742. memset(UpdateFirmwarepayloadData, 0, 300);
  12743. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12744. if(!interLock.isUpdateFirmwareGoing)
  12745. {
  12746. interLock.isUpdateFirmwareGoing = 1;
  12747. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12748. sleep(1);
  12749. }
  12750. else
  12751. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12752. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12753. return result;
  12754. }
  12755. void *UpdateFirmwareProcess(void *data)
  12756. {
  12757. pthread_detach(pthread_self());
  12758. mtrace();
  12759. int retriesInt =0, retryIntervalInt=0;
  12760. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12761. int port=0;
  12762. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12763. int isSuccess = 0;
  12764. char ftpbuf[1024];
  12765. char temp[1024];
  12766. char * pch;
  12767. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12768. json_object *UpdateFirmware;
  12769. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12770. if(!is_error(UpdateFirmware))
  12771. {
  12772. // Required data
  12773. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12774. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12775. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12776. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12777. // Optional data
  12778. if(json_object_object_get(UpdateFirmware, "retries"))
  12779. {
  12780. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12781. }
  12782. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12783. {
  12784. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12785. }
  12786. }
  12787. json_object_put(UpdateFirmware);
  12788. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12789. memset(path, 0, ARRAY_SIZE(path));
  12790. // Wait retrieveData
  12791. if(strlen(retrieveDatestr) > 10)
  12792. {
  12793. do
  12794. {
  12795. sleep(1);
  12796. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12797. }
  12798. // Ready to download
  12799. system("rm -f /mnt/*");
  12800. if(strncmp(locationstr,"http", 4) == 0)
  12801. {
  12802. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12803. sprintf(ftppath,"/%s", path);
  12804. DEBUG_INFO("locationstr: %s\n", locationstr);
  12805. DEBUG_INFO("protocol: %s\n",protocol);
  12806. DEBUG_INFO("host: %s\n",host);
  12807. DEBUG_INFO("path: %s\n",path);
  12808. DEBUG_INFO("ftppath: %s\n",ftppath);
  12809. int ftppathlen=strlen(ftppath);
  12810. int i=1;
  12811. char filenametemp[50];
  12812. while(i < ftppathlen)
  12813. {
  12814. int len=ftppathlen-i;
  12815. if(ftppath[len]== 47) // '/' ascll code: 47
  12816. {
  12817. DEBUG_INFO("compare '/' all right\n");
  12818. break;
  12819. }
  12820. i=i+1;
  12821. }
  12822. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12823. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12824. filenametemp[i+1] = 0;
  12825. do
  12826. {
  12827. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12828. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12829. sleep(1);
  12830. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12831. if(!isSuccess)
  12832. {
  12833. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12834. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12835. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12836. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12837. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12838. }
  12839. else
  12840. {
  12841. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12842. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12843. }
  12844. retriesInt--;
  12845. }while((isSuccess == 0)&&(retriesInt >= 0));
  12846. }
  12847. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12848. {
  12849. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12850. memset(temp, 0, ARRAY_SIZE(temp));
  12851. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12852. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12853. int ftppathlen=strlen(ftpbuf);
  12854. int i=1;
  12855. char filenametemp[50];
  12856. while(i < ftppathlen)
  12857. {
  12858. int len=ftppathlen-i;
  12859. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12860. {
  12861. DEBUG_INFO(" compare '/' all right\n");
  12862. break;
  12863. }
  12864. i=i+1;
  12865. }
  12866. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12867. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12868. filenametemp[i+1] = 0;
  12869. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12870. pch=strchr(temp,'@');
  12871. if(pch==NULL)
  12872. {
  12873. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12874. protocol, host, &port, path);
  12875. strcpy(user,"anonymous");
  12876. strcpy(password,"");
  12877. }
  12878. else
  12879. {
  12880. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12881. protocol, user, password, host, &port, path);
  12882. }
  12883. sscanf(host,"%[^/]%s",host1, path1);
  12884. sprintf(ftppath,"%s", path1);
  12885. //DEBUG_INFO("protocol =%s\n",protocol);
  12886. //DEBUG_INFO("user =%s\n",user);
  12887. //DEBUG_INFO("password =%s\n",password);
  12888. //DEBUG_INFO("host1 =%s\n",host1);
  12889. //DEBUG_INFO("port =%d\n",port);
  12890. //DEBUG_INFO("path1 =%s\n",path1);
  12891. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12892. //ftpFile(host, user, password, port, ftppath, fname);
  12893. //download firmware pthred
  12894. if(port == 0)
  12895. {
  12896. port = 21;
  12897. }
  12898. do
  12899. {
  12900. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12901. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12902. sleep(1);
  12903. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12904. if(!isSuccess)
  12905. {
  12906. //BulldogUtil.sleepMs(interval*1000);
  12907. DEBUG_INFO("Update firmware request and download file fail.\n");
  12908. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12909. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12910. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12911. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12912. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12913. }
  12914. else
  12915. {
  12916. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12917. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12918. }
  12919. retriesInt--;
  12920. }while((!isSuccess)&&(retriesInt >= 0));
  12921. }
  12922. else
  12923. {
  12924. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12925. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12926. sleep(1);
  12927. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12928. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12929. }
  12930. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12931. interLock.isUpdateFirmwareGoing = 0;
  12932. pthread_exit(NULL);
  12933. }
  12934. int handleCertificateSignedRequest(char *uuid, char *payload)
  12935. {
  12936. mtrace();
  12937. int result = PASS;
  12938. json_object *CertificateSigned;
  12939. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12940. CertificateSigned = json_tokener_parse(payload);
  12941. if(!is_error(CertificateSigned))
  12942. {
  12943. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12944. }
  12945. json_object_put(CertificateSigned);
  12946. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12947. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12948. fclose(fp);
  12949. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12950. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12951. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12952. sendCertificateSignedConfirmation(uuid);
  12953. return result;
  12954. }
  12955. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12956. {
  12957. mtrace();
  12958. int result = PASS;
  12959. json_object *DeleteCertificate;
  12960. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12961. DeleteCertificate = json_tokener_parse(payload);
  12962. if(!is_error(DeleteCertificate))
  12963. {
  12964. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12965. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12966. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12967. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12968. }
  12969. json_object_put(DeleteCertificate);
  12970. /*
  12971. * TODO: Delete certificateSigned process
  12972. */
  12973. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12974. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12975. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12976. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12977. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12978. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12979. sendDeleteCertificateConfirmation(uuid);
  12980. return result;
  12981. }
  12982. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12983. {
  12984. mtrace();
  12985. int result = PASS;
  12986. json_object *ExtendedTriggerMessage;
  12987. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12988. ExtendedTriggerMessage = json_tokener_parse(payload);
  12989. if(!is_error(ExtendedTriggerMessage))
  12990. {
  12991. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12992. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12993. {
  12994. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12995. }
  12996. else
  12997. {
  12998. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12999. }
  13000. }
  13001. json_object_put(ExtendedTriggerMessage);
  13002. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13003. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13004. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13005. {
  13006. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13007. }
  13008. else
  13009. {
  13010. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13011. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13012. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13013. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13014. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13015. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13016. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13017. {
  13018. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13019. }
  13020. else
  13021. {
  13022. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13023. }
  13024. }
  13025. sendExtendedTriggerMessageConfirmation(uuid);
  13026. //==========================
  13027. // Trigger message
  13028. //==========================
  13029. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13030. {
  13031. //sendBootNotificationRequest();
  13032. server_sign = FALSE;
  13033. }
  13034. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13035. {
  13036. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13037. }
  13038. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13039. {
  13040. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13041. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13042. {
  13043. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13044. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13045. }
  13046. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13047. }
  13048. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13049. {
  13050. refreshStartTimer(&clientTime.Heartbeat);
  13051. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13052. }
  13053. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13054. {
  13055. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13056. {
  13057. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13058. }
  13059. else
  13060. {
  13061. for(int idx=0;idx< gunTotalNumber;idx++)
  13062. {
  13063. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13064. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13065. }
  13066. }
  13067. }
  13068. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13069. {
  13070. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13071. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13072. {
  13073. 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\" &");
  13074. }
  13075. }
  13076. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13077. {
  13078. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13079. {
  13080. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13081. }
  13082. else
  13083. {
  13084. for(int idx=0;idx< gunTotalNumber;idx++)
  13085. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13086. }
  13087. }
  13088. return result;
  13089. }
  13090. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13091. {
  13092. mtrace();
  13093. int result = PASS;
  13094. json_object *GetInstalledCertificateIds;
  13095. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13096. GetInstalledCertificateIds = json_tokener_parse(payload);
  13097. if(!is_error(GetInstalledCertificateIds))
  13098. {
  13099. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13100. }
  13101. json_object_put(GetInstalledCertificateIds);
  13102. /*
  13103. * TODO: Return installed certificate process
  13104. */
  13105. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13106. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13107. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13108. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13109. sendGetInstalledCertificateIdsConfirmation(uuid);
  13110. return result;
  13111. }
  13112. int handleGetLogRequest(char *uuid, char *payload)
  13113. {
  13114. mtrace();
  13115. int result = PASS;
  13116. json_object *GetLog;
  13117. DEBUG_INFO("handleGetLogRequest...\n");
  13118. GetLog = json_tokener_parse(payload);
  13119. if(!is_error(GetLog))
  13120. {
  13121. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13122. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13123. if(json_object_object_get(GetLog, "retries") != NULL)
  13124. {
  13125. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13126. }
  13127. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13128. {
  13129. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13130. }
  13131. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13132. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13133. {
  13134. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13135. }
  13136. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13137. {
  13138. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13139. }
  13140. }
  13141. json_object_put(GetLog);
  13142. /*
  13143. * TODO: Upload log process
  13144. */
  13145. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13146. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13147. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13148. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13149. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13150. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13151. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13152. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13153. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13154. sendGetLogConfirmation(uuid);
  13155. return result;
  13156. }
  13157. int handleInstallCertificateRequest(char *uuid, char *payload)
  13158. {
  13159. mtrace();
  13160. int result = PASS;
  13161. json_object *InstallCertificate;
  13162. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13163. InstallCertificate = json_tokener_parse(payload);
  13164. if(!is_error(InstallCertificate))
  13165. {
  13166. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13167. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13168. /*
  13169. * TODO: Install certificate process
  13170. */
  13171. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13172. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13173. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13174. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13175. sendInstallCertificateConfirmation(uuid);
  13176. }
  13177. json_object_put(InstallCertificate);
  13178. return result;
  13179. }
  13180. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13181. {
  13182. mtrace();
  13183. int result = PASS;
  13184. json_object *SignedUpdateFirmware;
  13185. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13186. SignedUpdateFirmware = json_tokener_parse(payload);
  13187. if(!is_error(SignedUpdateFirmware))
  13188. {
  13189. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13190. {
  13191. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13192. }
  13193. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13194. {
  13195. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13196. }
  13197. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13198. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13199. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13200. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13201. {
  13202. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13203. }
  13204. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13205. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13206. }
  13207. json_object_put(SignedUpdateFirmware);
  13208. /*
  13209. * TODO: Upgrade firmware process
  13210. */
  13211. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13212. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13213. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13214. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13215. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13216. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13217. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13218. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13219. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13220. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13221. sendInstallCertificateConfirmation(uuid);
  13222. return result;
  13223. }
  13224. int handleUnknownRequest(char *uuid, char *payload)
  13225. {
  13226. mtrace();
  13227. int result = PASS;
  13228. DEBUG_INFO("handleUnknownRequest...\n");
  13229. sendUnknownConfirmation(uuid);
  13230. result = PASS;
  13231. return result;
  13232. }
  13233. //==========================================
  13234. // Handle server response routine
  13235. //==========================================
  13236. void handleAuthorizeResponse(char *payload, int gun_index)
  13237. {
  13238. mtrace();
  13239. char expiryDatestr[30]={0};
  13240. char parentIdTagstr[20]={0};
  13241. char statusstr[20]={0};
  13242. int expiryDateISNULL=FALSE;
  13243. int parentIdTagISNULL=FALSE;
  13244. DEBUG_INFO("handleAuthorizeResponse...\n");
  13245. json_object *Authorize;
  13246. Authorize = json_tokener_parse(payload);
  13247. if(!is_error(Authorize))
  13248. {
  13249. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13250. {
  13251. // Required data
  13252. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13253. // Optional data
  13254. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13255. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13256. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13257. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13258. }
  13259. }
  13260. json_object_put(Authorize);
  13261. if(expiryDateISNULL == FALSE)
  13262. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13263. if(parentIdTagISNULL == FALSE)
  13264. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13265. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13266. //Update idTag information to authorization cache if supproted
  13267. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13268. {
  13269. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13270. }
  13271. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13272. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13273. authorizeRetryTimes = 0;
  13274. }
  13275. void handleBootNotificationResponse(char *payload, int gun_index)
  13276. {
  13277. mtrace();
  13278. char statusStr[12]={0};
  13279. char currentTimeStr[30]={0};
  13280. int intervalInt = 0;
  13281. DEBUG_INFO("handleBootNotificationResponse...\n");
  13282. json_object *BootNotification;
  13283. BootNotification = json_tokener_parse(payload);
  13284. if(!is_error(BootNotification))
  13285. {
  13286. // Required data
  13287. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13288. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13289. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13290. }
  13291. json_object_put(BootNotification);
  13292. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13293. BootNotificationInterval = intervalInt;
  13294. //write back to ShmOCPP16Data->BootNotification
  13295. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13296. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13297. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13298. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13299. {
  13300. if((intervalInt == 0) || (intervalInt >= 10))
  13301. {
  13302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13303. HeartBeatWaitTime = intervalInt;
  13304. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13305. }
  13306. server_sign = TRUE;
  13307. server_pending =FALSE;
  13308. }
  13309. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13310. {
  13311. server_pending = TRUE;
  13312. }
  13313. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13314. srand(time(NULL));
  13315. refreshStartTimer(&clientTime.Heartbeat);
  13316. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13317. SetOcppConnStatus(TRUE);
  13318. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13319. }
  13320. void handleDataTransferResponse(char *payload, int gun_index)
  13321. {
  13322. json_object *DataTransfer = json_tokener_parse(payload);
  13323. if(!is_error(DataTransfer))
  13324. {
  13325. // Required data
  13326. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13327. // Optional data
  13328. if(json_object_object_get(DataTransfer, "data") != NULL)
  13329. {
  13330. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13331. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13332. if(!is_error(Data))
  13333. {
  13334. if(json_object_object_get(Data, "msgId") != NULL)
  13335. {
  13336. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13337. {
  13338. 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")));
  13339. }
  13340. }
  13341. }
  13342. json_object_put(Data);
  13343. }
  13344. }
  13345. json_object_put(DataTransfer);
  13346. }
  13347. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13348. {
  13349. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13350. //struct json_object *obj;
  13351. // obj = json_tokener_parse(payload);
  13352. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13353. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13354. //No fields are defined.
  13355. }
  13356. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13357. {
  13358. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13359. //struct json_object *obj;
  13360. // obj = json_tokener_parse(payload);
  13361. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13362. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13363. //No fields are defined.
  13364. }
  13365. void handleHeartbeatResponse(char *payload, int gun_index)
  13366. {
  13367. mtrace();
  13368. DEBUG_INFO("handleHeartbeatResponse...\n");
  13369. json_object *Heartbeat;
  13370. Heartbeat = json_tokener_parse(payload);
  13371. if(!is_error(Heartbeat))
  13372. {
  13373. // Required data
  13374. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13375. }
  13376. json_object_put(Heartbeat);
  13377. if(FirstHeartBeat == 0)
  13378. {
  13379. FirstHeartBeat = 1;
  13380. DEBUG_INFO("FirstHeartBeat \n");
  13381. }
  13382. HeartBeatWithNOResponse = 0;
  13383. refreshStartTimer(&clientTime.Heartbeat);
  13384. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13385. }
  13386. void handleMeterValuesResponse(char *payload, int gun_index)
  13387. {
  13388. mtrace();
  13389. DEBUG_INFO("handleMeterValuesResponse...\n");
  13390. isQueueSendable = 1;
  13391. }
  13392. void handleStartTransactionResponse(char *payload, int gun_index)
  13393. {
  13394. mtrace();
  13395. //int transactionIdInt = 0;
  13396. FILE *outfile;
  13397. char data[100]={0};
  13398. DEBUG_INFO("handleStartTransactionResponse...\n");
  13399. json_object *StartTransaction;
  13400. StartTransaction = json_tokener_parse(payload);
  13401. if(!is_error(StartTransaction))
  13402. {
  13403. // Required data
  13404. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13405. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13406. // Optional data
  13407. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13408. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13409. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13410. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13411. }
  13412. json_object_put(StartTransaction);
  13413. isQueueSendable = 1;
  13414. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13415. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13416. //-----------Start : write to the Queue TransactionId file -----------------//
  13417. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13418. {}
  13419. else
  13420. {
  13421. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13422. if(log == NULL)
  13423. {
  13424. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13425. return ;
  13426. }
  13427. else
  13428. {
  13429. fclose(log);
  13430. }
  13431. }
  13432. // open file for writing
  13433. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13434. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13435. {
  13436. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13437. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13438. fputs(data, outfile);
  13439. fclose (outfile);
  13440. }
  13441. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13442. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13443. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13444. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13445. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13446. }
  13447. void handleStatusNotificationResponse(char *payload, int gun_index)
  13448. {
  13449. mtrace();
  13450. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13451. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13452. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13453. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13454. }
  13455. void handleStopTransactionnResponse(char *payload, int gun_index)
  13456. {
  13457. mtrace();
  13458. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13459. json_object *StopTransaction;
  13460. StopTransaction = json_tokener_parse(payload);
  13461. if(!is_error(StopTransaction))
  13462. {
  13463. // Optional data
  13464. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13465. {
  13466. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13467. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13469. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13470. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13471. }
  13472. }
  13473. json_object_put(StopTransaction);
  13474. isQueueSendable = 1;
  13475. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13476. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13477. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13478. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13479. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13480. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13481. }
  13482. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13483. {
  13484. mtrace();
  13485. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13486. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13487. }
  13488. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13489. {
  13490. mtrace();
  13491. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13492. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13493. }
  13494. void handleSignCertificateResponse(char *payload, int gun_index)
  13495. {
  13496. mtrace();
  13497. DEBUG_INFO("handleSignCertificateResponse...\n");
  13498. json_object *SignCertificate;
  13499. SignCertificate = json_tokener_parse(payload);
  13500. if(!is_error(SignCertificate))
  13501. {
  13502. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13503. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13504. }
  13505. json_object_put(SignCertificate);
  13506. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13507. }
  13508. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13509. {
  13510. mtrace();
  13511. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13512. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13513. }
  13514. //==========================================
  13515. // Handle Error routine
  13516. //==========================================
  13517. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13518. {
  13519. mtrace();
  13520. #ifdef SystemLogMessage
  13521. DEBUG_INFO("errorCode: %s\n", errorCode);
  13522. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13523. DEBUG_INFO("errorDetails: %s\n", payload);
  13524. #endif
  13525. }
  13526. //===============================================
  13527. // Common routine
  13528. //===============================================
  13529. int initialConfigurationTable(void)
  13530. {
  13531. //clock_t start_t, end_t, total_t;
  13532. FILE *fp;
  13533. FILE *outfile;
  13534. char str[512]={0};
  13535. char sstr[256]={0};
  13536. int c = 0;
  13537. char *loc;
  13538. int confVersion = 13;
  13539. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13540. //start_t = clock();
  13541. //printf("Starting of the program, start_t = %ld\n", start_t);
  13542. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13543. // Check configuration file size is correct
  13544. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13545. {
  13546. struct stat st;
  13547. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13548. if(st.st_size < 3100)
  13549. {
  13550. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13551. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13552. }
  13553. }
  13554. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13555. {
  13556. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13557. if(outfile == NULL)
  13558. {
  13559. DEBUG_INFO("Error opening file\n");
  13560. return FALSE;
  13561. }
  13562. /*Core Profile*/
  13563. //AllowOfflineTxForUnknownId
  13564. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13568. //AuthorizationCacheEnabled
  13569. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13573. //AuthorizeRemoteTxRequests
  13574. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13578. //BlinkRepeat
  13579. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13583. //ClockAlignedDataInterval
  13584. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13588. //ConnectionTimeOut
  13589. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13593. //GetConfigurationMaxKeys
  13594. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13598. // HeartbeatInterval
  13599. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13603. // LightIntensity
  13604. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13608. // LocalAuthorizeOffline
  13609. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13613. // LocalPreAuthorize
  13614. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13618. // MaxEnergyOnInvalidId
  13619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13623. // MeterValuesAlignedData
  13624. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13626. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13627. 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" );
  13628. else
  13629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13631. // MeterValuesAlignedDataMaxLength
  13632. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13636. else
  13637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13639. // MeterValuesSampledData
  13640. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13642. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13643. 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" );
  13644. else
  13645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13647. // MeterValuesSampledDataMaxLength
  13648. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13650. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13652. else
  13653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13655. // MeterValueSampleInterval
  13656. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13660. // MinimumStatusDuration
  13661. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13664. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13666. // NumberOfConnectors
  13667. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13670. {
  13671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13672. }
  13673. else
  13674. {
  13675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13676. }
  13677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13678. // ResetRetries
  13679. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13683. // ConnectorPhaseRotation
  13684. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13688. // ConnectorPhaseRotationMaxLength
  13689. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13693. // StopTransactionOnEVSideDisconnect
  13694. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13698. // StopTransactionOnInvalidId
  13699. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13703. // StopTxnAlignedData
  13704. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13708. // StopTxnAlignedDataMaxLength
  13709. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13713. // StopTxnSampledData
  13714. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13716. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13718. else
  13719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13721. // StopTxnSampledDataMaxLength
  13722. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13725. {
  13726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13727. }
  13728. else
  13729. {
  13730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13731. }
  13732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13733. // SupportedFeatureProfiles
  13734. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13738. // SupportedFeatureProfilesMaxLength
  13739. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13743. // TransactionMessageAttempts
  13744. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13747. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13749. // TransactionMessageRetryInterval
  13750. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13753. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13755. // UnlockConnectorOnEVSideDisconnect
  13756. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13760. // WebSocketPingInterval
  13761. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13765. // QueueOffLineMeterValues
  13766. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13770. // AuthorizationKey
  13771. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13775. // SecurityProfile
  13776. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13780. // DefaultPrice
  13781. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13785. // CustomDisplayCostAndPrice
  13786. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13790. // CustomIdleFeeAfterStop
  13791. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13795. // TimeOffset
  13796. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13800. // NextTimeOffsetTransitionDateTime
  13801. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13805. // TimeOffsetNextTransition
  13806. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13810. // SystemUptimeSec
  13811. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13815. // FreeVend
  13816. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13820. // FreeVendIdtag
  13821. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13825. // OcppServer
  13826. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13828. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13830. // MaintainServer
  13831. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13833. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13835. // StatusNotificationPeriodically
  13836. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13840. // StatusNotificationInterval
  13841. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13845. // Configuration Version
  13846. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13850. //* Local Auth List Management Profile*/
  13851. #if 0
  13852. //For OCTT Test Case
  13853. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13856. #endif
  13857. #if 1
  13858. //LocalAuthListEnabled
  13859. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13863. #endif
  13864. //LocalAuthListMaxLength
  13865. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13869. //SendLocalListMaxLength
  13870. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13874. //ReserveConnectorZeroSupported
  13875. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13879. //* Smart Charging Profile */
  13880. //ChargeProfileMaxStackLevel
  13881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13885. // ChargingScheduleAllowedChargingRateUnit
  13886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13890. // ChargingScheduleMaxPeriods
  13891. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13895. // ConnectorSwitch3to1PhaseSupported
  13896. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13900. // MaxChargingProfilesInstalled
  13901. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13905. fclose(outfile);
  13906. }
  13907. else
  13908. {
  13909. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13910. char keystr[60]={0};
  13911. char readonlystr[10]={0};
  13912. char valuestr[256]={0};
  13913. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13914. if(fp == NULL) {
  13915. DEBUG_INFO("Error opening file");
  13916. return FALSE;
  13917. }
  13918. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13919. {
  13920. //DEBUG_INFO("Get Configuration \n");
  13921. if(strlen(str) > 0)
  13922. {
  13923. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13924. //*************************key*********************************/
  13925. if(strstr(str, "key") != NULL)
  13926. {
  13927. loc = strstr(str, "key");
  13928. c = 0;
  13929. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13930. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13931. {
  13932. sstr[c] = loc[strlen("key")+3+c];
  13933. c++;
  13934. }
  13935. sstr[c] = '\0';
  13936. strcpy(keystr,sstr);
  13937. }
  13938. //*************************readonly*********************************/
  13939. if(strstr(str, "readonly") != NULL)
  13940. {
  13941. loc = strstr(str, "readonly");
  13942. c = 0;
  13943. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13944. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13945. {
  13946. sstr[c] = loc[strlen("readonly")+2+c];
  13947. c++;
  13948. }
  13949. sstr[c] = '\0';
  13950. strcpy(readonlystr,sstr);
  13951. }
  13952. //*************************value*********************************/
  13953. if(strstr(str, "value") != NULL)
  13954. {
  13955. loc = strstr(str, "value");
  13956. c = 0;
  13957. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13958. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13959. {
  13960. sstr[c] = loc[strlen("value")+3+c];
  13961. c++;
  13962. }
  13963. sstr[c] = '\0';
  13964. strcpy(valuestr,sstr);
  13965. }
  13966. // DEBUG_INFO("keystr=%s\n",keystr);
  13967. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13968. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13969. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13970. {
  13971. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13972. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13974. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13975. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13976. }
  13977. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13978. {
  13979. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13980. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13982. }
  13983. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13984. {
  13985. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13987. }
  13988. if(strcmp(keystr, "BlinkRepeat") == 0)
  13989. {
  13990. //Charger.BlinkRepeat = Integer.parseInt(value);
  13991. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13993. }
  13994. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13995. {
  13996. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13998. }
  13999. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14000. {
  14001. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14003. }
  14004. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14005. {
  14006. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14008. }
  14009. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14010. {
  14011. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14013. HeartBeatWaitTime = atoi(valuestr);
  14014. }
  14015. if(strcmp(keystr, "LightIntensity") == 0)
  14016. {
  14017. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14019. }
  14020. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14021. {
  14022. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14024. }
  14025. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14026. {
  14027. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14029. }
  14030. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14031. {
  14032. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14034. }
  14035. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14036. {
  14037. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14039. }
  14040. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14041. {
  14042. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14044. }
  14045. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14046. {
  14047. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14049. }
  14050. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14051. {
  14052. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14054. }
  14055. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14056. {
  14057. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14059. }
  14060. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14061. {
  14062. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14064. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14065. }
  14066. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14067. {
  14068. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14070. }
  14071. if(strcmp(keystr, "ResetRetries") == 0)
  14072. {
  14073. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14075. }
  14076. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14077. {
  14078. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14080. }
  14081. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14082. {
  14083. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14085. }
  14086. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14087. {
  14088. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14090. }
  14091. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14092. {
  14093. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14095. }
  14096. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14097. {
  14098. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14100. }
  14101. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14102. {
  14103. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14105. }
  14106. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14107. {
  14108. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14110. }
  14111. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14112. {
  14113. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14115. }
  14116. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14117. {
  14118. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14120. }
  14121. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14122. {
  14123. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14125. }
  14126. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14127. {
  14128. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14130. TransactionMessageAttemptsValue = atoi(valuestr);
  14131. }
  14132. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14133. {
  14134. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14136. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14137. }
  14138. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14139. {
  14140. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14142. }
  14143. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14144. {
  14145. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14147. }
  14148. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14149. {
  14150. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14152. }
  14153. if(strcmp(keystr, "AuthorizationKey") == 0)
  14154. {
  14155. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14156. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14158. }
  14159. if(strcmp(keystr, "SecurityProfile") == 0)
  14160. {
  14161. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14163. }
  14164. if(strcmp(keystr, "DefaultPrice") == 0)
  14165. {
  14166. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14168. }
  14169. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14170. {
  14171. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14173. }
  14174. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14175. {
  14176. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14178. }
  14179. if(strcmp(keystr, "TimeOffset") == 0)
  14180. {
  14181. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14183. }
  14184. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14185. {
  14186. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14188. }
  14189. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14190. {
  14191. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14193. }
  14194. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14195. {
  14196. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14198. }
  14199. if(strcmp(keystr, "FreeVend") == 0)
  14200. {
  14201. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14203. }
  14204. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14205. {
  14206. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14208. }
  14209. if(strcmp(keystr, "OcppServer") == 0)
  14210. {
  14211. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14212. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14213. }
  14214. if(strcmp(keystr, "MaintainServer") == 0)
  14215. {
  14216. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14217. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14218. }
  14219. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14220. {
  14221. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14223. }
  14224. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14225. {
  14226. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14228. }
  14229. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14230. {
  14231. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14233. }
  14234. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14235. {
  14236. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14238. }
  14239. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14240. {
  14241. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14243. }
  14244. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14245. {
  14246. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14248. }
  14249. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14250. {
  14251. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14253. }
  14254. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14255. {
  14256. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14258. }
  14259. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14260. {
  14261. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14263. }
  14264. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14265. {
  14266. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14268. }
  14269. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14270. {
  14271. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14273. }
  14274. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14275. {
  14276. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14278. }
  14279. }
  14280. }
  14281. fclose(fp);
  14282. }
  14283. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14284. {
  14285. return PASS;
  14286. }
  14287. else
  14288. {
  14289. return FAIL;
  14290. }
  14291. }
  14292. void StoreConfigurationTable(void)
  14293. {
  14294. FILE *outfile;
  14295. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14296. if(outfile == NULL)
  14297. {
  14298. DEBUG_INFO("Error opening file");
  14299. return ;
  14300. }
  14301. /*Core Profile*/
  14302. //AllowOfflineTxForUnknownId
  14303. /*
  14304. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14305. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14308. */
  14309. //DEBUG_INFO("data=%s\n",data);
  14310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14311. //AuthorizationCacheEnabled
  14312. /*
  14313. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14316. */
  14317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14318. //AuthorizeRemoteTxRequests
  14319. /*
  14320. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14323. */
  14324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14325. //BlinkRepeat
  14326. /*
  14327. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14330. */
  14331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14332. //ClockAlignedDataInterval
  14333. /*
  14334. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14337. */
  14338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14339. //ConnectionTimeOut
  14340. /*
  14341. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14344. */
  14345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14346. //GetConfigurationMaxKeys
  14347. /*
  14348. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14351. */
  14352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14353. // HeartbeatInterval
  14354. /*
  14355. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14358. */
  14359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14360. // LightIntensity
  14361. /*
  14362. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14365. */
  14366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14367. // LocalAuthorizeOffline
  14368. /*
  14369. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14372. */
  14373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14374. // LocalPreAuthorize
  14375. /*
  14376. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14379. */
  14380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14381. // MaxEnergyOnInvalidId
  14382. /*
  14383. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14386. */
  14387. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14389. // MeterValuesAlignedData
  14390. /*
  14391. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14394. */
  14395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14396. // MeterValuesAlignedDataMaxLength
  14397. /*
  14398. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14401. */
  14402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14403. // MeterValuesSampledData
  14404. /*
  14405. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14408. */
  14409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14410. // MeterValuesSampledDataMaxLength
  14411. /*
  14412. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14415. */
  14416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14417. // MeterValueSampleInterval
  14418. /*
  14419. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14422. */
  14423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14424. // MinimumStatusDuration
  14425. /*
  14426. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14429. */
  14430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14431. // NumberOfConnectors
  14432. /*
  14433. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14436. {
  14437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14438. }
  14439. else
  14440. {
  14441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14442. }
  14443. */
  14444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14445. // ResetRetries
  14446. /*
  14447. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14450. */
  14451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14452. // ConnectorPhaseRotation
  14453. /*
  14454. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14457. */
  14458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14459. // ConnectorPhaseRotationMaxLength
  14460. /*
  14461. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14464. */
  14465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14466. // StopTransactionOnEVSideDisconnect
  14467. /*
  14468. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14471. */
  14472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14473. // StopTransactionOnInvalidId
  14474. /*
  14475. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14478. */
  14479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14480. // StopTxnAlignedData
  14481. /*
  14482. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14485. */
  14486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14487. // StopTxnAlignedDataMaxLength
  14488. /*
  14489. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14492. */
  14493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14494. // StopTxnSampledData
  14495. /*
  14496. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14499. */
  14500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14501. // StopTxnSampledDataMaxLength
  14502. /*
  14503. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14506. */
  14507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14508. // SupportedFeatureProfiles
  14509. /*
  14510. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14513. */
  14514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14515. // SupportedFeatureProfilesMaxLength
  14516. /*
  14517. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14520. */
  14521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14522. // TransactionMessageAttempts
  14523. /*
  14524. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14527. */
  14528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14529. // TransactionMessageRetryInterval
  14530. /*
  14531. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14534. */
  14535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14536. // UnlockConnectorOnEVSideDisconnect
  14537. /*
  14538. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14541. */
  14542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14543. // WebSocketPingInterval
  14544. /*
  14545. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14548. */
  14549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14550. // QueueOffLineMeterValues
  14551. /*
  14552. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14555. */
  14556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14557. // AuthorizationKey
  14558. /*
  14559. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14562. */
  14563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14564. // SecurityProfile
  14565. /*
  14566. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14569. */
  14570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14571. // DefaultPrice
  14572. /*
  14573. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14576. */
  14577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14578. // CustomDisplayCostAndPrice
  14579. /*
  14580. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14583. */
  14584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14585. // CustomIdleFeeAfterStop
  14586. /*
  14587. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14590. */
  14591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14592. // TimeOffset
  14593. /*
  14594. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14597. */
  14598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14599. // NextTimeOffsetTransitionDateTime
  14600. /*
  14601. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14604. */
  14605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14606. // TimeOffsetNextTransition
  14607. /*
  14608. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14611. */
  14612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14613. // SystemUptimeSec
  14614. /*
  14615. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14618. */
  14619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14620. // FreeVend
  14621. /*
  14622. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14625. */
  14626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14627. // FreeVendIdtag
  14628. /*
  14629. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14632. */
  14633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14634. // OcppServer
  14635. /*
  14636. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14639. */
  14640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14641. // MaintainServer
  14642. /*
  14643. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14646. */
  14647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14648. // StatusNotificationPeriodically
  14649. /*
  14650. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14653. */
  14654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14655. // StatusNotificationInterval
  14656. /*
  14657. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14660. */
  14661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14662. // ConfigurationVersion
  14663. /*
  14664. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14667. */
  14668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14669. //* Local Auth List Management Profile*/
  14670. //LocalAuthListEnabled
  14671. /*
  14672. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14675. */
  14676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14677. //LocalAuthListMaxLength
  14678. /*
  14679. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14682. */
  14683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14684. //SendLocalListMaxLength
  14685. /*
  14686. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14689. */
  14690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14691. //ReserveConnectorZeroSupported
  14692. /*
  14693. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14696. */
  14697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14698. //* Smart Charging Profile */
  14699. //ChargeProfileMaxStackLevel
  14700. /*
  14701. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14704. */
  14705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14706. // ChargingScheduleAllowedChargingRateUnit
  14707. /*
  14708. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14711. */
  14712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14713. // ChargingScheduleMaxPeriods
  14714. /*
  14715. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14718. */
  14719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14720. // ConnectorSwitch3to1PhaseSupported
  14721. /*
  14722. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14725. */
  14726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14727. // MaxChargingProfilesInstalled
  14728. /*
  14729. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14732. */
  14733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14734. fclose(outfile);
  14735. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14736. }
  14737. void getKeyValue(char *keyReq)
  14738. {
  14739. int isEmpty = FALSE;
  14740. int isKnowKey = FALSE;
  14741. DEBUG_INFO("keyReq = %s\n", keyReq);
  14742. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14743. isEmpty = TRUE;
  14744. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14745. {
  14746. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14749. {
  14750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14751. }
  14752. else
  14753. {
  14754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14755. }
  14756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14757. isKnowKey = TRUE;
  14758. }
  14759. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14760. {
  14761. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14763. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14764. {
  14765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14766. }
  14767. else
  14768. {
  14769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14770. }
  14771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14772. isKnowKey = TRUE;
  14773. }
  14774. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14775. {
  14776. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14779. {
  14780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14781. }
  14782. else
  14783. {
  14784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14785. }
  14786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14787. isKnowKey = TRUE;
  14788. }
  14789. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14790. {
  14791. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14794. {
  14795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14796. }
  14797. else
  14798. {
  14799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14800. }
  14801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14802. isKnowKey = TRUE;
  14803. }
  14804. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14805. {
  14806. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14809. {
  14810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14811. }
  14812. else
  14813. {
  14814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14815. }
  14816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14817. isKnowKey = TRUE;
  14818. }
  14819. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14820. {
  14821. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14824. {
  14825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14826. }
  14827. else
  14828. {
  14829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14830. }
  14831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14832. isKnowKey = TRUE;
  14833. }
  14834. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14835. {
  14836. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14839. {
  14840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14841. }
  14842. else
  14843. {
  14844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14845. }
  14846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14847. isKnowKey = TRUE;
  14848. }
  14849. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14850. {
  14851. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14854. {
  14855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14856. }
  14857. else
  14858. {
  14859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14860. }
  14861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14862. isKnowKey = TRUE;
  14863. }
  14864. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14865. {
  14866. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14869. {
  14870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14871. }
  14872. else
  14873. {
  14874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14875. }
  14876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14877. isKnowKey = TRUE;
  14878. }
  14879. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14880. {
  14881. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14884. {
  14885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14886. }
  14887. else
  14888. {
  14889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14890. }
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14892. isKnowKey = TRUE;
  14893. }
  14894. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14895. {
  14896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14899. {
  14900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14901. }
  14902. else
  14903. {
  14904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14905. }
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14907. isKnowKey = TRUE;
  14908. }
  14909. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14910. {
  14911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14914. {
  14915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14916. }
  14917. else
  14918. {
  14919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14920. }
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14922. isKnowKey = TRUE;
  14923. }
  14924. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14925. {
  14926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14929. {
  14930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14931. }
  14932. else
  14933. {
  14934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14935. }
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14937. isKnowKey = TRUE;
  14938. }
  14939. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14940. {
  14941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14944. {
  14945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14946. }
  14947. else
  14948. {
  14949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14950. }
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14952. isKnowKey = TRUE;
  14953. }
  14954. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14955. {
  14956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14959. {
  14960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14961. }
  14962. else
  14963. {
  14964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14965. }
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14967. isKnowKey = TRUE;
  14968. }
  14969. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14970. {
  14971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14974. {
  14975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14976. }
  14977. else
  14978. {
  14979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14980. }
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14982. isKnowKey = TRUE;
  14983. }
  14984. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14985. {
  14986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14989. {
  14990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14991. }
  14992. else
  14993. {
  14994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14995. }
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14997. isKnowKey = TRUE;
  14998. }
  14999. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15000. {
  15001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15004. {
  15005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15006. }
  15007. else
  15008. {
  15009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15010. }
  15011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15012. isKnowKey = TRUE;
  15013. }
  15014. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15015. {
  15016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15019. {
  15020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15021. }
  15022. else
  15023. {
  15024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15025. }
  15026. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15028. isKnowKey = TRUE;
  15029. }
  15030. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15031. {
  15032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15035. {
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15037. }
  15038. else
  15039. {
  15040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15041. }
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15043. isKnowKey = TRUE;
  15044. }
  15045. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15046. {
  15047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15050. {
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15052. }
  15053. else
  15054. {
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15056. }
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15058. isKnowKey = TRUE;
  15059. }
  15060. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15061. {
  15062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15065. {
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15067. }
  15068. else
  15069. {
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15071. }
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15073. isKnowKey = TRUE;
  15074. }
  15075. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15076. {
  15077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15080. {
  15081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15082. }
  15083. else
  15084. {
  15085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15086. }
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15088. isKnowKey = TRUE;
  15089. }
  15090. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15091. {
  15092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15095. {
  15096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15097. }
  15098. else
  15099. {
  15100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15101. }
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15103. isKnowKey = TRUE;
  15104. }
  15105. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15106. {
  15107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15110. {
  15111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15112. }
  15113. else
  15114. {
  15115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15116. }
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15118. isKnowKey = TRUE;
  15119. }
  15120. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15121. {
  15122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15125. {
  15126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15127. }
  15128. else
  15129. {
  15130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15131. }
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15133. isKnowKey = TRUE;
  15134. }
  15135. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15136. {
  15137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15140. {
  15141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15142. }
  15143. else
  15144. {
  15145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15146. }
  15147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15148. isKnowKey = TRUE;
  15149. }
  15150. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15151. {
  15152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15155. {
  15156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15157. }
  15158. else
  15159. {
  15160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15161. }
  15162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15163. isKnowKey = TRUE;
  15164. }
  15165. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15166. {
  15167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15170. {
  15171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15172. }
  15173. else
  15174. {
  15175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15176. }
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15178. isKnowKey = TRUE;
  15179. }
  15180. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15181. {
  15182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15185. {
  15186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15187. }
  15188. else
  15189. {
  15190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15191. }
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15193. isKnowKey = TRUE;
  15194. }
  15195. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15196. {
  15197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15200. {
  15201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15202. }
  15203. else
  15204. {
  15205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15206. }
  15207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15208. isKnowKey = TRUE;
  15209. }
  15210. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15211. {
  15212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15215. {
  15216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15217. }
  15218. else
  15219. {
  15220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15221. }
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15223. isKnowKey = TRUE;
  15224. }
  15225. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15226. {
  15227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15230. {
  15231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15232. }
  15233. else
  15234. {
  15235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15236. }
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15238. isKnowKey = TRUE;
  15239. }
  15240. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15241. {
  15242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15245. {
  15246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15247. }
  15248. else
  15249. {
  15250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15251. }
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15253. isKnowKey = TRUE;
  15254. }
  15255. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15256. {
  15257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15260. {
  15261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15262. }
  15263. else
  15264. {
  15265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15266. }
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15268. isKnowKey = TRUE;
  15269. }
  15270. /*
  15271. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15272. {
  15273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15276. {
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15278. }
  15279. else
  15280. {
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15282. }
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15284. isKnowKey = TRUE;
  15285. }*/
  15286. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15287. {
  15288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15291. {
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15293. }
  15294. else
  15295. {
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15297. }
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15299. isKnowKey = TRUE;
  15300. }
  15301. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15302. {
  15303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15306. {
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15308. }
  15309. else
  15310. {
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15312. }
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15314. isKnowKey = TRUE;
  15315. }
  15316. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15317. {
  15318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15321. {
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15323. }
  15324. else
  15325. {
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15327. }
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15329. isKnowKey = TRUE;
  15330. }
  15331. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15332. {
  15333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15336. {
  15337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15338. }
  15339. else
  15340. {
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15342. }
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15344. isKnowKey = TRUE;
  15345. }
  15346. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15347. {
  15348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15351. {
  15352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15353. }
  15354. else
  15355. {
  15356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15357. }
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15359. isKnowKey = TRUE;
  15360. }
  15361. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15362. {
  15363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15366. {
  15367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15368. }
  15369. else
  15370. {
  15371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15372. }
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15374. isKnowKey = TRUE;
  15375. }
  15376. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15377. {
  15378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15381. {
  15382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15383. }
  15384. else
  15385. {
  15386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15387. }
  15388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15389. isKnowKey = TRUE;
  15390. }
  15391. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15392. {
  15393. struct sysinfo s_info;
  15394. int error = sysinfo(&s_info);
  15395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15398. {
  15399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15400. }
  15401. else
  15402. {
  15403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15404. }
  15405. if(error != 0)
  15406. {
  15407. DEBUG_WARN("System uptime get error: %d\n", error);
  15408. }
  15409. else
  15410. {
  15411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15412. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15413. }
  15414. isKnowKey = TRUE;
  15415. }
  15416. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15417. {
  15418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15421. {
  15422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15423. }
  15424. else
  15425. {
  15426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15427. }
  15428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15429. isKnowKey = TRUE;
  15430. }
  15431. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15432. {
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15436. {
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15438. }
  15439. else
  15440. {
  15441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15442. }
  15443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15444. isKnowKey = TRUE;
  15445. }
  15446. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15447. {
  15448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15451. {
  15452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15453. }
  15454. else
  15455. {
  15456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15457. }
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15459. isKnowKey = TRUE;
  15460. }
  15461. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15462. {
  15463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15466. {
  15467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15468. }
  15469. else
  15470. {
  15471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15472. }
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15474. isKnowKey = TRUE;
  15475. }
  15476. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15477. {
  15478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15481. {
  15482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15483. }
  15484. else
  15485. {
  15486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15487. }
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15489. isKnowKey = TRUE;
  15490. }
  15491. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15492. {
  15493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15496. {
  15497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15498. }
  15499. else
  15500. {
  15501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15502. }
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15504. isKnowKey = TRUE;
  15505. }
  15506. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15507. {
  15508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15511. {
  15512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15513. }
  15514. else
  15515. {
  15516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15517. }
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15519. isKnowKey = TRUE;
  15520. }
  15521. #if 1
  15522. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15523. {
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15526. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15527. {
  15528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15529. }
  15530. else
  15531. {
  15532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15533. }
  15534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15535. isKnowKey = TRUE;
  15536. }
  15537. #endif
  15538. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15539. {
  15540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15542. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15543. {
  15544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15545. }
  15546. else
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15549. }
  15550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15551. isKnowKey = TRUE;
  15552. }
  15553. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15554. {
  15555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15557. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15558. {
  15559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15560. }
  15561. else
  15562. {
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15564. }
  15565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15566. isKnowKey = TRUE;
  15567. }
  15568. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15569. {
  15570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15572. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15573. {
  15574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15575. }
  15576. else
  15577. {
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15579. }
  15580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15581. isKnowKey = TRUE;
  15582. }
  15583. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15584. {
  15585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15587. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15588. {
  15589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15590. }
  15591. else
  15592. {
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15594. }
  15595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15596. isKnowKey = TRUE;
  15597. }
  15598. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15599. {
  15600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15602. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15603. {
  15604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15605. }
  15606. else
  15607. {
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15609. }
  15610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15611. isKnowKey = TRUE;
  15612. }
  15613. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15614. {
  15615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15617. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15618. {
  15619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15620. }
  15621. else
  15622. {
  15623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15624. }
  15625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15626. isKnowKey = TRUE;
  15627. }
  15628. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15629. {
  15630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15632. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15633. {
  15634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15635. }
  15636. else
  15637. {
  15638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15639. }
  15640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15641. isKnowKey = TRUE;
  15642. }
  15643. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15644. {
  15645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15647. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15648. {
  15649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15650. }
  15651. else
  15652. {
  15653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15654. }
  15655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15656. isKnowKey = TRUE;
  15657. }
  15658. //=========================================================
  15659. if(!isEmpty && !isKnowKey)
  15660. {
  15661. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15662. strcpy(unknownkey[UnknownKeynum], keyReq);
  15663. UnknownKeynum = UnknownKeynum + 1;
  15664. }
  15665. }
  15666. void processUnkownKey(void)
  15667. {
  15668. DEBUG_INFO("processUnkownKey...\n");
  15669. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15670. for(int index=0; index < UnknownKeynum; index++)
  15671. {
  15672. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15673. {
  15674. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15675. }
  15676. }
  15677. }
  15678. int setKeyValue(char *key, char *value)
  15679. {
  15680. int isSuccess = NotSupported;
  15681. int check_ascii=0;
  15682. char str[501]={0};
  15683. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15684. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15685. {
  15686. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15688. {
  15689. strcpy(str, (const char*)value);
  15690. for(int i = 0; str[i]; i++){
  15691. str[i] = tolower(str[i]);
  15692. }
  15693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15694. isSuccess = ConfigurationStatus_Accepted;
  15695. }
  15696. else
  15697. {
  15698. isSuccess = ConfigurationStatus_Rejected;
  15699. }
  15700. }
  15701. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15702. {
  15703. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15704. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15705. {
  15706. strcpy(str, (const char*)value);
  15707. for(int i = 0; str[i]; i++){
  15708. str[i] = tolower(str[i]);
  15709. }
  15710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15711. isSuccess = ConfigurationStatus_Accepted;
  15712. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15713. }
  15714. else
  15715. {
  15716. isSuccess = ConfigurationStatus_Rejected;
  15717. }
  15718. }
  15719. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15720. {
  15721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15722. {
  15723. strcpy(str, (const char*)value);
  15724. for(int i = 0; str[i]; i++)
  15725. {
  15726. str[i] = tolower(str[i]);
  15727. }
  15728. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15730. isSuccess = ConfigurationStatus_Accepted;
  15731. }
  15732. else
  15733. {
  15734. isSuccess = ConfigurationStatus_Rejected;
  15735. }
  15736. }
  15737. if(strcmp(key, "BlinkRepeat") == 0)
  15738. {
  15739. //Charger.BlinkRepeat = Integer.parseInt(value);
  15740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15741. {
  15742. check_ascii = value[0];
  15743. if( (check_ascii < 48) || (check_ascii > 57) )
  15744. {
  15745. isSuccess = ConfigurationStatus_Rejected;
  15746. }
  15747. else
  15748. {
  15749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15750. isSuccess = ConfigurationStatus_Accepted;
  15751. }
  15752. }
  15753. else
  15754. {
  15755. isSuccess = ConfigurationStatus_Rejected;
  15756. }
  15757. }
  15758. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15759. {
  15760. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15761. {
  15762. check_ascii = value[0];
  15763. if( (check_ascii < 48) || (check_ascii > 57) )
  15764. {
  15765. isSuccess = ConfigurationStatus_Rejected;
  15766. }
  15767. else
  15768. {
  15769. if((atoi(value) == 0) || (atoi(value) >= 5))
  15770. {
  15771. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15773. isSuccess = ConfigurationStatus_Accepted;
  15774. }
  15775. else
  15776. isSuccess = ConfigurationStatus_Rejected;
  15777. }
  15778. }
  15779. else
  15780. {
  15781. isSuccess = ConfigurationStatus_Rejected;
  15782. }
  15783. }
  15784. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15785. {
  15786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15787. {
  15788. check_ascii = value[0];
  15789. if( (check_ascii < 48) || (check_ascii > 57) )
  15790. {
  15791. isSuccess = ConfigurationStatus_Rejected;
  15792. }
  15793. else
  15794. {
  15795. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15797. isSuccess = ConfigurationStatus_Accepted;
  15798. }
  15799. }
  15800. else
  15801. {
  15802. isSuccess = ConfigurationStatus_Rejected;
  15803. }
  15804. }
  15805. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15806. {
  15807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15808. {
  15809. check_ascii = value[0];
  15810. if( (check_ascii < 48) || (check_ascii > 57) )
  15811. {
  15812. isSuccess = ConfigurationStatus_Rejected;
  15813. }
  15814. else
  15815. {
  15816. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15818. isSuccess = ConfigurationStatus_Accepted;
  15819. }
  15820. }
  15821. else
  15822. {
  15823. isSuccess = ConfigurationStatus_Rejected;
  15824. }
  15825. }
  15826. if(strcmp(key, "HeartbeatInterval") == 0)
  15827. {
  15828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15829. {
  15830. check_ascii = value[0];
  15831. if( (check_ascii < 48) || (check_ascii > 57) )
  15832. {
  15833. isSuccess = ConfigurationStatus_Rejected;
  15834. }
  15835. else
  15836. {
  15837. if((atoi(value) == 0) || (atoi(value) >= 10))
  15838. {
  15839. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15841. HeartBeatWaitTime = atoi(value);
  15842. isSuccess = ConfigurationStatus_Accepted;
  15843. }
  15844. else
  15845. {
  15846. isSuccess = ConfigurationStatus_Rejected;
  15847. }
  15848. }
  15849. }
  15850. else
  15851. {
  15852. isSuccess = ConfigurationStatus_Rejected;
  15853. }
  15854. }
  15855. if(strcmp(key, "LightIntensity") == 0)
  15856. {
  15857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15858. {
  15859. check_ascii = value[0];
  15860. if( (check_ascii < 48) || (check_ascii > 57) )
  15861. {
  15862. isSuccess = ConfigurationStatus_Rejected;
  15863. }
  15864. else
  15865. {
  15866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15867. isSuccess = ConfigurationStatus_Accepted;
  15868. }
  15869. }
  15870. else
  15871. {
  15872. isSuccess = ConfigurationStatus_Rejected;
  15873. }
  15874. }
  15875. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15876. {
  15877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15878. {
  15879. strcpy(str, (const char*)value);
  15880. for(int i = 0; str[i]; i++)
  15881. {
  15882. str[i] = tolower(str[i]);
  15883. }
  15884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15885. isSuccess = ConfigurationStatus_Accepted;
  15886. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15887. }
  15888. else
  15889. {
  15890. isSuccess = ConfigurationStatus_Rejected;
  15891. }
  15892. }
  15893. if(strcmp(key, "LocalPreAuthorize") == 0)
  15894. {
  15895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15896. {
  15897. strcpy(str, (const char*)value);
  15898. for(int i = 0; str[i]; i++)
  15899. {
  15900. str[i] = tolower(str[i]);
  15901. }
  15902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15903. isSuccess = ConfigurationStatus_Accepted;
  15904. }
  15905. else
  15906. {
  15907. isSuccess = ConfigurationStatus_Rejected;
  15908. }
  15909. }
  15910. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15911. {
  15912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15913. {
  15914. check_ascii = value[0];
  15915. if( (check_ascii < 48) || (check_ascii > 57) )
  15916. {
  15917. isSuccess = ConfigurationStatus_Rejected;
  15918. }
  15919. else
  15920. {
  15921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15922. isSuccess = ConfigurationStatus_Accepted;
  15923. }
  15924. }
  15925. else
  15926. {
  15927. isSuccess = ConfigurationStatus_Rejected;
  15928. }
  15929. }
  15930. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15931. {
  15932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15933. {
  15934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15935. isSuccess = ConfigurationStatus_Accepted;
  15936. }
  15937. else
  15938. {
  15939. isSuccess = ConfigurationStatus_Rejected;
  15940. }
  15941. }
  15942. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15943. {
  15944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15945. {
  15946. check_ascii = value[0];
  15947. if( (check_ascii < 48) || (check_ascii > 57) )
  15948. {
  15949. isSuccess = ConfigurationStatus_Rejected;
  15950. }
  15951. else
  15952. {
  15953. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15955. isSuccess = ConfigurationStatus_Accepted;
  15956. }
  15957. }
  15958. else
  15959. {
  15960. isSuccess = ConfigurationStatus_Rejected;
  15961. }
  15962. }
  15963. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15964. {
  15965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15966. {
  15967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15968. isSuccess = ConfigurationStatus_Accepted;
  15969. }
  15970. else
  15971. {
  15972. isSuccess = ConfigurationStatus_Rejected;
  15973. }
  15974. }
  15975. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15976. {
  15977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15978. {
  15979. check_ascii = value[0];
  15980. if( (check_ascii < 48) || (check_ascii > 57) )
  15981. {
  15982. isSuccess = ConfigurationStatus_Rejected;
  15983. }
  15984. else
  15985. {
  15986. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15988. isSuccess = ConfigurationStatus_Accepted;
  15989. }
  15990. }
  15991. else
  15992. {
  15993. isSuccess = ConfigurationStatus_Rejected;
  15994. }
  15995. }
  15996. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15997. {
  15998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15999. {
  16000. check_ascii = value[0];
  16001. if( (check_ascii < 48) || (check_ascii > 57) )
  16002. {
  16003. isSuccess = ConfigurationStatus_Rejected;
  16004. }
  16005. else
  16006. {
  16007. if((atoi(value) == 0) || (atoi(value) >= 3))
  16008. {
  16009. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16011. isSuccess = ConfigurationStatus_Accepted;
  16012. }
  16013. else
  16014. {
  16015. isSuccess = ConfigurationStatus_Rejected;
  16016. }
  16017. }
  16018. }
  16019. else
  16020. {
  16021. isSuccess = ConfigurationStatus_Rejected;
  16022. }
  16023. }
  16024. if(strcmp(key, "MinimumStatusDuration") == 0)
  16025. {
  16026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16027. {
  16028. check_ascii = value[0];
  16029. if( (check_ascii < 48) || (check_ascii > 57) )
  16030. {
  16031. isSuccess = ConfigurationStatus_Rejected;
  16032. }
  16033. else
  16034. {
  16035. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16036. {
  16037. isSuccess = ConfigurationStatus_Rejected;
  16038. }
  16039. else
  16040. {
  16041. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16043. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16044. isSuccess = ConfigurationStatus_Accepted;
  16045. }
  16046. }
  16047. }
  16048. else
  16049. {
  16050. isSuccess = ConfigurationStatus_Rejected;
  16051. }
  16052. }
  16053. if(strcmp(key, "NumberOfConnectors") == 0)
  16054. {
  16055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16056. {
  16057. check_ascii = value[0];
  16058. if( (check_ascii < 48) || (check_ascii > 57) )
  16059. {
  16060. isSuccess = ConfigurationStatus_Rejected;
  16061. }
  16062. else
  16063. {
  16064. //Charger.ResetRetries = Integer.parseInt(value);
  16065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16066. isSuccess = ConfigurationStatus_Accepted;
  16067. }
  16068. }
  16069. else
  16070. {
  16071. isSuccess = ConfigurationStatus_Rejected;
  16072. }
  16073. }
  16074. if(strcmp(key, "ResetRetries") == 0)
  16075. {
  16076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16077. {
  16078. check_ascii = value[0];
  16079. if( (check_ascii < 48) || (check_ascii > 57) )
  16080. {
  16081. isSuccess = ConfigurationStatus_Rejected;
  16082. }
  16083. else
  16084. {
  16085. //Charger.ResetRetries = Integer.parseInt(value);
  16086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16087. isSuccess = ConfigurationStatus_Accepted;
  16088. }
  16089. }
  16090. else
  16091. {
  16092. isSuccess = ConfigurationStatus_Rejected;
  16093. }
  16094. }
  16095. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16096. {
  16097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16098. {
  16099. strcpy(str, (const char*)value);
  16100. for(int i = 0; str[i]; i++)
  16101. {
  16102. str[i] = tolower(str[i]);
  16103. }
  16104. if(strcmp(str, "notapplicable")== 0)
  16105. {
  16106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16107. isSuccess = ConfigurationStatus_Accepted;
  16108. }
  16109. else if(strcmp(str, "unknown")== 0)
  16110. {
  16111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16112. isSuccess = ConfigurationStatus_Accepted;
  16113. }
  16114. else if(strcmp(str, "rst")== 0)
  16115. {
  16116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16117. isSuccess = ConfigurationStatus_Accepted;
  16118. }
  16119. else if(strcmp(str, "rts")== 0)
  16120. {
  16121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16122. isSuccess = ConfigurationStatus_Accepted;
  16123. }
  16124. else if(strcmp(str, "srt")== 0)
  16125. {
  16126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16127. isSuccess = ConfigurationStatus_Accepted;
  16128. }
  16129. else if(strcmp(str, "str")== 0)
  16130. {
  16131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16132. isSuccess = ConfigurationStatus_Accepted;
  16133. }
  16134. else if(strcmp(str, "trs")== 0)
  16135. {
  16136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16137. isSuccess = ConfigurationStatus_Accepted;
  16138. }
  16139. else if(strcmp(str, "tsr")== 0)
  16140. {
  16141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16142. isSuccess = ConfigurationStatus_Accepted;
  16143. }
  16144. else
  16145. {
  16146. isSuccess = ConfigurationStatus_Rejected;
  16147. }
  16148. }
  16149. else
  16150. {
  16151. isSuccess = ConfigurationStatus_Rejected;
  16152. }
  16153. }
  16154. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16155. {
  16156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16157. {
  16158. check_ascii = value[0];
  16159. if( (check_ascii < 48) || (check_ascii > 57) )
  16160. {
  16161. isSuccess = ConfigurationStatus_Rejected;
  16162. }
  16163. else
  16164. {
  16165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16166. isSuccess = ConfigurationStatus_Accepted;
  16167. }
  16168. }
  16169. else
  16170. {
  16171. isSuccess = ConfigurationStatus_Rejected;
  16172. }
  16173. }
  16174. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16175. {
  16176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16177. {
  16178. strcpy(str, (const char*)value);
  16179. for(int i = 0; str[i]; i++)
  16180. {
  16181. str[i] = tolower(str[i]);
  16182. }
  16183. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16185. isSuccess = ConfigurationStatus_Accepted;
  16186. }
  16187. else
  16188. {
  16189. isSuccess = ConfigurationStatus_Rejected;
  16190. }
  16191. }
  16192. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16193. {
  16194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16195. {
  16196. strcpy(str, (const char*)value);
  16197. for(int i = 0; str[i]; i++)
  16198. {
  16199. str[i] = tolower(str[i]);
  16200. }
  16201. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16203. isSuccess = ConfigurationStatus_Accepted;
  16204. }
  16205. else
  16206. {
  16207. isSuccess = ConfigurationStatus_Rejected;
  16208. }
  16209. }
  16210. if(strcmp(key, "StopTxnAlignedData") == 0)
  16211. {
  16212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16213. {
  16214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16215. isSuccess = ConfigurationStatus_Accepted;
  16216. }
  16217. else
  16218. {
  16219. isSuccess = ConfigurationStatus_Rejected;
  16220. }
  16221. }
  16222. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16223. {
  16224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16225. {
  16226. check_ascii = value[0];
  16227. if( (check_ascii < 48) || (check_ascii > 57) )
  16228. {
  16229. isSuccess = ConfigurationStatus_Rejected;
  16230. }
  16231. else
  16232. {
  16233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16234. isSuccess = ConfigurationStatus_Accepted;
  16235. }
  16236. }
  16237. else
  16238. {
  16239. isSuccess = ConfigurationStatus_Rejected;
  16240. }
  16241. }
  16242. if(strcmp(key, "StopTxnSampledData") == 0)
  16243. {
  16244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16245. {
  16246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16247. isSuccess = ConfigurationStatus_Accepted;
  16248. }
  16249. else
  16250. {
  16251. isSuccess = ConfigurationStatus_Rejected;
  16252. }
  16253. }
  16254. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16255. {
  16256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16257. {
  16258. check_ascii = value[0];
  16259. if( (check_ascii < 48) || (check_ascii > 57) )
  16260. {
  16261. isSuccess = ConfigurationStatus_Rejected;
  16262. }
  16263. else
  16264. {
  16265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16266. isSuccess = ConfigurationStatus_Accepted;
  16267. }
  16268. }
  16269. else
  16270. {
  16271. isSuccess = ConfigurationStatus_Rejected;
  16272. }
  16273. }
  16274. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16275. {
  16276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16277. {
  16278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16279. isSuccess = ConfigurationStatus_Accepted;
  16280. }
  16281. else
  16282. {
  16283. isSuccess = ConfigurationStatus_Rejected;
  16284. }
  16285. }
  16286. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16287. {
  16288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16289. {
  16290. check_ascii = value[0];
  16291. if( (check_ascii < 48) || (check_ascii > 57) )
  16292. {
  16293. isSuccess = ConfigurationStatus_Rejected;
  16294. }
  16295. else
  16296. {
  16297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16298. isSuccess = ConfigurationStatus_Accepted;
  16299. }
  16300. }
  16301. else
  16302. {
  16303. isSuccess = ConfigurationStatus_Rejected;
  16304. }
  16305. }
  16306. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16307. {
  16308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16309. {
  16310. check_ascii = value[0];
  16311. if( (check_ascii < 48) || (check_ascii > 57) )
  16312. {
  16313. isSuccess = ConfigurationStatus_Rejected;
  16314. }
  16315. else
  16316. {
  16317. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16319. TransactionMessageAttemptsValue = atoi(value);
  16320. isSuccess = ConfigurationStatus_Accepted;
  16321. }
  16322. }
  16323. else
  16324. {
  16325. isSuccess = ConfigurationStatus_Rejected;
  16326. }
  16327. }
  16328. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16329. {
  16330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16331. {
  16332. check_ascii = value[0];
  16333. if( (check_ascii < 48) || (check_ascii > 57) )
  16334. {
  16335. isSuccess = ConfigurationStatus_Rejected;
  16336. }
  16337. else
  16338. {
  16339. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16341. TransactionMessageRetryIntervalValue = atoi(value);
  16342. isSuccess = ConfigurationStatus_Accepted;
  16343. }
  16344. }
  16345. else
  16346. {
  16347. isSuccess = ConfigurationStatus_Rejected;
  16348. }
  16349. }
  16350. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16351. {
  16352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16353. {
  16354. strcpy(str, (const char*)value);
  16355. for(int i = 0; str[i]; i++)
  16356. {
  16357. str[i] = tolower(str[i]);
  16358. }
  16359. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16361. isSuccess = ConfigurationStatus_Accepted;
  16362. }
  16363. else
  16364. {
  16365. isSuccess = ConfigurationStatus_Rejected;
  16366. }
  16367. }
  16368. if(strcmp(key, "WebSocketPingInterval") == 0)
  16369. {
  16370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16371. {
  16372. check_ascii = value[0];
  16373. if( (check_ascii < 48) || (check_ascii > 57) )
  16374. {
  16375. isSuccess = ConfigurationStatus_Rejected;
  16376. }
  16377. else
  16378. {
  16379. if((atoi(value) == 0) || (atoi(value) >= 10))
  16380. {
  16381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16382. isSuccess = ConfigurationStatus_Accepted;
  16383. }
  16384. else
  16385. isSuccess = ConfigurationStatus_Rejected;
  16386. }
  16387. }
  16388. else
  16389. {
  16390. isSuccess = ConfigurationStatus_Rejected;
  16391. }
  16392. }
  16393. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16394. {
  16395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16396. {
  16397. strcpy(str, (const char*)value);
  16398. for(int i = 0; str[i]; i++)
  16399. {
  16400. str[i] = tolower(str[i]);
  16401. }
  16402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16403. isSuccess = ConfigurationStatus_Accepted;
  16404. }
  16405. else
  16406. {
  16407. isSuccess = ConfigurationStatus_Rejected;
  16408. }
  16409. }
  16410. if(strcmp(key, "AuthorizationKey") == 0)
  16411. {
  16412. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16413. {
  16414. strcpy(str, (const char*)value);
  16415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16416. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16417. isSuccess = ConfigurationStatus_Accepted;
  16418. }
  16419. else
  16420. {
  16421. isSuccess = ConfigurationStatus_Rejected;
  16422. }
  16423. }
  16424. if(strcmp(key, "SecurityProfile") == 0)
  16425. {
  16426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16427. {
  16428. check_ascii = value[0];
  16429. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16430. {
  16431. isSuccess = ConfigurationStatus_Rejected;
  16432. }
  16433. else if(check_ascii == 0x33)
  16434. {
  16435. isSuccess = NotSupported;
  16436. }
  16437. else
  16438. {
  16439. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16440. {
  16441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16442. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16443. isSuccess = ConfigurationStatus_Accepted;
  16444. }
  16445. else
  16446. isSuccess = ConfigurationStatus_Rejected;
  16447. }
  16448. }
  16449. else
  16450. {
  16451. isSuccess = ConfigurationStatus_Rejected;
  16452. }
  16453. }
  16454. if(strcmp(key, "DefaultPrice") == 0)
  16455. {
  16456. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16457. {
  16458. strcpy(str, (const char*)value);
  16459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16460. isSuccess = ConfigurationStatus_Accepted;
  16461. }
  16462. else
  16463. {
  16464. isSuccess = ConfigurationStatus_Rejected;
  16465. }
  16466. }
  16467. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16468. {
  16469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16470. {
  16471. strcpy(str, (const char*)value);
  16472. for(int i = 0; str[i]; i++)
  16473. {
  16474. str[i] = tolower(str[i]);
  16475. }
  16476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16477. isSuccess = ConfigurationStatus_Accepted;
  16478. }
  16479. else
  16480. {
  16481. isSuccess = ConfigurationStatus_Rejected;
  16482. }
  16483. }
  16484. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16485. {
  16486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16487. {
  16488. strcpy(str, (const char*)value);
  16489. for(int i = 0; str[i]; i++)
  16490. {
  16491. str[i] = tolower(str[i]);
  16492. }
  16493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16494. isSuccess = ConfigurationStatus_Accepted;
  16495. }
  16496. else
  16497. {
  16498. isSuccess = ConfigurationStatus_Rejected;
  16499. }
  16500. }
  16501. if(strcmp(key, "TimeOffset") == 0)
  16502. {
  16503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16504. {
  16505. strcpy(str, (const char*)value);
  16506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16507. isSuccess = ConfigurationStatus_Accepted;
  16508. }
  16509. else
  16510. {
  16511. isSuccess = ConfigurationStatus_Rejected;
  16512. }
  16513. }
  16514. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16515. {
  16516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16517. {
  16518. strcpy(str, (const char*)value);
  16519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16520. isSuccess = ConfigurationStatus_Accepted;
  16521. }
  16522. else
  16523. {
  16524. isSuccess = ConfigurationStatus_Rejected;
  16525. }
  16526. }
  16527. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16528. {
  16529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16530. {
  16531. strcpy(str, (const char*)value);
  16532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16533. isSuccess = ConfigurationStatus_Accepted;
  16534. }
  16535. else
  16536. {
  16537. isSuccess = ConfigurationStatus_Rejected;
  16538. }
  16539. }
  16540. if(strcmp(key, "SystemUptimeSec") == 0)
  16541. {
  16542. isSuccess = NotSupported;
  16543. }
  16544. if(strcmp(key, "FreeVend") == 0)
  16545. {
  16546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16547. {
  16548. strcpy(str, (const char*)value);
  16549. for(int i = 0; str[i]; i++)
  16550. {
  16551. str[i] = tolower(str[i]);
  16552. }
  16553. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16555. isSuccess = ConfigurationStatus_Accepted;
  16556. }
  16557. else
  16558. {
  16559. isSuccess = ConfigurationStatus_Rejected;
  16560. }
  16561. }
  16562. if(strcmp(key, "FreeVendIdtag") == 0)
  16563. {
  16564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16565. {
  16566. strcpy(str, (const char*)value);
  16567. if(strlen(str) <= 20)
  16568. {
  16569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16570. isSuccess = ConfigurationStatus_Accepted;
  16571. }
  16572. else
  16573. {
  16574. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16575. isSuccess = ConfigurationStatus_Rejected;
  16576. }
  16577. }
  16578. else
  16579. {
  16580. isSuccess = ConfigurationStatus_Rejected;
  16581. }
  16582. }
  16583. if(strcmp(key, "OcppServer") == 0)
  16584. {
  16585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16586. {
  16587. strcpy(str, (const char*)value);
  16588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16589. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16590. isSuccess = ConfigurationStatus_Accepted;
  16591. }
  16592. else
  16593. {
  16594. isSuccess = ConfigurationStatus_Rejected;
  16595. }
  16596. }
  16597. if(strcmp(key, "MaintainServer") == 0)
  16598. {
  16599. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16600. {
  16601. strcpy(str, (const char*)value);
  16602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16603. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16604. isSuccess = ConfigurationStatus_Accepted;
  16605. }
  16606. else
  16607. {
  16608. isSuccess = ConfigurationStatus_Rejected;
  16609. }
  16610. }
  16611. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16612. {
  16613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16614. {
  16615. strcpy(str, (const char*)value);
  16616. for(int i = 0; str[i]; i++)
  16617. {
  16618. str[i] = tolower(str[i]);
  16619. }
  16620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16621. isSuccess = ConfigurationStatus_Accepted;
  16622. }
  16623. else
  16624. {
  16625. isSuccess = ConfigurationStatus_Rejected;
  16626. }
  16627. }
  16628. if(strcmp(key, "StatusNotificationInterval") == 0)
  16629. {
  16630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16631. {
  16632. check_ascii = value[0];
  16633. if( (check_ascii < 48) || (check_ascii > 57) )
  16634. {
  16635. isSuccess = ConfigurationStatus_Rejected;
  16636. }
  16637. else
  16638. {
  16639. if((atoi(value) == 0) || (atoi(value) >= 10))
  16640. {
  16641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16642. isSuccess = ConfigurationStatus_Accepted;
  16643. }
  16644. else
  16645. isSuccess = ConfigurationStatus_Rejected;
  16646. }
  16647. }
  16648. else
  16649. {
  16650. isSuccess = ConfigurationStatus_Rejected;
  16651. }
  16652. }
  16653. #if 0
  16654. //For OCPP Test Case
  16655. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16656. {
  16657. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16658. {
  16659. strcpy(str, (const char*)value);
  16660. for(int i = 0; str[i]; i++)
  16661. {
  16662. str[i] = tolower(str[i]);
  16663. }
  16664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16665. isSuccess = ConfigurationStatus_Accepted;
  16666. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16667. }
  16668. else
  16669. {
  16670. isSuccess = ConfigurationStatus_Rejected;
  16671. }
  16672. }
  16673. #endif
  16674. #if 1
  16675. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16676. {
  16677. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16678. {
  16679. strcpy(str, (const char*)value);
  16680. for(int i = 0; str[i]; i++)
  16681. {
  16682. str[i] = tolower(str[i]);
  16683. }
  16684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16685. isSuccess = ConfigurationStatus_Accepted;
  16686. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16687. }
  16688. else
  16689. {
  16690. isSuccess = ConfigurationStatus_Rejected;
  16691. }
  16692. }
  16693. #endif
  16694. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16695. {
  16696. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16697. {
  16698. check_ascii = value[0];
  16699. if( (check_ascii < 48) || (check_ascii > 57) )
  16700. {
  16701. isSuccess = ConfigurationStatus_Rejected;
  16702. }
  16703. else
  16704. {
  16705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16706. isSuccess = ConfigurationStatus_Accepted;
  16707. }
  16708. }
  16709. else
  16710. {
  16711. isSuccess = ConfigurationStatus_Rejected;
  16712. }
  16713. }
  16714. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16715. {
  16716. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16717. {
  16718. check_ascii = value[0];
  16719. if( (check_ascii < 48) || (check_ascii > 57) )
  16720. {
  16721. isSuccess = ConfigurationStatus_Rejected;
  16722. }
  16723. else
  16724. {
  16725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16726. isSuccess = ConfigurationStatus_Accepted;
  16727. }
  16728. }
  16729. else
  16730. {
  16731. isSuccess = ConfigurationStatus_Rejected;
  16732. }
  16733. }
  16734. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16735. {
  16736. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16737. {
  16738. strcpy(str, (const char*)value);
  16739. for(int i = 0; str[i]; i++)
  16740. {
  16741. str[i] = tolower(str[i]);
  16742. }
  16743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16744. isSuccess = ConfigurationStatus_Accepted;
  16745. }
  16746. else
  16747. {
  16748. isSuccess = ConfigurationStatus_Rejected;
  16749. }
  16750. }
  16751. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16752. {
  16753. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16754. {
  16755. check_ascii = value[0];
  16756. if( (check_ascii < 48) || (check_ascii > 57) )
  16757. {
  16758. isSuccess = ConfigurationStatus_Rejected;
  16759. }
  16760. else
  16761. {
  16762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16763. isSuccess = ConfigurationStatus_Accepted;
  16764. }
  16765. }
  16766. else
  16767. {
  16768. isSuccess = ConfigurationStatus_Rejected;
  16769. }
  16770. }
  16771. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16772. {
  16773. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16774. {
  16775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16776. isSuccess = ConfigurationStatus_Accepted;
  16777. }
  16778. else
  16779. {
  16780. isSuccess = ConfigurationStatus_Rejected;
  16781. }
  16782. }
  16783. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16784. {
  16785. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16786. {
  16787. check_ascii = value[0];
  16788. if( (check_ascii < 48) || (check_ascii > 57) )
  16789. {
  16790. isSuccess = ConfigurationStatus_Rejected;
  16791. }
  16792. else
  16793. {
  16794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16795. isSuccess = ConfigurationStatus_Accepted;
  16796. }
  16797. }
  16798. else
  16799. {
  16800. isSuccess = ConfigurationStatus_Rejected;
  16801. }
  16802. }
  16803. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16804. {
  16805. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16806. {
  16807. strcpy(str, (const char*)value);
  16808. for(int i = 0; str[i]; i++)
  16809. {
  16810. str[i] = tolower(str[i]);
  16811. }
  16812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16813. isSuccess = ConfigurationStatus_Accepted;
  16814. }
  16815. else
  16816. {
  16817. isSuccess = ConfigurationStatus_Rejected;
  16818. }
  16819. }
  16820. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16821. {
  16822. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16823. {
  16824. check_ascii = value[0];
  16825. if( (check_ascii < 48) || (check_ascii > 57) )
  16826. {
  16827. isSuccess = ConfigurationStatus_Rejected;
  16828. }
  16829. else
  16830. {
  16831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16832. isSuccess = ConfigurationStatus_Accepted;
  16833. }
  16834. }
  16835. else
  16836. {
  16837. isSuccess = ConfigurationStatus_Rejected;
  16838. }
  16839. }
  16840. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16841. return isSuccess;
  16842. }
  16843. int TransactionMessageAttemptsGet(void)
  16844. {
  16845. return TransactionMessageAttemptsValue;
  16846. }
  16847. int FirstHeartBeatResponse(void)
  16848. {
  16849. return FirstHeartBeat;
  16850. }
  16851. int TransactionMessageRetryIntervalGet(void)
  16852. {
  16853. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16854. }
  16855. int ReadHttpStatus(int sock)
  16856. {
  16857. //char c;
  16858. char buff[1024]="",*ptr=buff+1;
  16859. int bytes_received, status;
  16860. DEBUG_INFO("Begin Response ..\n");
  16861. while((bytes_received = recv(sock, ptr, 1, 0))){
  16862. if(bytes_received==-1){
  16863. perror("ReadHttpStatus");
  16864. exit(1);
  16865. }
  16866. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16867. ptr++;
  16868. }
  16869. *ptr=0;
  16870. ptr=buff+1;
  16871. sscanf(ptr,"%*s %d ", &status);
  16872. DEBUG_INFO("%s\n",ptr);
  16873. DEBUG_INFO("status=%d\n",status);
  16874. DEBUG_INFO("End Response ..\n");
  16875. return (bytes_received>0)?status:0;
  16876. }
  16877. //the only filed that it parsed is 'Content-Length'
  16878. int ParseHeader(int sock)
  16879. {
  16880. //char c;
  16881. char buff[1024]="",*ptr=buff+4;
  16882. int bytes_received;
  16883. DEBUG_INFO("Begin HEADER ..\n");
  16884. while((bytes_received = recv(sock, ptr, 1, 0))){
  16885. if(bytes_received==-1){
  16886. perror("Parse Header");
  16887. exit(1);
  16888. }
  16889. if(
  16890. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16891. (ptr[-1]=='\r') && (*ptr=='\n' )
  16892. ) break;
  16893. ptr++;
  16894. }
  16895. *ptr=0;
  16896. ptr=buff+4;
  16897. //printf("%s",ptr);
  16898. if(bytes_received){
  16899. ptr=strstr(ptr,"Content-Length:");
  16900. if(ptr){
  16901. sscanf(ptr,"%*s %d",&bytes_received);
  16902. }else
  16903. bytes_received=-1; //unknown size
  16904. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16905. }
  16906. DEBUG_INFO("End HEADER ..\n");
  16907. return bytes_received ;
  16908. }
  16909. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16910. {
  16911. int result = TRUE;
  16912. char rmFileCmd[100]={0};
  16913. char FilePath[100]={0};
  16914. char ftpbuf[200];
  16915. int systemresult;
  16916. sprintf(FilePath,"/mnt/%s",filename);
  16917. system("ping 8.8.8.8 &");
  16918. if((access(FilePath,F_OK))!=-1)
  16919. {
  16920. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16921. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16922. system(rmFileCmd);
  16923. }
  16924. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16925. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16926. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16927. systemresult = system(ftpbuf);
  16928. if(systemresult != 0)
  16929. {
  16930. DEBUG_INFO("http DownLoad error!\n");
  16931. result = FALSE;
  16932. }
  16933. system("pkill ping");
  16934. return result;
  16935. }
  16936. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16937. {
  16938. int result = TRUE;
  16939. char rmFileCmd[100]={0};
  16940. char FilePath[100]={0};
  16941. char ftpbuf[200];
  16942. int systemresult;
  16943. sprintf(FilePath,"/mnt/%s",filename);
  16944. system("ping 8.8.8.8 &");
  16945. if((access(FilePath,F_OK))!=-1)
  16946. {
  16947. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16948. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16949. system(rmFileCmd);
  16950. }
  16951. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16952. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16953. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16954. systemresult = system(ftpbuf);
  16955. if(systemresult != 0)
  16956. {
  16957. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16958. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16959. systemresult = system(ftpbuf);
  16960. if(systemresult != 0)
  16961. {
  16962. DEBUG_WARN("wget error!\n");
  16963. result = FALSE;
  16964. }
  16965. }
  16966. system("pkill ping");
  16967. return result;
  16968. }
  16969. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16970. {
  16971. char rmFileCmd[100]={0};
  16972. char FilePath[100]={0};
  16973. char buf[512];
  16974. int systemresult = 0;
  16975. //DEBUG_INFO("filename=%s\n",filename);
  16976. //DEBUG_INFO("url=%s\n",url);
  16977. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16978. if((access(FilePath,F_OK))!=-1)
  16979. {
  16980. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16981. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16982. system(rmFileCmd);
  16983. }
  16984. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16985. if(fp == NULL)
  16986. {
  16987. DEBUG_INFO("log is NULL\n");
  16988. return FALSE;
  16989. }
  16990. else
  16991. {
  16992. fprintf(fp, "%s\n", url);
  16993. fprintf(fp, "%s\n", filename);
  16994. fclose(fp);
  16995. }
  16996. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16997. if(phpFP == NULL)
  16998. {
  16999. DEBUG_INFO("PHP upload fail.\n");
  17000. return FALSE;
  17001. }
  17002. else
  17003. {
  17004. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17005. {
  17006. if(strstr(buf, "result") != NULL)
  17007. {
  17008. sscanf(buf, "result: %d", &systemresult);
  17009. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17010. }
  17011. }
  17012. pclose(phpFP);
  17013. }
  17014. if(systemresult != 1)
  17015. {
  17016. DEBUG_INFO("HTTP upload error!\n");
  17017. return FALSE;
  17018. }
  17019. return TRUE;
  17020. }
  17021. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17022. {
  17023. int result = FALSE;
  17024. char ftpbuf[200];
  17025. int systemresult;
  17026. /*
  17027. // Domaind name transfer to IP address
  17028. struct hostent* server;
  17029. char *IPbuffer;
  17030. server = gethostbyname(location);
  17031. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17032. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17033. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17034. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17035. systemresult = system(ftpbuf);
  17036. if(systemresult != 0)
  17037. {
  17038. DEBUG_INFO("ftpput error!\n");
  17039. }
  17040. else
  17041. {
  17042. result = TRUE;
  17043. DEBUG_INFO("ftpput OK!\n");
  17044. }
  17045. return result;
  17046. }
  17047. int GetOcppServerURL()
  17048. {
  17049. int result = FALSE;
  17050. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17051. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17052. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17053. struct yuarel url;
  17054. char urlStr[512];
  17055. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17056. {
  17057. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17058. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17059. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17060. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17061. if(yuarel_parse(&url, urlStr) != -1)
  17062. {
  17063. sprintf(OcppProtocol, "%s", url.scheme);
  17064. sprintf(OcppHost, "%s", url.host);
  17065. if(url.path == NULL)
  17066. OcppTempPath[0] = '\0';
  17067. else
  17068. {
  17069. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17070. {
  17071. sprintf(OcppTempPath, "%s/", url.path);
  17072. }
  17073. else
  17074. {
  17075. sprintf(OcppTempPath, "%s", url.path);
  17076. }
  17077. }
  17078. if(url.port == 0)
  17079. {
  17080. if(strcmp(OcppProtocol, "wss") == 0)
  17081. OcppPort = 443;
  17082. else
  17083. OcppPort = 80;
  17084. }
  17085. else
  17086. OcppPort = url.port;
  17087. result = TRUE;
  17088. }
  17089. }
  17090. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17091. {
  17092. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17093. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17094. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17095. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17096. if(yuarel_parse(&url, urlStr) != -1)
  17097. {
  17098. sprintf(OcppProtocol, "%s", url.scheme);
  17099. sprintf(OcppHost, "%s", url.host);
  17100. if(url.path == NULL)
  17101. OcppTempPath[0] = '\0';
  17102. else
  17103. sprintf(OcppTempPath, "%s", url.path);
  17104. if(url.port == 0)
  17105. {
  17106. if(strcmp(OcppProtocol, "wss") == 0)
  17107. OcppPort = 443;
  17108. else
  17109. OcppPort = 80;
  17110. }
  17111. else
  17112. OcppPort = url.port;
  17113. result = TRUE;
  17114. }
  17115. }
  17116. else
  17117. {
  17118. strcpy(OcppHost,"");
  17119. }
  17120. return result;
  17121. }
  17122. int GetOcppPath()
  17123. {
  17124. int result = FALSE;
  17125. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17126. {
  17127. if(OcppTempPath == NULL)
  17128. {
  17129. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17130. }
  17131. else
  17132. {
  17133. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17134. }
  17135. result = TRUE;
  17136. goto End;
  17137. }
  17138. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17139. {
  17140. if(OcppTempPath == NULL)
  17141. {
  17142. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17143. }
  17144. else
  17145. {
  17146. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17147. }
  17148. result = TRUE;
  17149. goto End;
  17150. }
  17151. else
  17152. {
  17153. strcpy(OcppPath,"");
  17154. }
  17155. End:
  17156. return result;
  17157. }
  17158. int GetOcppPort()
  17159. {
  17160. return OcppPort;
  17161. }
  17162. int GetOcppConnStatus(void)
  17163. {
  17164. return ShmOCPP16Data->OcppConnStatus;
  17165. }
  17166. void SetOcppConnStatus(uint8_t status)
  17167. {
  17168. ShmOCPP16Data->OcppConnStatus = status;
  17169. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17170. }
  17171. int GetHeartBeatWithNOResponse(void)
  17172. {
  17173. return HeartBeatWithNOResponse;
  17174. }
  17175. void SetHeartBeatWithNOResponse(void)
  17176. {
  17177. HeartBeatWithNOResponse = 0;
  17178. }
  17179. void GetStartTransactionIdTag(int gun_index)
  17180. {
  17181. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17182. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17183. }
  17184. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17185. {
  17186. char ch;
  17187. FILE *fptr1;
  17188. int temptransactionId;
  17189. char str[100]={0};
  17190. temptransactionId = 0;
  17191. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17192. {
  17193. DEBUG_INFO("IdTag is empty.\n");
  17194. return temptransactionId;
  17195. }
  17196. /*------ Read the file ----------------*/
  17197. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17198. if (!fptr1)
  17199. {
  17200. DEBUG_INFO("QueueTransactionId file open error.\n");
  17201. //printf(" File not found or unable to open the input file!!\n");
  17202. return temptransactionId;
  17203. }
  17204. ch=fgetc(fptr1);
  17205. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17206. rewind(fptr1);
  17207. if(ch!=EOF)
  17208. {
  17209. // printf("%c",ch);
  17210. while (fgets(str, 100, fptr1) != NULL)
  17211. {
  17212. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17213. if(str[0]=='\0')
  17214. {
  17215. break;
  17216. }
  17217. char *revbuf[8] = {0}; // Variable store string split
  17218. int num = 0;// Quantity after string split
  17219. DEBUG_INFO("Transaction queue data= %s\n", str);
  17220. splitstring(str,",",revbuf,&num); // String split
  17221. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17222. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17223. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17224. DEBUG_INFO("------------------------------\n");
  17225. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17226. {
  17227. if(isStopTransaction)
  17228. {
  17229. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17230. {
  17231. temptransactionId = atoi(revbuf[2]);
  17232. //break;
  17233. }
  17234. }
  17235. else
  17236. {
  17237. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17238. {
  17239. temptransactionId = atoi(revbuf[2]);
  17240. //break;
  17241. }
  17242. }
  17243. }
  17244. }
  17245. }
  17246. else
  17247. DEBUG_INFO("EOF\n");
  17248. fclose(fptr1);
  17249. /*------- End of reading ---------------*/
  17250. return temptransactionId;
  17251. }
  17252. void SetTransactionIdZero(int transactionId)
  17253. {
  17254. char ch;
  17255. FILE *fptr1, *fptr2;
  17256. int temptransactionId = 0;
  17257. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17258. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17259. if (!fptr1)
  17260. {
  17261. //printf(" File not found or unable to open the input file!!\n");
  17262. return ;
  17263. }
  17264. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17265. if (!fptr2)
  17266. {
  17267. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17268. fclose(fptr1);
  17269. return ;
  17270. }
  17271. ch=fgetc(fptr1);
  17272. rewind(fptr1);
  17273. if(ch!=EOF)
  17274. {
  17275. // copy all contents to the temporary file except the specific line
  17276. while (fgets(str, 100, fptr1) != NULL)
  17277. {
  17278. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17279. if(str[0]=='\0')
  17280. {
  17281. break;
  17282. }
  17283. char *revbuf[8] = {0};
  17284. int num = 0;
  17285. strcpy(strtemp, str);
  17286. splitstring(str,",",revbuf,&num);
  17287. if(revbuf[2][0] != '\0')
  17288. {
  17289. temptransactionId = atoi(revbuf[2]);
  17290. if(transactionId != temptransactionId)
  17291. {
  17292. fprintf(fptr2, "%s\n", strtemp);
  17293. }
  17294. }
  17295. }
  17296. }
  17297. fclose(fptr1);
  17298. fclose(fptr2);
  17299. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17300. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17301. /*------ Read the file ----------------*/
  17302. }
  17303. int InternetDisconnect(void)
  17304. {
  17305. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17306. }
  17307. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17308. void storeTempStopTransaction(int gun_index)
  17309. {
  17310. char guid[37]={0};
  17311. int tempIndex = 0;
  17312. char TempStopTransaction[256];
  17313. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17314. DEBUG_INFO("storeTempStopTransaction...\n");
  17315. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17316. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17317. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17318. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17319. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17320. {
  17321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17322. {
  17323. tempIndex = ((gun_index==2) ? 1: 0);
  17324. }
  17325. else
  17326. {
  17327. tempIndex = gun_index;
  17328. }
  17329. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17330. {
  17331. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17332. {
  17333. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17334. }
  17335. }// END OF CHAdeMO_QUANTITY
  17336. }
  17337. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17338. {
  17339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17340. {
  17341. tempIndex = ((gun_index==2) ? 1: 0);
  17342. }
  17343. else
  17344. {
  17345. tempIndex = gun_index;
  17346. }
  17347. for (int index = 0; index < CCS_QUANTITY; index++)
  17348. {
  17349. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17350. {
  17351. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17352. }
  17353. }// END OF CCS_QUANTITY
  17354. }
  17355. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17356. {
  17357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17358. {
  17359. tempIndex = ((gun_index==2) ? 1: 0);
  17360. }
  17361. else
  17362. {
  17363. tempIndex = gun_index;
  17364. }
  17365. for (int index = 0; index < GB_QUANTITY; index++)
  17366. {
  17367. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17368. {
  17369. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17370. }
  17371. }// END OF GB_QUANTITY
  17372. }
  17373. else if(gunType[gun_index] == GUN_TYPE_DO)
  17374. {
  17375. tempIndex = gun_index;
  17376. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17377. {
  17378. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17379. {
  17380. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17381. }
  17382. }
  17383. }
  17384. else
  17385. {
  17386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17387. {
  17388. tempIndex = 2;
  17389. }
  17390. else
  17391. {
  17392. tempIndex = gun_index;
  17393. }
  17394. for (int index = 0; index < AC_QUANTITY; index++)
  17395. {
  17396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17397. {
  17398. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17399. }
  17400. }// END OF AC_QUANTITY
  17401. }
  17402. //Stop Transaction Time
  17403. struct timeval tmnow;
  17404. struct tm *tm;
  17405. char buf[28];//, usec_buf[6];
  17406. gettimeofday(&tmnow, NULL);
  17407. time_t t;
  17408. t = time(NULL);
  17409. /*UTC time and date*/
  17410. tm = gmtime(&t);
  17411. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17413. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17415. random_uuid(guid);
  17416. /***********************************transactionData******************************************************/
  17417. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17419. //=================================
  17420. //1. Transaction_Begin
  17421. //=================================
  17422. //============================== Energy.Active.Import.Interval ===========================================
  17423. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17424. {
  17425. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17428. 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*/]);
  17429. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17430. 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))
  17431. {
  17432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17433. }
  17434. else
  17435. {
  17436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17437. }
  17438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17440. }
  17441. //=================================
  17442. //2. Transaction_End
  17443. //=================================
  17444. //2.1====================================== Current.Import L1 ==============================================
  17445. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17446. {
  17447. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17448. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17449. {
  17450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17451. {
  17452. tempIndex = ((gun_index==2) ? 1: 0);
  17453. }
  17454. else
  17455. {
  17456. tempIndex = gun_index;
  17457. }
  17458. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17459. {
  17460. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17461. {
  17462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17463. }
  17464. }// End of for CHAdeMO_QUANTITY
  17465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17466. }
  17467. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17468. {
  17469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17470. {
  17471. tempIndex = ((gun_index==2) ? 1: 0);
  17472. }
  17473. else
  17474. {
  17475. tempIndex = gun_index;
  17476. }
  17477. for (int index = 0; index < CCS_QUANTITY; index++)
  17478. {
  17479. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17480. {
  17481. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17482. }
  17483. }// End of for CCS_QUANTITY
  17484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17485. }
  17486. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17487. {
  17488. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17489. {
  17490. tempIndex = ((gun_index==2) ? 1: 0);
  17491. }
  17492. else
  17493. {
  17494. tempIndex = gun_index;
  17495. }
  17496. for (int index = 0; index < GB_QUANTITY; index++)
  17497. {
  17498. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17499. {
  17500. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17501. }
  17502. }// End of for GB_QUANTITY
  17503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17504. }
  17505. else if(gunType[gun_index] == GUN_TYPE_DO)
  17506. {
  17507. tempIndex = gun_index;
  17508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17509. {
  17510. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17511. {
  17512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17513. }
  17514. }
  17515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17516. }
  17517. else
  17518. {
  17519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17520. {
  17521. tempIndex = 2;
  17522. }
  17523. else
  17524. {
  17525. tempIndex = gun_index;
  17526. }
  17527. for (int index = 0; index < AC_QUANTITY; index++)
  17528. {
  17529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17530. {
  17531. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17532. }
  17533. }// End of for AC_QUANTITY
  17534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17535. }
  17536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17539. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17542. }
  17543. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17544. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17545. {
  17546. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17547. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17548. {
  17549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17550. {
  17551. tempIndex = ((gun_index==2) ? 1: 0);
  17552. }
  17553. else
  17554. {
  17555. tempIndex = gun_index;
  17556. }
  17557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17558. {
  17559. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17560. {
  17561. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17562. }
  17563. }// END OF CHAdeMO_QUANTITY
  17564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17565. }
  17566. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17567. {
  17568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17569. {
  17570. tempIndex = ((gun_index==2) ? 1: 0);
  17571. }
  17572. else
  17573. {
  17574. tempIndex = gun_index;
  17575. }
  17576. for (int index = 0; index < CCS_QUANTITY; index++)
  17577. {
  17578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17579. {
  17580. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17581. }
  17582. }// END OF CCS_QUANTITY
  17583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17584. }
  17585. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17586. {
  17587. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17588. {
  17589. tempIndex = ((gun_index==2) ? 1: 0);
  17590. }
  17591. else
  17592. {
  17593. tempIndex = gun_index;
  17594. }
  17595. for (int index = 0; index < GB_QUANTITY; index++)
  17596. {
  17597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17598. {
  17599. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17600. }
  17601. }// END OF GB_QUANTITY
  17602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17603. }
  17604. else if(gunType[gun_index] == GUN_TYPE_DO)
  17605. {
  17606. tempIndex = gun_index;
  17607. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17608. {
  17609. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17610. {
  17611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17612. }
  17613. }
  17614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17615. }
  17616. else
  17617. {
  17618. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17619. {
  17620. tempIndex = 2;
  17621. }
  17622. else
  17623. {
  17624. tempIndex = gun_index;
  17625. }
  17626. for (int index = 0; index < AC_QUANTITY; index++)
  17627. {
  17628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17629. {
  17630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17631. }
  17632. }// END OF AC_QUANTITY
  17633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17634. }
  17635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17638. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17641. }
  17642. //2.3====================================== Power.Active.Import =========================================
  17643. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17644. {
  17645. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17646. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17647. {
  17648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17649. {
  17650. tempIndex = ((gun_index==2) ? 1: 0);
  17651. }
  17652. else
  17653. {
  17654. tempIndex = gun_index;
  17655. }
  17656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17657. {
  17658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17659. {
  17660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17661. }
  17662. } // End for CHAdeMO_QUANTITY
  17663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17664. }
  17665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17666. {
  17667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17668. {
  17669. tempIndex = ((gun_index==2) ? 1: 0);
  17670. }
  17671. else
  17672. {
  17673. tempIndex = gun_index;
  17674. }
  17675. for (int index = 0; index < CCS_QUANTITY; index++)
  17676. {
  17677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17678. {
  17679. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17680. }
  17681. } // END for CCS_QUANTITY
  17682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17683. }
  17684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17685. {
  17686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17687. {
  17688. tempIndex = ((gun_index==2) ? 1: 0);
  17689. }
  17690. else
  17691. {
  17692. tempIndex = gun_index;
  17693. }
  17694. for (int index = 0; index < GB_QUANTITY; index++)
  17695. {
  17696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17697. {
  17698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17699. }
  17700. }// END for GB_QUANTITY
  17701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17702. }
  17703. else if(gunType[gun_index] == GUN_TYPE_DO)
  17704. {
  17705. tempIndex = gun_index;
  17706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17707. {
  17708. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17709. {
  17710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17711. }
  17712. }
  17713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17714. }
  17715. else
  17716. {
  17717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17718. {
  17719. tempIndex = 2;
  17720. }
  17721. else
  17722. {
  17723. tempIndex = gun_index;
  17724. }
  17725. for (int index = 0; index < AC_QUANTITY; index++)
  17726. {
  17727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17728. {
  17729. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17730. }
  17731. } // END for AC_QUANTITY
  17732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17733. }
  17734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17737. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17740. }
  17741. //2.4====================================== Voltage L1 ====================================================
  17742. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17743. {
  17744. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17745. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17746. {
  17747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17748. {
  17749. tempIndex = ((gun_index==2) ? 1: 0);
  17750. }
  17751. else
  17752. {
  17753. tempIndex = gun_index;
  17754. }
  17755. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17756. {
  17757. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17758. {
  17759. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17760. }
  17761. } // END OF FOR CHAdeMO_QUANTITY
  17762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17763. }
  17764. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17765. {
  17766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17767. {
  17768. tempIndex = ((gun_index==2) ? 1: 0);
  17769. }
  17770. else
  17771. {
  17772. tempIndex = gun_index;
  17773. }
  17774. for (int index = 0; index < CCS_QUANTITY; index++)
  17775. {
  17776. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17777. {
  17778. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17779. }
  17780. } // END OF FOR CCS_QUANTITY
  17781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17782. }
  17783. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17784. {
  17785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17786. {
  17787. tempIndex = ((gun_index==2) ? 1: 0);
  17788. }
  17789. else
  17790. {
  17791. tempIndex = gun_index;
  17792. }
  17793. for (int index = 0; index < GB_QUANTITY; index++)
  17794. {
  17795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17796. {
  17797. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17798. }
  17799. } // END OF FOR GB_QUANTITY
  17800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17801. }
  17802. else if(gunType[gun_index] == GUN_TYPE_DO)
  17803. {
  17804. tempIndex = gun_index;
  17805. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17806. {
  17807. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17808. {
  17809. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17810. }
  17811. }
  17812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17813. }
  17814. else
  17815. {
  17816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17817. {
  17818. tempIndex = 2;
  17819. }
  17820. else
  17821. {
  17822. tempIndex = gun_index;
  17823. }
  17824. for (int index = 0; index < AC_QUANTITY; index++)
  17825. {
  17826. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17827. {
  17828. 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
  17829. }
  17830. } // END OF FOR AC_QUANTITY
  17831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17832. }
  17833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17836. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17839. }
  17840. //2.5============================================== End SoC =========================================================
  17841. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17842. {
  17843. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17844. 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))
  17845. {
  17846. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17847. {
  17848. tempIndex = ((gun_index==2) ? 1: 0);
  17849. }
  17850. else
  17851. {
  17852. tempIndex = gun_index;
  17853. }
  17854. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17855. {
  17856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17857. {
  17858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17859. {
  17860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17861. }
  17862. }
  17863. }
  17864. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17865. {
  17866. for (int index = 0; index < CCS_QUANTITY; index++)
  17867. {
  17868. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17869. {
  17870. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17871. }
  17872. }
  17873. }
  17874. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17875. {
  17876. for (int index = 0; index < GB_QUANTITY; index++)
  17877. {
  17878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17879. {
  17880. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17881. }
  17882. }
  17883. }
  17884. else if(gunType[gun_index] == GUN_TYPE_DO)
  17885. {
  17886. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17887. {
  17888. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17889. {
  17890. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17891. }
  17892. }
  17893. }
  17894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17900. } // END FOR DC CASE
  17901. }
  17902. //2.6====================================== Current.Import L2 ==============================================
  17903. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17904. {
  17905. // AC 3 phase L2 current
  17906. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17907. {
  17908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17909. {
  17910. tempIndex = 2;
  17911. }
  17912. else
  17913. {
  17914. tempIndex = gun_index;
  17915. }
  17916. for (int index = 0; index < AC_QUANTITY; index++)
  17917. {
  17918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17919. {
  17920. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17921. }
  17922. }// End of for AC_QUANTITY
  17923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17924. }
  17925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17926. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17930. }
  17931. //2.7====================================== Current.Import L3 ==============================================
  17932. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17933. {
  17934. // AC 3 phase L3 current
  17935. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17936. {
  17937. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17938. {
  17939. tempIndex = 2;
  17940. }
  17941. else
  17942. {
  17943. tempIndex = gun_index;
  17944. }
  17945. for (int index = 0; index < AC_QUANTITY; index++)
  17946. {
  17947. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17948. {
  17949. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17950. }
  17951. }// End of for AC_QUANTITY
  17952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17953. }
  17954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17959. }
  17960. //2.9====================================== Voltage L2 ====================================================
  17961. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17962. {
  17963. // AC 3 phase L2 volatge
  17964. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17965. {
  17966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17967. {
  17968. tempIndex = 2;
  17969. }
  17970. else
  17971. {
  17972. tempIndex = gun_index;
  17973. }
  17974. for (int index = 0; index < AC_QUANTITY; index++)
  17975. {
  17976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17977. {
  17978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  17979. }
  17980. } // END OF FOR AC_QUANTITY
  17981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17982. }
  17983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17988. }
  17989. //2.10====================================== Voltage L3 ====================================================
  17990. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17991. {
  17992. // AC 3 phase L3 volatge
  17993. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17994. {
  17995. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17996. {
  17997. tempIndex = 2;
  17998. }
  17999. else
  18000. {
  18001. tempIndex = gun_index;
  18002. }
  18003. for (int index = 0; index < AC_QUANTITY; index++)
  18004. {
  18005. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18006. {
  18007. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  18008. }
  18009. } // END OF FOR AC_QUANTITY
  18010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18011. }
  18012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18017. }
  18018. //====================== Start SoC ================================
  18019. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18020. {
  18021. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18022. 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))
  18023. {
  18024. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18025. {
  18026. tempIndex = ((gun_index==2) ? 1: 0);
  18027. }
  18028. else
  18029. {
  18030. tempIndex = gun_index;
  18031. }
  18032. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18033. {
  18034. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18035. {
  18036. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18037. {
  18038. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18039. }
  18040. }
  18041. }
  18042. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18043. {
  18044. for (int index = 0; index < CCS_QUANTITY; index++)
  18045. {
  18046. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18047. {
  18048. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18049. }
  18050. }
  18051. }
  18052. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18053. {
  18054. for (int index = 0; index < GB_QUANTITY; index++)
  18055. {
  18056. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18057. {
  18058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18059. }
  18060. }
  18061. }
  18062. else if(gunType[gun_index] == GUN_TYPE_DO)
  18063. {
  18064. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18065. {
  18066. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18067. {
  18068. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18069. }
  18070. }
  18071. }
  18072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18078. } // END FOR DC CASE
  18079. }
  18080. //======================================== Message create ==============================================
  18081. json_object *StopTransaction = json_object_new_object();
  18082. json_object *transactionDatas = json_object_new_array();
  18083. json_object *sampledValues = json_object_new_array();
  18084. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18085. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18086. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18087. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18088. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18089. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18090. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18091. {
  18092. json_object *transactionData = json_object_new_object();
  18093. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18094. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18095. {
  18096. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18097. {
  18098. json_object *sampledValue = json_object_new_object();
  18099. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18100. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18101. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18102. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18103. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18104. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18105. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18106. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18107. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18108. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18109. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18110. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18111. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18112. json_object_array_add(sampledValues, sampledValue);
  18113. }
  18114. }
  18115. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18116. json_object_array_add(transactionDatas, transactionData);
  18117. }
  18118. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18119. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18120. ,MESSAGE_TYPE_CALL
  18121. ,guid
  18122. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18123. json_object_put(StopTransaction);
  18124. // Check File "TempStopTransaction" Exist
  18125. if((access(TempStopTransaction,F_OK))!=-1)
  18126. {
  18127. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18128. fclose(fopen(TempStopTransaction, "w"));
  18129. }
  18130. else
  18131. {
  18132. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18133. FILE *log = fopen(TempStopTransaction, "w+");
  18134. if(log == NULL)
  18135. {
  18136. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18137. return ;
  18138. }
  18139. else
  18140. {
  18141. fclose(log);
  18142. }
  18143. }
  18144. //Add TempStopTransaction | Update TempStopTransaction
  18145. // open file for writing
  18146. FILE *outfile;
  18147. outfile = fopen (TempStopTransaction, "a");
  18148. //DEBUG_INFO("data = %s\n", queuedata);
  18149. fputs(queuedata, outfile);
  18150. fputs("\n", outfile);
  18151. fclose (outfile);
  18152. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18153. OCPP_updatePeriodEnergy(gun_index);
  18154. }
  18155. void checkTempStopTransaction(int gun_index)
  18156. {
  18157. FILE *fptr1;
  18158. char ch;
  18159. char str[QUEUE_MESSAGE_LENGTH]={0};
  18160. char guid[37]={0};
  18161. char tempdata[65]={0};
  18162. char connectorStr[2]={0};
  18163. char TempStopTransaction[256];
  18164. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18165. fptr1 = fopen(TempStopTransaction, "r");
  18166. //TempStopTransaction格式: 槍號,StopTransaction封包
  18167. if (!fptr1)
  18168. {
  18169. //printf(" File not found or unable to open the input file!!\n");
  18170. return ;
  18171. }
  18172. ch=fgetc(fptr1);
  18173. //printf(" Now the content of the file %s is : \n",fname);
  18174. rewind(fptr1);
  18175. if(ch!=EOF)
  18176. {
  18177. // copy all contents to the temporary file except the specific line
  18178. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18179. {
  18180. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18181. if(str[0]=='\0')
  18182. {
  18183. break;
  18184. }
  18185. //TempStopTransaction格式: 槍號,StopTransaction封包
  18186. strncpy(connectorStr, str, 1);
  18187. if(atoi(connectorStr) != (gun_index+1))
  18188. {
  18189. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18190. fclose(fptr1);
  18191. return ;
  18192. }
  18193. //random_uuid(guid);
  18194. strncpy(guid, str+6, 36); //copy guid
  18195. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18196. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18197. {
  18198. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18199. }
  18200. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18201. OCPP_insert_transaction_msg(NO, str);
  18202. memset(str,0,ARRAY_SIZE(str));
  18203. }
  18204. }
  18205. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18206. fclose(fptr1);
  18207. remove(TempStopTransaction); // remove the original file
  18208. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18209. }
  18210. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18211. {
  18212. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18213. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18214. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18215. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18216. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18217. }
  18218. int GetWebSocketPingInterval(void)
  18219. {
  18220. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18221. }
  18222. int GetServerSign(void)
  18223. {
  18224. return server_sign;
  18225. }
  18226. uint8_t GetOcppSecurityProfile()
  18227. {
  18228. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18229. }
  18230. void GetOcppChargerBoxId(uint8_t *data)
  18231. {
  18232. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18233. }
  18234. void GetOcppSecurityPassword(uint8_t *data)
  18235. {
  18236. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18237. }
  18238. void SetOcppVersion(uint8_t *version)
  18239. {
  18240. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18241. DEBUG_INFO("ocpp version: %s\n", version);
  18242. if(strstr((char*)version, "ocpp1.6") != NULL)
  18243. {
  18244. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18245. }
  18246. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18247. {
  18248. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18249. system("pkill OcppBackend");
  18250. }
  18251. }
  18252. void SetServerSign(int value)
  18253. {
  18254. server_sign = value;
  18255. }
  18256. int GetBootNotificationInterval(void)
  18257. {
  18258. return BootNotificationInterval;
  18259. }
  18260. int GetInternetConn(void)
  18261. {
  18262. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18263. }
  18264. int GetBackendConnectionTimeout(void)
  18265. {
  18266. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18267. }
  18268. int isConnectorInitMode(int gun_index)
  18269. {
  18270. int tempIndex = 0;
  18271. int result = TRUE;
  18272. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18273. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18274. {
  18275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18276. {
  18277. tempIndex = ((gun_index==2) ? 1: 0);
  18278. }
  18279. else
  18280. {
  18281. tempIndex = gun_index;
  18282. }
  18283. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18284. {
  18285. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18286. {
  18287. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18288. } //end of the same index
  18289. }//end of for CHAdeMO_QUANTITY
  18290. }
  18291. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18292. {
  18293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18294. {
  18295. tempIndex = ((gun_index==2) ? 1: 0);
  18296. }
  18297. else
  18298. {
  18299. tempIndex = gun_index;
  18300. }
  18301. for (int index = 0; index < CCS_QUANTITY; index++)
  18302. {
  18303. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18304. {
  18305. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18306. } //end of the same index
  18307. } // end of for CCS_QUANTITY
  18308. }
  18309. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18310. {
  18311. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18312. {
  18313. tempIndex = ((gun_index==2) ? 1: 0);
  18314. }
  18315. else
  18316. {
  18317. tempIndex = gun_index;
  18318. }
  18319. for (int index = 0; index < GB_QUANTITY; index++)
  18320. {
  18321. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18322. {
  18323. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18324. } //end of the same index
  18325. } // end of for GB_QUANTITY
  18326. }
  18327. else if(gunType[gun_index] == GUN_TYPE_DO)
  18328. {
  18329. tempIndex = gun_index;
  18330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18331. {
  18332. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18333. {
  18334. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18335. } //end of the same index
  18336. }
  18337. }
  18338. else
  18339. {
  18340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18341. {
  18342. tempIndex = 2;
  18343. }
  18344. else
  18345. {
  18346. tempIndex = gun_index;
  18347. }
  18348. for (int index = 0; index < AC_QUANTITY; index++)
  18349. {
  18350. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18351. {
  18352. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18353. }//end of the same index
  18354. }//end of for AC_QUANTITY
  18355. }
  18356. return result;
  18357. }
  18358. void refreshProcDogTimer()
  18359. {
  18360. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18361. }
  18362. void InitialSystemValue(void)
  18363. {
  18364. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18365. locallistVersion=0;
  18366. BootNotificationInterval = 0;
  18367. authorizeRetryTimes = 0;
  18368. GunStatusInterval = 10;
  18369. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18370. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18371. //Hear Beat
  18372. HeartBeatWithNOResponse = 0;
  18373. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18374. FirstHeartBeat = 0;
  18375. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18376. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18377. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18378. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18379. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18380. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18381. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18382. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18383. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18384. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18385. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18386. //Status && ConnectorPlugIn Setting
  18387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18388. {
  18389. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18390. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18391. }
  18392. for (int index = 0; index < CCS_QUANTITY; index++)
  18393. {
  18394. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18395. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18396. }
  18397. for (int index = 0; index < GB_QUANTITY; index++)
  18398. {
  18399. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18400. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18401. }
  18402. for (int index = 0; index < AC_QUANTITY; index++)
  18403. {
  18404. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18405. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18406. }
  18407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18408. {
  18409. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18410. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18411. }
  18412. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18413. {
  18414. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18415. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18416. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18417. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18418. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18419. }
  18420. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18421. refreshStartTimer(&clientTime.Heartbeat);
  18422. sleep(1);
  18423. }
  18424. void LWS_Send(char *str)
  18425. {
  18426. //=====================================================
  18427. // Check InternetConn 0: disconnected, 1: connected
  18428. //====================================================
  18429. if(GetOcppConnStatus() == 0)
  18430. {
  18431. DEBUG_INFO("offline now !!!\n");
  18432. return;
  18433. }
  18434. // Only disable isWebsocketSendable operation initiated by charger
  18435. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18436. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18437. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18438. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18439. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18440. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18441. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18442. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18443. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18444. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18445. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18446. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18447. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18448. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18449. {
  18450. isWebsocketSendable = 0;
  18451. }
  18452. pthread_mutex_lock(&lock_send);
  18453. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18454. sprintf((char *)SendBuffer, "%s", str);
  18455. SendBufLen = strlen(str);
  18456. pthread_mutex_unlock(&lock_send);
  18457. lws_callback_on_writable(wsi_client);
  18458. //lws_service(context, 0);
  18459. //sleep(1);
  18460. }
  18461. void LWS_SendNow(char *str)
  18462. {
  18463. //=====================================================
  18464. // Check InternetConn 0: disconnected, 1: connected
  18465. //====================================================
  18466. if(GetOcppConnStatus() == 0)
  18467. {
  18468. DEBUG_INFO("offline now !!!\n");
  18469. return;
  18470. }
  18471. // Only disable isWebsocketSendable operation initiated by charger
  18472. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18473. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18474. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18475. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18476. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18477. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18478. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18479. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18480. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18481. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18482. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18483. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18484. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18485. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18486. {
  18487. isWebsocketSendable = 0;
  18488. }
  18489. pthread_mutex_lock(&lock_send);
  18490. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18491. sprintf((char *)SendBuffer, "%s", str);
  18492. SendBufLen = strlen(str);
  18493. pthread_mutex_unlock(&lock_send);
  18494. lws_callback_on_writable(wsi_client);
  18495. lws_service(context, 0);
  18496. //sleep(1);
  18497. }