MessageHandler.c 932 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263
  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 *targetCompositeProfile, 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. struct StructChargingProfile compositeProfile;
  1485. uint8_t limitMax=0;
  1486. int compositePeriodIdx = 0;
  1487. CurrentTime = time(NULL);
  1488. tmComposite=localtime(&CurrentTime);
  1489. 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);
  1490. if(isUnitA)
  1491. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1492. else
  1493. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1494. compositeProfile.ChargingSchedule.Duration = durationReq;
  1495. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1496. {
  1497. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1498. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1499. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1500. }
  1501. compositeProfile.ChargingProfileId = 0;
  1502. compositeProfile.StackLevel = 99 ;
  1503. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1504. maxProfile.ChargingProfileId = -1;
  1505. maxProfile.ChargingSchedule.Duration = -1;
  1506. system("rm -f /tmp/*.json");
  1507. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1508. // Search max profile
  1509. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1510. if((access(profileFileName, F_OK))!=-1)
  1511. {
  1512. fp = fopen(profileFileName, "r");
  1513. while(getline(&line, &len, fp) != -1)
  1514. {
  1515. json_object *obj = NULL;
  1516. obj = json_tokener_parse(line);
  1517. if(is_error(obj))
  1518. {
  1519. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1520. }
  1521. else
  1522. {
  1523. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1524. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1525. )
  1526. {
  1527. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1528. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1529. )
  1530. {
  1531. struct tm tmFrom, tmTo;
  1532. struct timeb tbFrom, tbTo;
  1533. 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) &&
  1534. (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))
  1535. {
  1536. tmFrom.tm_year -= 1900;
  1537. tmFrom.tm_mon -= 1;
  1538. tbFrom.time = mktime(&tmFrom);
  1539. tmTo.tm_year -= 1900;
  1540. tmTo.tm_mon -= 1;
  1541. tbTo.time = mktime(&tmTo);
  1542. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1543. {
  1544. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1545. {
  1546. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1547. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1548. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1549. }
  1550. maxProfile.ChargingProfileId = -1;
  1551. maxProfile.StackLevel = -1;
  1552. if(maxProfile.ChargingProfileId == -1)
  1553. DEBUG_INFO("MaxProfile found.\n");
  1554. else
  1555. DEBUG_INFO("MaxProfile updated.\n");
  1556. // Required item
  1557. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1558. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1559. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1560. if(isUnitA)
  1561. {
  1562. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1563. 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++)
  1564. {
  1565. 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"));
  1566. 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?
  1567. 3:
  1568. 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")));
  1569. 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")));
  1570. }
  1571. }
  1572. else
  1573. {
  1574. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1575. 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++)
  1576. {
  1577. 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"));
  1578. 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?
  1579. 3:
  1580. 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")));
  1581. 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));
  1582. }
  1583. }
  1584. // Optional item
  1585. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1586. {
  1587. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1588. }
  1589. else
  1590. {
  1591. sprintf((char*)maxProfile.ValidFrom, " ");
  1592. }
  1593. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1594. {
  1595. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1596. }
  1597. else
  1598. {
  1599. sprintf((char*)maxProfile.ValidTo, " ");
  1600. }
  1601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1602. {
  1603. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1604. }
  1605. else
  1606. {
  1607. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1608. }
  1609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1610. {
  1611. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1612. }
  1613. else
  1614. {
  1615. maxProfile.TransactionId = -1;
  1616. }
  1617. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1618. {
  1619. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1620. }
  1621. else
  1622. {
  1623. maxProfile.ChargingSchedule.Duration = 86400;
  1624. }
  1625. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1626. {
  1627. 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")));
  1628. }
  1629. else
  1630. {
  1631. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1632. }
  1633. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1634. {
  1635. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1636. }
  1637. else
  1638. {
  1639. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1640. }
  1641. }
  1642. }
  1643. }
  1644. else
  1645. {
  1646. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1647. {
  1648. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1649. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1650. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1651. }
  1652. maxProfile.ChargingProfileId = -1;
  1653. maxProfile.StackLevel = -1;
  1654. if(maxProfile.ChargingProfileId == -1)
  1655. DEBUG_INFO("MaxProfile found.\n");
  1656. else
  1657. DEBUG_INFO("MaxProfile updated.\n");
  1658. // Required item
  1659. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1660. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1661. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1662. if(isUnitA)
  1663. {
  1664. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1665. 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++)
  1666. {
  1667. 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"));
  1668. 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?
  1669. 3:
  1670. 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")));
  1671. 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")));
  1672. }
  1673. }
  1674. else
  1675. {
  1676. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1677. 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++)
  1678. {
  1679. 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"));
  1680. 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?
  1681. 3:
  1682. 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")));
  1683. 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));
  1684. }
  1685. }
  1686. // Optional item
  1687. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1688. {
  1689. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1690. }
  1691. else
  1692. {
  1693. sprintf((char*)maxProfile.ValidFrom, " ");
  1694. }
  1695. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1696. {
  1697. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1698. }
  1699. else
  1700. {
  1701. sprintf((char*)maxProfile.ValidTo, " ");
  1702. }
  1703. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1704. {
  1705. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1706. }
  1707. else
  1708. {
  1709. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1710. }
  1711. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1712. {
  1713. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1714. }
  1715. else
  1716. {
  1717. maxProfile.TransactionId = -1;
  1718. }
  1719. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1720. {
  1721. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1722. }
  1723. else
  1724. {
  1725. maxProfile.ChargingSchedule.Duration = 86400;
  1726. }
  1727. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1728. {
  1729. 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")));
  1730. }
  1731. else
  1732. {
  1733. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1734. }
  1735. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1736. {
  1737. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1738. }
  1739. else
  1740. {
  1741. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1742. }
  1743. }
  1744. }
  1745. }
  1746. json_object_put(obj);
  1747. }
  1748. fclose(fp);
  1749. /*
  1750. if(maxProfile.ChargingProfileId !=-1)
  1751. {
  1752. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1753. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1754. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1755. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1756. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1757. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1758. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1759. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1760. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1761. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1762. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1763. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1764. {
  1765. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1766. {
  1767. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1768. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1769. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1770. }
  1771. }
  1772. }
  1773. else
  1774. DEBUG_INFO("MaxProfile not found.\n");
  1775. DEBUG_INFO("------------------------------------\n");*/
  1776. }
  1777. if(maxProfile.ChargingProfileId != -1)
  1778. {
  1779. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1780. {
  1781. if(maxProfile.ChargingSchedule.Duration != -1)
  1782. {
  1783. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1784. 0:
  1785. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1786. }
  1787. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1788. {
  1789. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1790. {
  1791. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1792. 0:
  1793. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1794. if(idxPeriod > 0)
  1795. {
  1796. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1797. {
  1798. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1805. {
  1806. if(maxProfile.ChargingSchedule.Duration != -1)
  1807. {
  1808. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1809. }
  1810. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1811. {
  1812. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1813. {
  1814. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1815. if(idxPeriod > 0)
  1816. {
  1817. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1818. {
  1819. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. else
  1826. {
  1827. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1828. {
  1829. if(maxProfile.ChargingSchedule.Duration != -1)
  1830. {
  1831. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1832. 0:
  1833. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1834. }
  1835. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1836. {
  1837. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1838. {
  1839. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1840. 0:
  1841. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1842. if(idxPeriod > 0)
  1843. {
  1844. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1845. {
  1846. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1847. }
  1848. }
  1849. }
  1850. }
  1851. }
  1852. else
  1853. {
  1854. if(maxProfile.ChargingSchedule.Duration != -1)
  1855. {
  1856. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1857. 0:
  1858. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1859. }
  1860. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1861. {
  1862. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1863. {
  1864. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1865. 0:
  1866. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1867. if(idxPeriod > 0)
  1868. {
  1869. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1870. {
  1871. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. }
  1878. /*
  1879. DEBUG_INFO("MaxProfile after align.\n");
  1880. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1881. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1882. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1883. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1884. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1885. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1886. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1887. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1888. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1889. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1890. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1891. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1892. {
  1893. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1894. {
  1895. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1896. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1897. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1898. }
  1899. }
  1900. DEBUG_INFO("------------------------------------\n");*/
  1901. }
  1902. // Find each profile period quantity
  1903. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1904. {
  1905. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1906. limitMax = idx+1;
  1907. }
  1908. if(maxProfile.ChargingProfileId != -1)
  1909. {
  1910. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1911. {
  1912. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1913. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1914. (maxProfile.ChargingSchedule.Duration > 0))
  1915. {
  1916. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1917. {
  1918. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1919. compositePeriodIdx++;
  1920. }
  1921. else
  1922. {
  1923. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1924. }
  1925. }
  1926. }
  1927. }
  1928. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1929. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1930. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1931. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1932. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1933. {
  1934. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1935. {
  1936. compositeProfile.ChargingProfileId = 1;
  1937. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1938. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1939. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1940. }
  1941. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1942. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1943. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1944. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1945. }
  1946. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1947. if(line)
  1948. free(line);
  1949. }
  1950. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1951. {
  1952. FILE *fp;
  1953. char profileFileName[128];
  1954. char *line = NULL;
  1955. size_t len = 0;
  1956. time_t CurrentTime;
  1957. struct tm *tmComposite;
  1958. struct StructChargingProfile maxProfile;
  1959. struct StructChargingProfile defaultTxProfile;
  1960. struct StructChargingProfile txProfile;
  1961. struct StructChargingProfile compositeProfile;
  1962. struct StructChargingSchedulePeriod tmpPeriod;
  1963. uint8_t limitMax=0;
  1964. uint8_t limitDef=0;
  1965. uint8_t limitTx=0;
  1966. int compositePeriodIdx = 0;
  1967. CurrentTime = time(NULL);
  1968. tmComposite=localtime(&CurrentTime);
  1969. 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);
  1970. if(isUnitA)
  1971. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1972. else
  1973. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1974. compositeProfile.ChargingSchedule.Duration = durationReq;
  1975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1976. {
  1977. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1978. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1979. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1980. }
  1981. compositeProfile.ChargingProfileId = 0;
  1982. compositeProfile.StackLevel = 99 ;
  1983. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1984. maxProfile.ChargingProfileId = -1;
  1985. defaultTxProfile.ChargingProfileId = -1;
  1986. txProfile.ChargingProfileId = -1;
  1987. maxProfile.ChargingSchedule.Duration = -1;
  1988. defaultTxProfile.ChargingSchedule.Duration = -1;
  1989. txProfile.ChargingSchedule.Duration = -1;
  1990. system("rm -f /tmp/*.json");
  1991. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1992. /*
  1993. * Search valid charging profile
  1994. */
  1995. //DEBUG_INFO("====================================\n");
  1996. // Search tx profile
  1997. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1998. if((access(profileFileName, F_OK))!=-1)
  1999. {
  2000. fp = fopen(profileFileName, "r");
  2001. while(getline(&line, &len, fp) != -1)
  2002. {
  2003. json_object *obj = NULL;
  2004. obj = json_tokener_parse(line);
  2005. if(is_error(obj))
  2006. {
  2007. DEBUG_ERROR("Parse txProfile from file error.\n");
  2008. }
  2009. else
  2010. {
  2011. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2012. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2013. )
  2014. {
  2015. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2016. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2017. )
  2018. {
  2019. struct tm tmFrom, tmTo;
  2020. struct timeb tbFrom, tbTo;
  2021. 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) &&
  2022. (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))
  2023. {
  2024. tmFrom.tm_year -= 1900;
  2025. tmFrom.tm_mon -= 1;
  2026. tbFrom.time = mktime(&tmFrom);
  2027. tmTo.tm_year -= 1900;
  2028. tmTo.tm_mon -= 1;
  2029. tbTo.time = mktime(&tmTo);
  2030. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2031. {
  2032. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2033. {
  2034. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2036. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2037. }
  2038. txProfile.ChargingProfileId = -1;
  2039. txProfile.StackLevel = -1;
  2040. if(txProfile.ChargingProfileId == -1)
  2041. DEBUG_INFO("TxProfile found.\n");
  2042. else
  2043. DEBUG_INFO("TxProfile updated.\n");
  2044. // Required item
  2045. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2046. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2047. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2048. if(isUnitA)
  2049. {
  2050. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2051. 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++)
  2052. {
  2053. 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"));
  2054. 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?
  2055. 3:
  2056. 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")));
  2057. 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")));
  2058. }
  2059. }
  2060. else
  2061. {
  2062. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2063. 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++)
  2064. {
  2065. 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"));
  2066. 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?
  2067. 3:
  2068. 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")));
  2069. 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));
  2070. }
  2071. }
  2072. // Optional item
  2073. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2074. {
  2075. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2076. }
  2077. else
  2078. {
  2079. sprintf((char*)txProfile.ValidFrom, " ");
  2080. }
  2081. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2082. {
  2083. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2084. }
  2085. else
  2086. {
  2087. sprintf((char*)txProfile.ValidTo, " ");
  2088. }
  2089. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2090. {
  2091. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2092. }
  2093. else
  2094. {
  2095. sprintf((char*)txProfile.RecurrencyKind, " ");
  2096. }
  2097. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2098. {
  2099. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2100. }
  2101. else
  2102. {
  2103. txProfile.TransactionId = -1;
  2104. }
  2105. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2106. {
  2107. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2108. }
  2109. else
  2110. {
  2111. txProfile.ChargingSchedule.Duration = 86400;
  2112. }
  2113. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2114. {
  2115. 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")));
  2116. }
  2117. else
  2118. {
  2119. 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));
  2120. }
  2121. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2122. {
  2123. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2124. }
  2125. else
  2126. {
  2127. txProfile.ChargingSchedule.MinChargingRate = -1;
  2128. }
  2129. }
  2130. }
  2131. }
  2132. else
  2133. {
  2134. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2135. {
  2136. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2137. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2138. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2139. }
  2140. txProfile.ChargingProfileId = -1;
  2141. txProfile.StackLevel = -1;
  2142. if(txProfile.ChargingProfileId == -1)
  2143. DEBUG_INFO("TxProfile found.\n");
  2144. else
  2145. DEBUG_INFO("TxProfile updated.\n");
  2146. // Required item
  2147. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2148. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2149. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2150. if(isUnitA)
  2151. {
  2152. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2153. 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++)
  2154. {
  2155. 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"));
  2156. 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?
  2157. 3:
  2158. 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")));
  2159. 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")));
  2160. }
  2161. }
  2162. else
  2163. {
  2164. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2165. 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++)
  2166. {
  2167. 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"));
  2168. 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?
  2169. 3:
  2170. 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")));
  2171. 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));
  2172. }
  2173. }
  2174. // Optional item
  2175. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2176. {
  2177. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2178. }
  2179. else
  2180. {
  2181. sprintf((char*)txProfile.ValidFrom, " ");
  2182. }
  2183. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2184. {
  2185. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2186. }
  2187. else
  2188. {
  2189. sprintf((char*)txProfile.ValidTo, " ");
  2190. }
  2191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2192. {
  2193. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2194. }
  2195. else
  2196. {
  2197. sprintf((char*)txProfile.RecurrencyKind, " ");
  2198. }
  2199. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2200. {
  2201. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2202. }
  2203. else
  2204. {
  2205. txProfile.TransactionId = -1;
  2206. }
  2207. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2208. {
  2209. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2210. }
  2211. else
  2212. {
  2213. txProfile.ChargingSchedule.Duration = 86400;
  2214. }
  2215. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2216. {
  2217. 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")));
  2218. }
  2219. else
  2220. {
  2221. 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));
  2222. }
  2223. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2224. {
  2225. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2226. }
  2227. else
  2228. {
  2229. txProfile.ChargingSchedule.MinChargingRate = -1;
  2230. }
  2231. }
  2232. }
  2233. }
  2234. json_object_put(obj);
  2235. }
  2236. fclose(fp);
  2237. /*
  2238. if(txProfile.ChargingProfileId != -1)
  2239. {
  2240. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2241. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2242. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2243. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2244. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2245. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2246. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2247. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2248. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2249. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2250. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2251. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2252. {
  2253. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2254. {
  2255. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2256. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2257. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2258. }
  2259. }
  2260. }
  2261. else
  2262. DEBUG_INFO("TxProfile not found.\n");*/
  2263. }
  2264. // Search default tx profile
  2265. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2266. if((access(profileFileName, F_OK))==-1)
  2267. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2268. if((access(profileFileName, F_OK))!=-1)
  2269. {
  2270. fp = fopen(profileFileName, "r");
  2271. while(getline(&line, &len, fp) != -1)
  2272. {
  2273. json_object *obj = NULL;
  2274. obj = json_tokener_parse(line);
  2275. if(is_error(obj))
  2276. {
  2277. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2278. }
  2279. else
  2280. {
  2281. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2282. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2283. )
  2284. {
  2285. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2286. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2287. )
  2288. {
  2289. struct tm tmFrom, tmTo;
  2290. struct timeb tbFrom, tbTo;
  2291. 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) &&
  2292. (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))
  2293. {
  2294. tmFrom.tm_year -= 1900;
  2295. tmFrom.tm_mon -= 1;
  2296. tbFrom.time = mktime(&tmFrom);
  2297. tmTo.tm_year -= 1900;
  2298. tmTo.tm_mon -= 1;
  2299. tbTo.time = mktime(&tmTo);
  2300. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2301. {
  2302. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2303. {
  2304. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2305. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2306. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2307. }
  2308. defaultTxProfile.ChargingProfileId = -1;
  2309. defaultTxProfile.StackLevel = -1;
  2310. if(defaultTxProfile.ChargingProfileId == -1)
  2311. DEBUG_INFO("TxDefaultProfile found.\n");
  2312. else
  2313. DEBUG_INFO("TxDefaultProfile updated.\n");
  2314. // Required item
  2315. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2316. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2317. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2318. if(isUnitA)
  2319. {
  2320. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2321. 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++)
  2322. {
  2323. 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"));
  2324. 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?
  2325. 3:
  2326. 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")));
  2327. 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")));
  2328. }
  2329. }
  2330. else
  2331. {
  2332. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2333. 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++)
  2334. {
  2335. 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"));
  2336. 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?
  2337. 3:
  2338. 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")));
  2339. 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));
  2340. }
  2341. }
  2342. // Optional item
  2343. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2344. {
  2345. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2346. }
  2347. else
  2348. {
  2349. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2350. }
  2351. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2352. {
  2353. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2354. }
  2355. else
  2356. {
  2357. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2358. }
  2359. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2360. {
  2361. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2362. }
  2363. else
  2364. {
  2365. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2366. }
  2367. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2368. {
  2369. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2370. }
  2371. else
  2372. {
  2373. defaultTxProfile.TransactionId = -1;
  2374. }
  2375. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2376. {
  2377. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2378. }
  2379. else
  2380. {
  2381. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2382. }
  2383. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2384. {
  2385. 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")));
  2386. }
  2387. else
  2388. {
  2389. 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));
  2390. }
  2391. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2392. {
  2393. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2394. }
  2395. else
  2396. {
  2397. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2398. }
  2399. }
  2400. }
  2401. }
  2402. else
  2403. {
  2404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2405. {
  2406. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2407. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2409. }
  2410. defaultTxProfile.ChargingProfileId = -1;
  2411. defaultTxProfile.StackLevel = -1;
  2412. if(defaultTxProfile.ChargingProfileId == -1)
  2413. DEBUG_INFO("TxDefaultProfile found.\n");
  2414. else
  2415. DEBUG_INFO("TxDefaultProfile updated.\n");
  2416. // Required item
  2417. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2418. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2419. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2420. if(isUnitA)
  2421. {
  2422. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2423. 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++)
  2424. {
  2425. 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"));
  2426. 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?
  2427. 3:
  2428. 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")));
  2429. 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")));
  2430. }
  2431. }
  2432. else
  2433. {
  2434. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2435. 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++)
  2436. {
  2437. 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"));
  2438. 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?
  2439. 3:
  2440. 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")));
  2441. 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));
  2442. }
  2443. }
  2444. // Optional item
  2445. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2446. {
  2447. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2448. }
  2449. else
  2450. {
  2451. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2452. }
  2453. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2454. {
  2455. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2456. }
  2457. else
  2458. {
  2459. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2460. }
  2461. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2462. {
  2463. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2464. }
  2465. else
  2466. {
  2467. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2468. }
  2469. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2470. {
  2471. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2472. }
  2473. else
  2474. {
  2475. defaultTxProfile.TransactionId = -1;
  2476. }
  2477. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2478. {
  2479. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2480. }
  2481. else
  2482. {
  2483. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2484. }
  2485. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2486. {
  2487. 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")));
  2488. }
  2489. else
  2490. {
  2491. 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));
  2492. }
  2493. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2494. {
  2495. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2496. }
  2497. else
  2498. {
  2499. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2500. }
  2501. }
  2502. }
  2503. }
  2504. json_object_put(obj);
  2505. }
  2506. fclose(fp);
  2507. /*
  2508. if(defaultTxProfile.ChargingProfileId != -1)
  2509. {
  2510. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2511. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2512. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2513. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2514. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2515. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2516. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2517. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2518. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2519. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2520. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2521. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2522. {
  2523. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2524. {
  2525. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2526. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2527. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2528. }
  2529. }
  2530. }
  2531. else
  2532. DEBUG_INFO("TxDefaultProfile not found.\n");
  2533. DEBUG_INFO("------------------------------------\n");*/
  2534. }
  2535. // Search max profile
  2536. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2537. if((access(profileFileName, F_OK))!=-1)
  2538. {
  2539. fp = fopen(profileFileName, "r");
  2540. while(getline(&line, &len, fp) != -1)
  2541. {
  2542. json_object *obj = NULL;
  2543. obj = json_tokener_parse(line);
  2544. if(is_error(obj))
  2545. {
  2546. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2547. }
  2548. else
  2549. {
  2550. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2551. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2552. )
  2553. {
  2554. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2555. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2556. )
  2557. {
  2558. struct tm tmFrom, tmTo;
  2559. struct timeb tbFrom, tbTo;
  2560. 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) &&
  2561. (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))
  2562. {
  2563. tmFrom.tm_year -= 1900;
  2564. tmFrom.tm_mon -= 1;
  2565. tbFrom.time = mktime(&tmFrom);
  2566. tmTo.tm_year -= 1900;
  2567. tmTo.tm_mon -= 1;
  2568. tbTo.time = mktime(&tmTo);
  2569. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2570. {
  2571. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2572. {
  2573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2576. }
  2577. maxProfile.ChargingProfileId = -1;
  2578. maxProfile.StackLevel = -1;
  2579. if(maxProfile.ChargingProfileId == -1)
  2580. DEBUG_INFO("MaxProfile found.\n");
  2581. else
  2582. DEBUG_INFO("MaxProfile updated.\n");
  2583. // Required item
  2584. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2585. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2586. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2587. if(isUnitA)
  2588. {
  2589. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2590. 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++)
  2591. {
  2592. 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"));
  2593. 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?
  2594. 3:
  2595. 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")));
  2596. 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")));
  2597. }
  2598. }
  2599. else
  2600. {
  2601. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2602. 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++)
  2603. {
  2604. 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"));
  2605. 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?
  2606. 3:
  2607. 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")));
  2608. 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));
  2609. }
  2610. }
  2611. // Optional item
  2612. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2613. {
  2614. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2615. }
  2616. else
  2617. {
  2618. sprintf((char*)maxProfile.ValidFrom, " ");
  2619. }
  2620. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2621. {
  2622. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2623. }
  2624. else
  2625. {
  2626. sprintf((char*)maxProfile.ValidTo, " ");
  2627. }
  2628. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2629. {
  2630. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2631. }
  2632. else
  2633. {
  2634. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2635. }
  2636. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2637. {
  2638. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2639. }
  2640. else
  2641. {
  2642. maxProfile.TransactionId = -1;
  2643. }
  2644. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2645. {
  2646. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2647. }
  2648. else
  2649. {
  2650. maxProfile.ChargingSchedule.Duration = 86400;
  2651. }
  2652. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2653. {
  2654. 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")));
  2655. }
  2656. else
  2657. {
  2658. 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));
  2659. }
  2660. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2661. {
  2662. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2663. }
  2664. else
  2665. {
  2666. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2667. }
  2668. }
  2669. }
  2670. }
  2671. else
  2672. {
  2673. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2674. {
  2675. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2676. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2677. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2678. }
  2679. maxProfile.ChargingProfileId = -1;
  2680. maxProfile.StackLevel = -1;
  2681. if(maxProfile.ChargingProfileId == -1)
  2682. DEBUG_INFO("MaxProfile found.\n");
  2683. else
  2684. DEBUG_INFO("MaxProfile updated.\n");
  2685. // Required item
  2686. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2687. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2688. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2689. if(isUnitA)
  2690. {
  2691. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2692. 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++)
  2693. {
  2694. 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"));
  2695. 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?
  2696. 3:
  2697. 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")));
  2698. 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")));
  2699. }
  2700. }
  2701. else
  2702. {
  2703. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2704. 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++)
  2705. {
  2706. 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"));
  2707. 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?
  2708. 3:
  2709. 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")));
  2710. 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));
  2711. }
  2712. }
  2713. // Optional item
  2714. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2715. {
  2716. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2717. }
  2718. else
  2719. {
  2720. sprintf((char*)maxProfile.ValidFrom, " ");
  2721. }
  2722. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2723. {
  2724. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2725. }
  2726. else
  2727. {
  2728. sprintf((char*)maxProfile.ValidTo, " ");
  2729. }
  2730. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2731. {
  2732. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2733. }
  2734. else
  2735. {
  2736. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2737. }
  2738. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2739. {
  2740. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2741. }
  2742. else
  2743. {
  2744. maxProfile.TransactionId = -1;
  2745. }
  2746. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2747. {
  2748. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2749. }
  2750. else
  2751. {
  2752. maxProfile.ChargingSchedule.Duration = 86400;
  2753. }
  2754. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2755. {
  2756. 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")));
  2757. }
  2758. else
  2759. {
  2760. 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));
  2761. }
  2762. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2763. {
  2764. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2765. }
  2766. else
  2767. {
  2768. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2769. }
  2770. }
  2771. }
  2772. }
  2773. json_object_put(obj);
  2774. }
  2775. fclose(fp);
  2776. /*
  2777. if(maxProfile.ChargingProfileId !=-1)
  2778. {
  2779. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2780. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2781. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2782. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2783. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2784. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2785. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2786. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2787. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2788. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2789. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2791. {
  2792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2793. {
  2794. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2795. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2796. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2797. }
  2798. }
  2799. }
  2800. else
  2801. DEBUG_INFO("MaxProfile not found.\n");
  2802. DEBUG_INFO("------------------------------------\n");*/
  2803. }
  2804. /*
  2805. * Align found profile start schedule & periods
  2806. */
  2807. //DEBUG_INFO("====================================\n");
  2808. /*
  2809. // For local test usage, force modify found profile start schedule info
  2810. 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);
  2811. 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);
  2812. 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);
  2813. */
  2814. if(txProfile.ChargingProfileId != -1)
  2815. {
  2816. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2817. {
  2818. if(txProfile.ChargingSchedule.Duration != -1)
  2819. {
  2820. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2821. 0:
  2822. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2823. }
  2824. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2825. {
  2826. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2827. {
  2828. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2829. 0:
  2830. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2831. if(idxPeriod > 0)
  2832. {
  2833. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2834. {
  2835. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2836. }
  2837. }
  2838. }
  2839. }
  2840. }
  2841. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2842. {
  2843. if(txProfile.ChargingSchedule.Duration != -1)
  2844. {
  2845. 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?
  2846. 0:
  2847. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2848. }
  2849. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2850. {
  2851. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2852. {
  2853. 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?
  2854. 0:
  2855. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2856. if(idxPeriod > 0)
  2857. {
  2858. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2859. {
  2860. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2861. }
  2862. }
  2863. }
  2864. }
  2865. }
  2866. else
  2867. {
  2868. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2869. {
  2870. if(txProfile.ChargingSchedule.Duration != -1)
  2871. {
  2872. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2873. 0:
  2874. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2875. }
  2876. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2877. {
  2878. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2879. {
  2880. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2881. 0:
  2882. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2883. if(idxPeriod > 0)
  2884. {
  2885. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2886. {
  2887. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2888. }
  2889. }
  2890. }
  2891. }
  2892. }
  2893. else
  2894. {
  2895. if(txProfile.ChargingSchedule.Duration != -1)
  2896. {
  2897. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2898. 0:
  2899. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2900. }
  2901. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2902. {
  2903. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2904. {
  2905. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2906. 0:
  2907. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2908. if(idxPeriod > 0)
  2909. {
  2910. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2911. {
  2912. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2913. }
  2914. }
  2915. }
  2916. }
  2917. }
  2918. }
  2919. /*
  2920. DEBUG_INFO("txProfile after align.\n");
  2921. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2922. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2923. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2924. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2925. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2926. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2927. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2928. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2929. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2930. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2931. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2932. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2933. {
  2934. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2935. {
  2936. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2937. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2938. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2939. }
  2940. }*/
  2941. }
  2942. if(defaultTxProfile.ChargingProfileId != -1)
  2943. {
  2944. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2945. {
  2946. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2947. {
  2948. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2949. 0:
  2950. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2951. }
  2952. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2953. {
  2954. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2955. {
  2956. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2957. 0:
  2958. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2959. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2960. {
  2961. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2962. }
  2963. if(idxPeriod > 0)
  2964. {
  2965. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2966. {
  2967. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2968. }
  2969. }
  2970. }
  2971. }
  2972. }
  2973. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2974. {
  2975. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2976. {
  2977. 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?
  2978. 0:
  2979. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2980. }
  2981. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2982. {
  2983. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2984. {
  2985. 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?
  2986. 0:
  2987. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2988. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2989. {
  2990. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2991. }
  2992. if(idxPeriod > 0)
  2993. {
  2994. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2995. {
  2996. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2997. }
  2998. }
  2999. }
  3000. }
  3001. }
  3002. else
  3003. {
  3004. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3005. {
  3006. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3007. {
  3008. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3009. 0:
  3010. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3011. }
  3012. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3013. {
  3014. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3015. {
  3016. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3017. 0:
  3018. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3019. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3020. {
  3021. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3022. }
  3023. if(idxPeriod > 0)
  3024. {
  3025. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3026. {
  3027. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3028. }
  3029. }
  3030. }
  3031. }
  3032. }
  3033. else
  3034. {
  3035. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3036. {
  3037. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3038. 0:
  3039. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3040. }
  3041. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3042. {
  3043. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3044. {
  3045. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3046. 0:
  3047. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3048. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3049. {
  3050. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3051. }
  3052. if(idxPeriod > 0)
  3053. {
  3054. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3055. {
  3056. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. }
  3063. /*
  3064. DEBUG_INFO("defaultTxProfile after align.\n");
  3065. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3066. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3067. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3068. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3069. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3070. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3071. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3072. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3073. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3074. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3075. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3076. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3077. {
  3078. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3079. {
  3080. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3081. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3082. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3083. }
  3084. }
  3085. DEBUG_INFO("------------------------------------\n");*/
  3086. }
  3087. if(maxProfile.ChargingProfileId != -1)
  3088. {
  3089. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3090. {
  3091. if(maxProfile.ChargingSchedule.Duration != -1)
  3092. {
  3093. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3094. 0:
  3095. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3096. }
  3097. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3098. {
  3099. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3100. {
  3101. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3102. 0:
  3103. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3104. if(idxPeriod > 0)
  3105. {
  3106. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3107. {
  3108. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3109. }
  3110. }
  3111. }
  3112. }
  3113. }
  3114. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3115. {
  3116. if(maxProfile.ChargingSchedule.Duration != -1)
  3117. {
  3118. 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?
  3119. 0:
  3120. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3121. }
  3122. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3123. {
  3124. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3125. {
  3126. 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?
  3127. 0:
  3128. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3129. if(idxPeriod > 0)
  3130. {
  3131. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3132. {
  3133. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3134. }
  3135. }
  3136. }
  3137. }
  3138. }
  3139. else
  3140. {
  3141. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3142. {
  3143. if(maxProfile.ChargingSchedule.Duration != -1)
  3144. {
  3145. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3146. 0:
  3147. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3148. }
  3149. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3150. {
  3151. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3152. {
  3153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3154. 0:
  3155. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3156. if(idxPeriod > 0)
  3157. {
  3158. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3159. {
  3160. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3161. }
  3162. }
  3163. }
  3164. }
  3165. }
  3166. else
  3167. {
  3168. if(maxProfile.ChargingSchedule.Duration != -1)
  3169. {
  3170. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3171. 0:
  3172. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3173. }
  3174. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3175. {
  3176. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3177. {
  3178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3179. 0:
  3180. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3181. if(idxPeriod > 0)
  3182. {
  3183. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3184. {
  3185. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3186. }
  3187. }
  3188. }
  3189. }
  3190. }
  3191. }
  3192. /*
  3193. DEBUG_INFO("MaxProfile after align.\n");
  3194. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3195. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3196. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3197. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3198. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3199. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3200. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3201. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3202. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3203. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3204. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3205. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3206. {
  3207. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3208. {
  3209. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3210. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3211. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3212. }
  3213. }
  3214. DEBUG_INFO("------------------------------------\n");*/
  3215. }
  3216. /*
  3217. * Merge to conposite schedule
  3218. */
  3219. //DEBUG_INFO("====================================\n");
  3220. // Find each profile period quantity
  3221. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3222. {
  3223. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3224. limitMax = idx+1;
  3225. }
  3226. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3227. {
  3228. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3229. limitDef = idx+1;
  3230. }
  3231. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3232. {
  3233. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3234. limitTx = idx+1;
  3235. }
  3236. // TxProfile found, composite schedule based on it
  3237. if(txProfile.ChargingProfileId != -1)
  3238. {
  3239. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3240. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3241. {
  3242. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3243. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3244. (txProfile.ChargingSchedule.Duration > 0))
  3245. {
  3246. if(maxProfile.ChargingProfileId != -1)
  3247. {
  3248. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3249. {
  3250. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3251. {
  3252. if((maxProfile.ChargingSchedule.Duration > 0))
  3253. {
  3254. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3255. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3256. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3257. }
  3258. else
  3259. {
  3260. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3261. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3262. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3263. }
  3264. }
  3265. if(idxMaxPeriod == (limitMax-1))
  3266. {
  3267. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3268. {
  3269. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3270. {
  3271. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3272. compositePeriodIdx++;
  3273. }
  3274. else
  3275. {
  3276. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3277. }
  3278. }
  3279. }
  3280. }
  3281. }
  3282. else
  3283. {
  3284. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3285. {
  3286. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3287. compositePeriodIdx++;
  3288. }
  3289. else
  3290. {
  3291. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3292. }
  3293. }
  3294. }
  3295. if(idxTxPeriod == (limitTx-1))
  3296. {
  3297. if(defaultTxProfile.ChargingProfileId != -1)
  3298. {
  3299. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3300. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3301. {
  3302. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3303. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3304. (defaultTxProfile.ChargingSchedule.Duration>0))
  3305. {
  3306. if(maxProfile.ChargingProfileId != -1)
  3307. {
  3308. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3309. {
  3310. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3311. {
  3312. if((maxProfile.ChargingSchedule.Duration > 0))
  3313. {
  3314. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3315. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3316. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3317. }
  3318. else
  3319. {
  3320. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3321. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3322. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3323. }
  3324. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3325. {
  3326. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3327. {
  3328. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3329. compositePeriodIdx++;
  3330. }
  3331. else
  3332. {
  3333. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3334. }
  3335. }
  3336. // Delete duplicate period
  3337. if(compositePeriodIdx > 1)
  3338. {
  3339. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3340. {
  3341. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3342. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3343. compositePeriodIdx -= 1;
  3344. }
  3345. }
  3346. }
  3347. else
  3348. {
  3349. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3350. {
  3351. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3352. compositePeriodIdx++;
  3353. }
  3354. else
  3355. {
  3356. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3357. }
  3358. break;
  3359. }
  3360. }
  3361. }
  3362. else
  3363. {
  3364. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3365. {
  3366. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3367. compositePeriodIdx++;
  3368. }
  3369. else
  3370. {
  3371. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3372. }
  3373. }
  3374. }
  3375. }
  3376. }
  3377. }
  3378. }
  3379. }
  3380. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3381. else if(defaultTxProfile.ChargingProfileId != -1)
  3382. {
  3383. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3384. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3385. {
  3386. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3387. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3388. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3389. {
  3390. if(maxProfile.ChargingProfileId != -1)
  3391. {
  3392. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3393. {
  3394. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3395. {
  3396. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3397. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3398. if((maxProfile.ChargingSchedule.Duration > 0))
  3399. {
  3400. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3401. }
  3402. else
  3403. {
  3404. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3405. }
  3406. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3407. {
  3408. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3409. {
  3410. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3411. compositePeriodIdx++;
  3412. }
  3413. else
  3414. {
  3415. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3416. }
  3417. }
  3418. // Delete duplicate period
  3419. if(compositePeriodIdx > 1)
  3420. {
  3421. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3422. {
  3423. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3424. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3425. compositePeriodIdx -= 1;
  3426. }
  3427. }
  3428. }
  3429. else
  3430. {
  3431. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3432. {
  3433. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3434. compositePeriodIdx++;
  3435. }
  3436. else
  3437. {
  3438. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3439. }
  3440. break;
  3441. }
  3442. }
  3443. }
  3444. else
  3445. {
  3446. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3447. {
  3448. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3449. compositePeriodIdx++;
  3450. }
  3451. else
  3452. {
  3453. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3454. }
  3455. }
  3456. }
  3457. }
  3458. }
  3459. // Fill other period by MaxProfile
  3460. if(maxProfile.ChargingProfileId != -1)
  3461. {
  3462. if(compositePeriodIdx==0)
  3463. {
  3464. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3465. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3466. {
  3467. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3468. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3469. (maxProfile.ChargingSchedule.Duration > 0))
  3470. {
  3471. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3472. {
  3473. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3474. compositePeriodIdx++;
  3475. }
  3476. else
  3477. {
  3478. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3479. }
  3480. }
  3481. }
  3482. }
  3483. else
  3484. {
  3485. int lastCompositePeriodIdx = compositePeriodIdx;
  3486. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3487. {
  3488. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3489. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3490. (maxProfile.ChargingSchedule.Duration > 0))
  3491. {
  3492. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3493. {
  3494. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3495. {
  3496. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3497. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3498. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3499. }
  3500. else
  3501. {
  3502. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3503. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3504. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3505. }
  3506. }
  3507. if(tmpPeriod.Limit != -1)
  3508. {
  3509. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3510. {
  3511. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3512. {
  3513. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3514. compositePeriodIdx++;
  3515. }
  3516. else
  3517. {
  3518. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3519. }
  3520. }
  3521. // Delete duplicate period
  3522. if(compositePeriodIdx > 1)
  3523. {
  3524. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3525. {
  3526. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3527. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3528. compositePeriodIdx -= 1;
  3529. }
  3530. }
  3531. }
  3532. }
  3533. }
  3534. }
  3535. }
  3536. compositeProfile.ChargingSchedule.Duration = durationReq;
  3537. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3538. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3539. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3540. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3541. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3542. {
  3543. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3544. {
  3545. compositeProfile.ChargingProfileId = 1;
  3546. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3547. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3548. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3549. }
  3550. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3551. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3552. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3553. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3554. }
  3555. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3556. if(line)
  3557. free(line);
  3558. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3559. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3560. }
  3561. //==========================================
  3562. // Init all share memory
  3563. //==========================================
  3564. int InitShareMemory()
  3565. {
  3566. int result = PASS;
  3567. int MeterSMId;
  3568. //creat ShmSysConfigAndInfo
  3569. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3570. {
  3571. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3572. result = FAIL;
  3573. }
  3574. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3575. {
  3576. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3577. result = FAIL;
  3578. }
  3579. else
  3580. {}
  3581. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3582. {
  3583. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3584. result = FAIL;
  3585. }
  3586. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3587. {
  3588. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3589. result = FAIL;
  3590. }
  3591. else
  3592. {}
  3593. //creat ShmPsuData
  3594. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3595. {
  3596. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3597. result = FAIL;
  3598. }
  3599. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3600. {
  3601. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3602. result = FAIL;
  3603. }
  3604. else
  3605. {}
  3606. //creat ShmOCPP16Data
  3607. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3608. {
  3609. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3610. result = FAIL;
  3611. }
  3612. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3613. {
  3614. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3615. result = FAIL;
  3616. }
  3617. else
  3618. {}
  3619. /****************************** For Initial Settings************************************************/
  3620. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3621. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3622. // allocate Configuration memory address
  3623. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3624. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3625. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3626. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3627. //offline MeterValue Interval
  3628. TempMeterValueInterval = 0;
  3629. return result;
  3630. }
  3631. int ProcessShareMemory()
  3632. {
  3633. int result = PASS;
  3634. if(InitShareMemory() == FAIL)
  3635. {
  3636. DEBUG_ERROR("InitShareMemory NG\n");
  3637. if(ShmStatusCodeData!=NULL)
  3638. {
  3639. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3640. }
  3641. result = FAIL;
  3642. }
  3643. // Model name parsing
  3644. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3645. {
  3646. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3647. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3648. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3649. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3650. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3651. ) // 'D' means DC
  3652. {
  3653. // DO series
  3654. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3655. {
  3656. SystemInitial += 1;
  3657. gunTotalNumber += 1;
  3658. gunType[gun_index] = GUN_TYPE_DO;
  3659. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3660. {
  3661. case Gun_Type_Chademo:
  3662. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3663. break;
  3664. case Gun_Type_CCS_2:
  3665. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3666. break;
  3667. case Gun_Type_GB:
  3668. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3669. break;
  3670. case Gun_Type_AC:
  3671. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3672. break;
  3673. default:
  3674. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3675. break;
  3676. }
  3677. }
  3678. }
  3679. else
  3680. {
  3681. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3682. {
  3683. SystemInitial += 1;
  3684. gunTotalNumber += 1;
  3685. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3686. {
  3687. case Gun_Type_Chademo:
  3688. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3689. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3690. break;
  3691. case Gun_Type_CCS_2:
  3692. gunType[gun_index] = GUN_TYPE_CCS;
  3693. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3694. break;
  3695. case Gun_Type_GB:
  3696. gunType[gun_index] = GUN_TYPE_GBT;
  3697. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3698. break;
  3699. case Gun_Type_AC:
  3700. gunType[gun_index] = GUN_TYPE_AC;
  3701. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3702. break;
  3703. default:
  3704. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3705. break;
  3706. }
  3707. }
  3708. }
  3709. }
  3710. else
  3711. {
  3712. DEBUG_ERROR("Model name parsing fail.\n");
  3713. result = FAIL;
  3714. }
  3715. if(result != PASS)sleep(5);
  3716. return result;
  3717. }
  3718. void checkRemoteStart(uint8_t connectorIdInt)
  3719. {
  3720. uint8_t tempIndex;
  3721. int result = PASS;
  3722. char cmdBuf[512];
  3723. //check Transaction active
  3724. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3725. {
  3726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3727. {
  3728. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3729. }
  3730. else
  3731. {
  3732. tempIndex = connectorIdInt -1;
  3733. }
  3734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3735. {
  3736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3737. {
  3738. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3739. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3740. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3741. {
  3742. //Reserved
  3743. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3744. }
  3745. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3746. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3747. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3748. {
  3749. //Reserved
  3750. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3751. result = FAIL;
  3752. goto end;
  3753. }
  3754. else
  3755. {
  3756. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3757. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3758. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3759. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3760. {
  3761. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3762. result = FAIL;
  3763. goto end;
  3764. }
  3765. }//END FOR ELSE
  3766. }
  3767. }// END FOR CHAdeMO_QUANTITY
  3768. }
  3769. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3770. {
  3771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3772. {
  3773. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3774. }
  3775. else
  3776. {
  3777. tempIndex = connectorIdInt -1;
  3778. }
  3779. for (int index = 0; index < CCS_QUANTITY; index++)
  3780. {
  3781. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3782. {
  3783. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3784. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3785. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3786. {
  3787. //Reserved
  3788. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3789. }
  3790. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3791. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3792. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3793. {
  3794. //Reserved
  3795. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3796. result = FAIL;
  3797. goto end;
  3798. }
  3799. else
  3800. {
  3801. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3802. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3803. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3804. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3805. {
  3806. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3807. result = FAIL;
  3808. goto end;
  3809. }
  3810. }// END FOR ELSE
  3811. }
  3812. }// END FOR CCS_QUANTITY
  3813. }
  3814. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3815. {
  3816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3817. {
  3818. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3819. }
  3820. else
  3821. {
  3822. tempIndex = connectorIdInt -1;
  3823. }
  3824. for (int index = 0; index < GB_QUANTITY; index++)
  3825. {
  3826. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3827. {
  3828. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3829. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3830. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3831. {
  3832. //Reserved
  3833. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3834. }
  3835. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3836. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3837. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3838. {
  3839. //Reserved
  3840. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3841. result = FAIL;
  3842. goto end;
  3843. }
  3844. else
  3845. {
  3846. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3847. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3848. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3849. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3850. {
  3851. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3852. result = FAIL;
  3853. goto end;
  3854. }
  3855. }// END FOR ELSE
  3856. }
  3857. } // END FOR GB_QUANTITY
  3858. }
  3859. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3860. {
  3861. tempIndex = connectorIdInt -1;
  3862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3863. {
  3864. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3865. {
  3866. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3867. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3868. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3869. {
  3870. //Reserved
  3871. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3872. }
  3873. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3874. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3875. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3876. {
  3877. //Reserved
  3878. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3879. result = FAIL;
  3880. goto end;
  3881. }
  3882. else
  3883. {
  3884. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3885. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3886. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3887. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3888. {
  3889. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3890. result = FAIL;
  3891. goto end;
  3892. }
  3893. }// END FOR ELSE
  3894. }
  3895. } // END FOR GB_QUANTITY
  3896. }
  3897. else
  3898. {
  3899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3900. {
  3901. tempIndex = 2;
  3902. }
  3903. else
  3904. {
  3905. tempIndex = connectorIdInt -1;
  3906. }
  3907. for (int index = 0; index < AC_QUANTITY; index++)
  3908. {
  3909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3910. {
  3911. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3912. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3913. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3914. {
  3915. //Reserved
  3916. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3917. }
  3918. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3919. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3920. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3921. {
  3922. //Reserved
  3923. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3924. result = FAIL;
  3925. goto end;
  3926. }
  3927. else
  3928. {
  3929. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3930. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3931. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3932. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3933. {
  3934. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3935. result = FAIL;
  3936. goto end;
  3937. }
  3938. }//END FOR ELSE
  3939. }
  3940. }// END FOR AC_QUANTITY
  3941. }
  3942. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3943. {
  3944. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3945. {
  3946. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3947. {
  3948. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3949. system(cmdBuf);
  3950. }
  3951. }
  3952. else
  3953. {
  3954. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3955. result = FAIL;
  3956. }
  3957. }
  3958. end:
  3959. if(result == PASS)
  3960. {
  3961. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3962. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3963. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3964. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3965. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3966. }
  3967. }
  3968. void CheckSystemValue(void)
  3969. {
  3970. char filenmae[100]={0};
  3971. char str[100]={0};
  3972. int tempIndex = 0;
  3973. //===============================
  3974. // send Heartbeat
  3975. //===============================
  3976. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3977. {
  3978. //parameter for test
  3979. sendHeartbeatRequest(0);
  3980. //===========================
  3981. // Reset Waiting Time
  3982. //===========================
  3983. HeartBeatWithNOResponse += 1;
  3984. }
  3985. //===============================
  3986. // Credit deduct report
  3987. //===============================
  3988. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  3989. {
  3990. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  3991. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  3992. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  3993. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  3994. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  3995. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  3996. }
  3997. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3998. {
  3999. OCPP_query_deduct_info();
  4000. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4001. }
  4002. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4003. {
  4004. // ClockAlign MeterValue
  4005. 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))
  4006. {
  4007. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4008. {
  4009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4010. {
  4011. tempIndex = ((gun_index==2) ? 1: 0);
  4012. }
  4013. else
  4014. {
  4015. tempIndex = gun_index;
  4016. }
  4017. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4018. {
  4019. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4020. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4021. {
  4022. reqClockAlignMeter[gun_index] = 1;
  4023. }
  4024. }// End for CHAdeMO
  4025. }
  4026. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4027. {
  4028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4029. {
  4030. tempIndex = ((gun_index==2) ? 1: 0);
  4031. }
  4032. else
  4033. {
  4034. tempIndex = gun_index;
  4035. }
  4036. for (int index = 0; index < CCS_QUANTITY; index++)
  4037. {
  4038. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4039. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4040. {
  4041. reqClockAlignMeter[gun_index] = 1;
  4042. }
  4043. } // End for CCS
  4044. }
  4045. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4046. {
  4047. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4048. {
  4049. tempIndex = ((gun_index==2) ? 1: 0);
  4050. }
  4051. else
  4052. {
  4053. tempIndex = gun_index;
  4054. }
  4055. for (int index = 0; index < GB_QUANTITY; index++)
  4056. {
  4057. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4058. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4059. {
  4060. reqClockAlignMeter[gun_index] = 1;
  4061. }
  4062. }// End for GB
  4063. }
  4064. else if(gunType[gun_index] == GUN_TYPE_DO)
  4065. {
  4066. tempIndex = gun_index;
  4067. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4068. {
  4069. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4070. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4071. {
  4072. reqClockAlignMeter[gun_index] = 1;
  4073. }
  4074. }
  4075. }
  4076. else
  4077. {
  4078. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4079. {
  4080. tempIndex = 2;
  4081. }
  4082. else
  4083. {
  4084. tempIndex = gun_index;
  4085. }
  4086. for (int index = 0; index < AC_QUANTITY; index++)
  4087. {
  4088. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4089. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4090. {
  4091. reqClockAlignMeter[gun_index] = 1;
  4092. }
  4093. }//End for AC
  4094. }
  4095. }
  4096. }
  4097. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4098. {
  4099. //==========================================
  4100. // Check remote start without connector id
  4101. //==========================================
  4102. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4103. {
  4104. int connectorIdInt = -1;
  4105. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4106. {
  4107. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4108. {
  4109. connectorIdInt = (gun_index+1);
  4110. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4111. checkRemoteStart(connectorIdInt);
  4112. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4113. break;
  4114. }
  4115. }
  4116. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4117. {
  4118. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4119. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4120. }
  4121. }
  4122. //==========================================
  4123. // csu trigger DataTransferReq
  4124. //==========================================
  4125. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4126. {
  4127. sendDataTransferRequest(gun_index);
  4128. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4129. }
  4130. //==========================================
  4131. // CSU Trigger Authorize Request
  4132. //==========================================
  4133. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4134. {
  4135. sendAuthorizeRequest(0);
  4136. authorizeRetryTimes = authorizeRetryTimes + 1;
  4137. if(authorizeRetryTimes < 3)
  4138. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4139. }
  4140. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4141. {
  4142. authorizeRetryTimes = 0;
  4143. SetOcppConnStatus(FALSE);
  4144. server_sign = FALSE;
  4145. }
  4146. 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))
  4147. {
  4148. sendAuthorizeRequest(0);
  4149. }
  4150. //==========================================
  4151. // Charger start transaction
  4152. //==========================================
  4153. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4154. {
  4155. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4156. sendStartTransactionRequest(gun_index);
  4157. refreshStartTimer(&clientTime.StartTransaction);
  4158. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4159. storeTempStopTransaction(gun_index);
  4160. }
  4161. //==========================================
  4162. // Charger stop transaction
  4163. //==========================================
  4164. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4165. {
  4166. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4167. sendStopTransactionRequest(gun_index);
  4168. OCPP_updatePeriodEnergy(gun_index);
  4169. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4170. refreshStartTimer(&clientTime.StopTransaction);
  4171. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4172. }
  4173. //==========================================
  4174. // Charger status report
  4175. //==========================================
  4176. //--- Check Mode Change ---//
  4177. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4178. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4179. {
  4180. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4181. {
  4182. tempIndex = ((gun_index==2) ? 1: 0);
  4183. }
  4184. else
  4185. {
  4186. tempIndex = gun_index;
  4187. }
  4188. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4189. {
  4190. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4191. {
  4192. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4193. {
  4194. // Sent unplug message for California pricing logic
  4195. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4196. {
  4197. uint8_t ts[20];
  4198. getNowDatetime(ts);
  4199. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4200. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4201. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4202. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4203. }
  4204. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4205. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4206. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4207. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4208. {
  4209. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4210. if((access(filenmae,F_OK))!=-1)
  4211. {
  4212. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4213. sprintf(str,"rm -f %s",filenmae);
  4214. system(str);
  4215. }
  4216. }
  4217. }
  4218. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4219. #if 1 // for TempStopTransaction
  4220. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4221. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4222. {
  4223. checkTempStopTransaction(gun_index);
  4224. }
  4225. #endif
  4226. }
  4227. }
  4228. }
  4229. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4230. {
  4231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4232. {
  4233. tempIndex = ((gun_index==2) ? 1: 0);
  4234. }
  4235. else
  4236. {
  4237. tempIndex = gun_index;
  4238. }
  4239. for (int index = 0; index < CCS_QUANTITY; index++)
  4240. {
  4241. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4242. {
  4243. 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]*/ )
  4244. {
  4245. // Sent unplug message for California pricing logic
  4246. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4247. {
  4248. uint8_t ts[20];
  4249. getNowDatetime(ts);
  4250. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4251. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4252. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4253. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4254. }
  4255. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4256. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4257. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4258. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4259. {
  4260. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4261. if((access(filenmae,F_OK))!=-1)
  4262. {
  4263. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4264. sprintf(str,"rm -f %s",filenmae);
  4265. system(str);
  4266. }
  4267. }
  4268. }
  4269. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4270. #if 1 // for TempStopTransaction
  4271. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4272. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4273. {
  4274. checkTempStopTransaction(gun_index);
  4275. }
  4276. #endif
  4277. }
  4278. }
  4279. }
  4280. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4281. {
  4282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4283. {
  4284. tempIndex = ((gun_index==2) ? 1: 0);
  4285. }
  4286. else
  4287. {
  4288. tempIndex = gun_index;
  4289. }
  4290. for (int index = 0; index < GB_QUANTITY; index++)
  4291. {
  4292. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4293. {
  4294. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4295. {
  4296. // Sent unplug message for California pricing logic
  4297. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4298. {
  4299. uint8_t ts[20];
  4300. getNowDatetime(ts);
  4301. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4302. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4303. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4304. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4305. }
  4306. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4307. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4308. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4309. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4310. {
  4311. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4312. if((access(filenmae,F_OK))!=-1)
  4313. {
  4314. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4315. sprintf(str,"rm -f %s",filenmae);
  4316. system(str);
  4317. }
  4318. }
  4319. }
  4320. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4321. #if 1 // for TempStopTransaction
  4322. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4323. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4324. {
  4325. checkTempStopTransaction(gun_index);
  4326. }
  4327. #endif
  4328. }
  4329. }
  4330. }
  4331. else if(gunType[gun_index] == GUN_TYPE_DO)
  4332. {
  4333. tempIndex = gun_index;
  4334. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4335. {
  4336. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4337. {
  4338. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4339. {
  4340. // Sent unplug message for California pricing logic
  4341. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4342. {
  4343. uint8_t ts[20];
  4344. getNowDatetime(ts);
  4345. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4346. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4347. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4348. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4349. }
  4350. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4351. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4352. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4353. 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
  4354. {
  4355. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4356. if((access(filenmae,F_OK))!=-1)
  4357. {
  4358. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4359. sprintf(str,"rm -f %s",filenmae);
  4360. system(str);
  4361. }
  4362. }
  4363. }
  4364. 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);
  4365. #if 1 // for TempStopTransaction
  4366. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4367. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4368. {
  4369. checkTempStopTransaction(gun_index);
  4370. }
  4371. #endif
  4372. }
  4373. }
  4374. }
  4375. else
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4378. {
  4379. tempIndex = 2;
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < AC_QUANTITY; index++)
  4386. {
  4387. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4388. {
  4389. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4390. {
  4391. // Sent unplug message for California pricing logic
  4392. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4393. {
  4394. uint8_t ts[20];
  4395. getNowDatetime(ts);
  4396. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4397. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4398. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4399. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4400. }
  4401. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4402. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4403. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4404. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4405. {
  4406. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4407. if((access(filenmae,F_OK))!=-1)
  4408. {
  4409. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4410. sprintf(str,"rm -f %s",filenmae);
  4411. system(str);
  4412. }
  4413. }
  4414. }
  4415. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4416. #if 1 // for TempStopTransaction
  4417. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4418. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4419. {
  4420. checkTempStopTransaction(gun_index);
  4421. }
  4422. #endif
  4423. }
  4424. }// END
  4425. }
  4426. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4427. (
  4428. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4429. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4430. )
  4431. )
  4432. {
  4433. if(SystemInitial > 0)
  4434. SystemInitial -= 1;
  4435. sendStatusNotificationRequest(gun_index);
  4436. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4437. }
  4438. //==============================================
  4439. // CSU Trigger Smart Charging Profile
  4440. //==============================================
  4441. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4442. {
  4443. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4444. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4445. }
  4446. //==============================================
  4447. // Meter report
  4448. //==============================================
  4449. // Trigger MeterValue
  4450. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4451. {
  4452. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4453. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4454. }
  4455. // Clock-aligned Meter value
  4456. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4457. {
  4458. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4459. reqClockAlignMeter[gun_index] = 0;
  4460. }
  4461. // Sample period MeterValue
  4462. 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))))
  4463. {
  4464. //check Transaction active
  4465. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4466. {
  4467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4468. {
  4469. tempIndex = ((gun_index==2) ? 1: 0);
  4470. }
  4471. else
  4472. {
  4473. tempIndex = gun_index;
  4474. }
  4475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4476. {
  4477. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4478. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4479. {
  4480. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4481. {
  4482. reqSampleMeter[gun_index] = 1;
  4483. }
  4484. }
  4485. }// End for CHAdeMO
  4486. }
  4487. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4488. {
  4489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4490. {
  4491. tempIndex = ((gun_index==2) ? 1: 0);
  4492. }
  4493. else
  4494. {
  4495. tempIndex = gun_index;
  4496. }
  4497. for (int index = 0; index < CCS_QUANTITY; index++)
  4498. {
  4499. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4500. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4501. {
  4502. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4503. {
  4504. reqSampleMeter[gun_index] = 1;
  4505. }
  4506. }
  4507. } // End for CCS
  4508. }
  4509. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4510. {
  4511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4512. {
  4513. tempIndex = ((gun_index==2) ? 1: 0);
  4514. }
  4515. else
  4516. {
  4517. tempIndex = gun_index;
  4518. }
  4519. for (int index = 0; index < GB_QUANTITY; index++)
  4520. {
  4521. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4522. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4523. {
  4524. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4525. {
  4526. reqSampleMeter[gun_index] = 1;
  4527. }
  4528. }
  4529. }// End for GB
  4530. }
  4531. else if(gunType[gun_index] == GUN_TYPE_DO)
  4532. {
  4533. tempIndex = gun_index;
  4534. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4535. {
  4536. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4537. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4538. {
  4539. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4540. {
  4541. reqSampleMeter[gun_index] = 1;
  4542. }
  4543. }
  4544. }
  4545. }
  4546. else
  4547. {
  4548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4549. {
  4550. tempIndex = 2;
  4551. }
  4552. else
  4553. {
  4554. tempIndex = gun_index;
  4555. }
  4556. for (int index = 0; index < AC_QUANTITY; index++)
  4557. {
  4558. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4559. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4560. {
  4561. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4562. {
  4563. reqSampleMeter[gun_index] = 1;
  4564. }
  4565. }
  4566. }//End for AC
  4567. }
  4568. if(reqSampleMeter[gun_index] == 1)
  4569. {
  4570. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4571. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4572. storeTempStopTransaction(gun_index);
  4573. reqSampleMeter[gun_index] = 0;
  4574. }
  4575. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4576. }
  4577. //==============================================
  4578. // Check Connector reserved
  4579. //==============================================
  4580. //===============================
  4581. // Check if Reserve is expired
  4582. //===============================
  4583. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4584. {
  4585. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4586. {
  4587. DEBUG_INFO("reserve expired.\n");
  4588. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4589. }
  4590. }//END OF Check if Reserve is expired
  4591. //==========================================
  4592. // csu trigger FirmwareStatusNotificationReq
  4593. //==========================================
  4594. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4595. {
  4596. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4597. }
  4598. //==========================================
  4599. // csu trigger DiagnosticsStatusNotificationReq
  4600. //==========================================
  4601. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4602. {
  4603. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4604. }
  4605. //==========================================
  4606. // csu trigger CancelReservationConf
  4607. //==========================================
  4608. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4609. {
  4610. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4611. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4612. }
  4613. //==========================================
  4614. // csu trigger ChangeAvailabilityConf
  4615. //==========================================
  4616. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4617. {
  4618. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4619. }
  4620. //==========================================
  4621. // csu trigger UnlockConnectorConf
  4622. //==========================================
  4623. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4624. {
  4625. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4626. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4627. }
  4628. //==========================================
  4629. // csu trigger ReserveNowConf
  4630. //==========================================
  4631. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4632. {
  4633. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4634. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4635. }
  4636. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4637. {
  4638. sendSignCertificateRequest();
  4639. }
  4640. }
  4641. }
  4642. //==========================================
  4643. // send request routine
  4644. //==========================================
  4645. int sendAuthorizeRequest(int gun_index)
  4646. {
  4647. mtrace();
  4648. int result = FAIL;
  4649. char message[100]={0};
  4650. char guid[37];
  4651. char tempdata[65]={0};
  4652. DEBUG_INFO("sendAuthorizeRequest...\n");
  4653. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4654. //Local Authorize
  4655. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4656. {
  4657. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4658. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4659. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4660. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4661. result = PASS;
  4662. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4663. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4664. authorizeRetryTimes = 0;
  4665. return result;
  4666. }
  4667. 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))||
  4668. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4669. {
  4670. // Query from cache
  4671. DEBUG_INFO("Authorize from cache.\n");
  4672. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4673. // Query from list
  4674. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4675. {
  4676. DEBUG_INFO("Authorize from list.\n");
  4677. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4678. }
  4679. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4680. {
  4681. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4682. {
  4683. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4684. }
  4685. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4686. {
  4687. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4688. }
  4689. if(!GetOcppConnStatus())
  4690. {
  4691. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4692. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4693. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4694. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4695. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4696. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4697. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4698. authorizeRetryTimes = 0;
  4699. return result;
  4700. }
  4701. }
  4702. else
  4703. {
  4704. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4705. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4706. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4707. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4708. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4709. else
  4710. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4711. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4712. result = PASS;
  4713. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4714. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4715. authorizeRetryTimes = 0;
  4716. return result;
  4717. }
  4718. }
  4719. //initialize struct Authorize
  4720. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4721. //get data from shared memory
  4722. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4723. random_uuid(guid);
  4724. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4725. LWS_Send(message);
  4726. sprintf(tempdata, "Authorize,%d", gun_index);
  4727. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4728. {
  4729. result = PASS;
  4730. DEBUG_INFO("Authorize mapItem pass\n");
  4731. }
  4732. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4733. return result;
  4734. }
  4735. int sendBootNotificationRequest(void)
  4736. {
  4737. mtrace();
  4738. int result = FAIL;
  4739. char message[500]={0}, payload[700]={0};
  4740. char guid[37]={0};
  4741. char tempdata[65]={0};
  4742. // Fill BootNotification fields
  4743. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4744. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4745. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4746. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4747. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4748. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4749. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4750. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4751. ShmOCPP16Data->ChargeBoxId
  4752. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4753. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4754. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4755. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4756. ,ShmOCPP16Data->BootNotification.CpIccid
  4757. ,ShmOCPP16Data->BootNotification.CpImsi);
  4758. random_uuid(guid);
  4759. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4760. LWS_Send(message);
  4761. sprintf(tempdata, "BootNotification,0");
  4762. 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*/)
  4763. {
  4764. result = PASS;
  4765. }
  4766. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4767. strcpy(queuedata,message);
  4768. return result;
  4769. }
  4770. int sendDataTransferRequest(int gun_index)
  4771. {
  4772. mtrace();
  4773. char message[1000]={0};
  4774. char guid[37]={0};
  4775. char tempdata[65]={0};
  4776. int result = FAIL;
  4777. random_uuid(guid);
  4778. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4779. MESSAGE_TYPE_CALL,
  4780. guid,
  4781. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4782. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4783. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4784. LWS_Send(message);
  4785. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4786. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4787. {
  4788. result = PASS;
  4789. DEBUG_INFO("DataTransfer mapItem pass\n");
  4790. }
  4791. return result;
  4792. }
  4793. int sendDiagnosticsStatusNotificationRequest(char *status)
  4794. {
  4795. mtrace();
  4796. int result = FAIL;
  4797. char message[110]={0};
  4798. char guid[37]={0};
  4799. char tempdata[65]={0};
  4800. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4801. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4802. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4803. random_uuid(guid);
  4804. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4805. LWS_SendNow(message);
  4806. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4807. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4808. {
  4809. result = PASS;
  4810. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4811. }
  4812. //#ifdef SystemLogMessage
  4813. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4814. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4815. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4816. //#endif
  4817. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4818. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4819. //record status
  4820. if(strcmp(status,"Idle")==0)
  4821. {
  4822. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4823. }
  4824. else if(strcmp(status,"Uploaded")==0)
  4825. {
  4826. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4827. }
  4828. else if(strcmp(status,"UploadFailed")==0)
  4829. {
  4830. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4831. }
  4832. else if(strcmp(status,"Uploading")==0)
  4833. {
  4834. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4835. }
  4836. return result;
  4837. }
  4838. int sendFirmwareStatusNotificationRequest(char *status)
  4839. {
  4840. mtrace();
  4841. int result = FAIL;
  4842. char message[110]={0};
  4843. char guid[37]={0};
  4844. char tempdata[65]={0};
  4845. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4846. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4847. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4848. random_uuid(guid);
  4849. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4850. LWS_SendNow(message);
  4851. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4852. 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*/)
  4853. {
  4854. result = PASS;
  4855. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4856. }
  4857. //#ifdef SystemLogMessage
  4858. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4859. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4860. //#endif
  4861. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4862. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4863. //record status
  4864. if(strcmp(status,"Downloaded")==0)
  4865. {
  4866. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4867. }
  4868. else if(strcmp(status,"DownloadFailed")==0)
  4869. {
  4870. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4871. }
  4872. else if(strcmp(status,"Downloading")==0)
  4873. {
  4874. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4875. }
  4876. else if(strcmp(status,"Idle")==0)
  4877. {
  4878. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4879. }
  4880. else if(strcmp(status,"InstallationFailed")==0)
  4881. {
  4882. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4883. }
  4884. else if(strcmp(status,"Installing")==0)
  4885. {
  4886. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4887. }
  4888. else if(strcmp(status,"Installed")==0)
  4889. {
  4890. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4891. }
  4892. return result;
  4893. }
  4894. int sendHeartbeatRequest(int gun_index)
  4895. {
  4896. mtrace();
  4897. int result = FAIL;
  4898. char message[80]={0};
  4899. char guid[37]={0};
  4900. char tempdata[65]={0};
  4901. random_uuid(guid);
  4902. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4903. , MESSAGE_TYPE_CALL
  4904. , guid );
  4905. LWS_Send(message);
  4906. sprintf(tempdata, "Heartbeat,%d", 0);
  4907. 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*/)
  4908. {
  4909. result = PASS;
  4910. }
  4911. return result;
  4912. }
  4913. int sendStartTransactionRequest(int gun_index)
  4914. {
  4915. mtrace();
  4916. int result = FAIL;
  4917. char message[250]={0};
  4918. char guid[37]={0};
  4919. struct timeval tmnow;
  4920. struct tm *tm;
  4921. char buf[28];//, usec_buf[6];
  4922. char tempdata[65]={0};
  4923. int tempIndex = 0;
  4924. DEBUG_INFO("sendStartTransactionRequest...\n");
  4925. gettimeofday(&tmnow, NULL);
  4926. time_t t;
  4927. t = time(NULL);
  4928. /*UTC time and date*/
  4929. tm = gmtime(&t);
  4930. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4931. #if 0 // remove temporally
  4932. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4933. strcat(buf,".");
  4934. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4935. strcat(buf,usec_buf);
  4936. #endif
  4937. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4938. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4939. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4940. // clear StartTransaction Response
  4941. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4942. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4943. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4944. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4945. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4946. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4947. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4948. {
  4949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4950. {
  4951. tempIndex = ((gun_index==2) ? 1: 0);
  4952. }
  4953. else
  4954. {
  4955. tempIndex = gun_index;
  4956. }
  4957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4958. {
  4959. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4960. {
  4961. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4962. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4963. }
  4964. }
  4965. }
  4966. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4967. {
  4968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4969. {
  4970. tempIndex = ((gun_index==2) ? 1: 0);
  4971. }
  4972. else
  4973. {
  4974. tempIndex = gun_index;
  4975. }
  4976. for (int index = 0; index < CCS_QUANTITY; index++)
  4977. {
  4978. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4979. {
  4980. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4981. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4982. }
  4983. }
  4984. }
  4985. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4986. {
  4987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4988. {
  4989. tempIndex = ((gun_index==2) ? 1: 0);
  4990. }
  4991. else
  4992. {
  4993. tempIndex = gun_index;
  4994. }
  4995. for (int index = 0; index < GB_QUANTITY; index++)
  4996. {
  4997. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4998. {
  4999. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5000. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5001. }
  5002. }
  5003. }
  5004. else if(gunType[gun_index] == GUN_TYPE_DO)
  5005. {
  5006. tempIndex = gun_index;
  5007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5008. {
  5009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5010. {
  5011. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5012. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5013. }
  5014. }
  5015. }
  5016. else
  5017. {
  5018. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5019. {
  5020. tempIndex = 2;
  5021. }
  5022. else
  5023. {
  5024. tempIndex = gun_index;
  5025. }
  5026. for (int index = 0; index < AC_QUANTITY; index++)
  5027. {
  5028. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5029. {
  5030. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5031. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5032. }
  5033. }
  5034. }
  5035. random_uuid(guid);
  5036. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5037. {
  5038. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5039. , gun_index +1
  5040. , MESSAGE_TYPE_CALL
  5041. , guid
  5042. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5043. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5044. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5045. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5046. }
  5047. else
  5048. {
  5049. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5050. , gun_index +1
  5051. , MESSAGE_TYPE_CALL
  5052. , guid
  5053. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5054. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5055. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5056. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5057. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5058. }
  5059. #if 1
  5060. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5061. 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*/)
  5062. {
  5063. result = PASS;
  5064. }
  5065. #endif
  5066. strcpy(queuedata, message);
  5067. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5068. OCPP_insert_transaction_msg(YES, queuedata);
  5069. return result;
  5070. }
  5071. int sendStatusNotificationRequest(int gun_index)
  5072. {
  5073. mtrace();
  5074. int result = FAIL;
  5075. char message[600]={0};
  5076. char guid[37];
  5077. int currentStatus = 0;
  5078. struct timeval tmnow;
  5079. struct tm *tm;
  5080. char buf[28];//, usec_buf[6];
  5081. char tempdata[65]={0};
  5082. int tempIndex = 0;
  5083. uint8_t isStateChanged = TRUE;
  5084. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5085. gettimeofday(&tmnow, NULL);
  5086. time_t t;
  5087. t = time(NULL);
  5088. /*UTC time and date*/
  5089. tm = gmtime(&t);
  5090. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5091. #if 0 // remove temporally
  5092. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5093. strcat(buf,".");
  5094. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5095. strcat(buf,usec_buf);
  5096. #endif
  5097. //printf("%s",buf);
  5098. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5099. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5100. // it's option
  5101. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5102. /*
  5103. enum _SYSTEM_STATUS
  5104. {
  5105. S_BOOTING = 0,
  5106. S_IDLE, = 1
  5107. S_AUTHORIZING, =2
  5108. S_REASSIGN_CHECK, =3
  5109. S_REASSIGN, =4
  5110. S_PRECHARGE, =5
  5111. S_PREPARING_FOR_EV, =6
  5112. S_PREPARING_FOR_EVSE, =7
  5113. S_CHARGING, =8
  5114. S_TERMINATING, =9
  5115. S_COMPLETE, =10
  5116. S_ALARM, =11
  5117. S_FAULT =12
  5118. }
  5119. */
  5120. //check Transaction active
  5121. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5122. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5123. {
  5124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5125. {
  5126. tempIndex = ((gun_index==2) ? 1: 0);
  5127. }
  5128. else
  5129. {
  5130. tempIndex = gun_index;
  5131. }
  5132. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5133. {
  5134. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5135. {
  5136. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5137. {
  5138. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5139. {
  5140. currentStatus = Preparing; //OCPP Status: Preparing
  5141. }
  5142. else
  5143. {
  5144. currentStatus = Available; //OCPP Status: Available
  5145. }
  5146. }
  5147. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5148. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5149. ) //S_PRECHARGE
  5150. {
  5151. currentStatus = Preparing; //OCPP Status: Preparing
  5152. }
  5153. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5154. {
  5155. currentStatus = Charging; //OCPP Status: Charging
  5156. }
  5157. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5158. {
  5159. currentStatus = Finishing; //OCPP Status: Finishing
  5160. }
  5161. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5162. {
  5163. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5164. }
  5165. 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
  5166. {
  5167. currentStatus = Unavailable; //OCPP Status: Unavailable
  5168. }
  5169. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5170. {
  5171. currentStatus = Faulted; //OCPP Status: Faulted
  5172. }
  5173. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5174. {
  5175. currentStatus = Reserved; //OCPP Status: Reserved
  5176. }
  5177. } //end of the same index
  5178. }//end of for CHAdeMO_QUANTITY
  5179. }
  5180. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5181. {
  5182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5183. {
  5184. tempIndex = ((gun_index==2) ? 1: 0);
  5185. }
  5186. else
  5187. {
  5188. tempIndex = gun_index;
  5189. }
  5190. for (int index = 0; index < CCS_QUANTITY; index++)
  5191. {
  5192. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5193. {
  5194. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5195. {
  5196. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5197. {
  5198. currentStatus = Preparing; //OCPP Status: Preparing
  5199. }
  5200. else
  5201. {
  5202. currentStatus = Available; //OCPP Status: Available
  5203. }
  5204. }
  5205. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5206. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5207. ) //S_PRECHARGE
  5208. {
  5209. currentStatus = Preparing; //OCPP Status: Preparing
  5210. }
  5211. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5212. {
  5213. currentStatus = Charging; //OCPP Status: Charging
  5214. }
  5215. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5216. {
  5217. currentStatus = Finishing; //OCPP Status: Finishing
  5218. }
  5219. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5220. {
  5221. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5222. }
  5223. 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
  5224. {
  5225. currentStatus = Unavailable; //OCPP Status : Unavailable
  5226. }
  5227. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5228. {
  5229. currentStatus = Faulted; //OCPP Status: Faulted
  5230. }
  5231. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5232. {
  5233. currentStatus = Reserved; //OCPP Status: Reserved
  5234. }
  5235. } //end of the same index
  5236. } // end of for CCS_QUANTITY
  5237. }
  5238. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5239. {
  5240. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5241. {
  5242. tempIndex = ((gun_index==2) ? 1: 0);
  5243. }
  5244. else
  5245. {
  5246. tempIndex = gun_index;
  5247. }
  5248. for (int index = 0; index < GB_QUANTITY; index++)
  5249. {
  5250. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5251. {
  5252. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5253. {
  5254. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5255. {
  5256. currentStatus = Preparing; //OCPP Status: Preparing
  5257. }
  5258. else
  5259. {
  5260. currentStatus = Available; //OCPP Status: Available
  5261. }
  5262. }
  5263. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5264. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5265. ) //S_PRECHARGE
  5266. {
  5267. currentStatus = Preparing; //OCPP Status: Preparing
  5268. }
  5269. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5270. {
  5271. currentStatus = Charging; //OCPP Status: Charging
  5272. }
  5273. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5274. {
  5275. currentStatus = Finishing; //OCPP Status: Finishing
  5276. }
  5277. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5278. {
  5279. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5280. }
  5281. 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
  5282. {
  5283. currentStatus = Unavailable; //OCPP Status: Unavailable
  5284. }
  5285. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5286. {
  5287. currentStatus = Faulted; //OCPP Status: Faulted
  5288. }
  5289. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5290. {
  5291. currentStatus = Reserved; //OCPP Status: Reserved
  5292. }
  5293. } //end of the same index
  5294. } // end of for GB_QUANTITY
  5295. }
  5296. else if(gunType[gun_index] == GUN_TYPE_DO)
  5297. {
  5298. tempIndex = gun_index;
  5299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5300. {
  5301. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5302. {
  5303. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5304. {
  5305. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5306. {
  5307. currentStatus = Preparing; //OCPP Status: Preparing
  5308. }
  5309. else
  5310. {
  5311. currentStatus = Available; //OCPP Status: Available
  5312. }
  5313. }
  5314. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5315. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5316. ) //S_PRECHARGE
  5317. {
  5318. currentStatus = Preparing; //OCPP Status: Preparing
  5319. }
  5320. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5321. {
  5322. currentStatus = Charging; //OCPP Status: Charging
  5323. }
  5324. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5325. {
  5326. currentStatus = Finishing; //OCPP Status: Finishing
  5327. }
  5328. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5329. {
  5330. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5331. }
  5332. 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
  5333. {
  5334. currentStatus = Unavailable; //OCPP Status: Unavailable
  5335. }
  5336. 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
  5337. {
  5338. currentStatus = Faulted; //OCPP Status: Faulted
  5339. }
  5340. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5341. {
  5342. currentStatus = Reserved; //OCPP Status: Reserved
  5343. }
  5344. } //end of the same index
  5345. }
  5346. }
  5347. else
  5348. {
  5349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5350. {
  5351. tempIndex = 2;
  5352. }
  5353. else
  5354. {
  5355. tempIndex = gun_index;
  5356. }
  5357. for (int index = 0; index < AC_QUANTITY; index++)
  5358. {
  5359. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5360. {
  5361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5362. {
  5363. 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))
  5364. {
  5365. currentStatus = Preparing; //OCPP Status: Preparing
  5366. }
  5367. else
  5368. {
  5369. currentStatus = Available; //OCPP Status: Available
  5370. }
  5371. }
  5372. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5373. {
  5374. currentStatus = Preparing; //OCPP Status: Preparing
  5375. }
  5376. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5377. {
  5378. currentStatus = Charging; //OCPP Status: Charging
  5379. }
  5380. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5381. {
  5382. currentStatus = Finishing; //OCPP Status: Finishing
  5383. }
  5384. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5385. {
  5386. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5387. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5388. else
  5389. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5390. }
  5391. 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
  5392. {
  5393. currentStatus = Unavailable; //OCPP Status: Unavailable
  5394. }
  5395. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5396. {
  5397. currentStatus = Faulted; //OCPP Status: Faulted
  5398. }
  5399. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5400. {
  5401. currentStatus = Reserved; //OCPP Status: Reserved
  5402. }
  5403. }//end of the same index
  5404. }//end of for AC_QUANTITY
  5405. }
  5406. //it's option
  5407. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5408. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5409. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5410. {
  5411. isStateChanged = FALSE;
  5412. }
  5413. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5414. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5415. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5416. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5417. random_uuid(guid);
  5418. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5419. , MESSAGE_TYPE_CALL
  5420. , guid
  5421. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5422. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5423. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5424. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5425. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5426. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5427. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5428. if((server_sign == TRUE) && isStateChanged)
  5429. {
  5430. LWS_Send(message);
  5431. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5432. 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*/)
  5433. {
  5434. //DEBUG_ERROR("statusNotification mapitem pass");
  5435. result = PASS;
  5436. }
  5437. }
  5438. else
  5439. {
  5440. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5441. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5442. result = PASS;
  5443. }
  5444. return result;
  5445. }
  5446. int sendStopTransactionRequest(int gun_index)
  5447. {
  5448. mtrace();
  5449. int result = FAIL;
  5450. //char message[1500]={0};
  5451. char guid[37]={0};
  5452. char tempdata[65]={0};
  5453. int tempIndex = 0;
  5454. char TempStopTransaction[256];
  5455. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5456. //int idx_sample=0;
  5457. DEBUG_INFO("sendStopTransactionRequest \n");
  5458. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5459. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5460. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5461. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5463. {
  5464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5465. {
  5466. tempIndex = ((gun_index==2) ? 1: 0);
  5467. }
  5468. else
  5469. {
  5470. tempIndex = gun_index;
  5471. }
  5472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5473. {
  5474. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5475. {
  5476. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5477. }
  5478. }// END OF CHAdeMO_QUANTITY
  5479. }
  5480. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5481. {
  5482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5483. {
  5484. tempIndex = ((gun_index==2) ? 1: 0);
  5485. }
  5486. else
  5487. {
  5488. tempIndex = gun_index;
  5489. }
  5490. for (int index = 0; index < CCS_QUANTITY; index++)
  5491. {
  5492. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5493. {
  5494. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5495. }
  5496. }// END OF CCS_QUANTITY
  5497. }
  5498. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5499. {
  5500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5501. {
  5502. tempIndex = ((gun_index==2) ? 1: 0);
  5503. }
  5504. else
  5505. {
  5506. tempIndex = gun_index;
  5507. }
  5508. for (int index = 0; index < GB_QUANTITY; index++)
  5509. {
  5510. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5511. {
  5512. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5513. }
  5514. }// END OF GB_QUANTITY
  5515. }
  5516. else if(gunType[gun_index] == GUN_TYPE_DO)
  5517. {
  5518. tempIndex = gun_index;
  5519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5520. {
  5521. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5522. {
  5523. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5524. }
  5525. }// END OF GB_QUANTITY
  5526. }
  5527. else
  5528. {
  5529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5530. {
  5531. tempIndex = 2;
  5532. }
  5533. else
  5534. {
  5535. tempIndex = gun_index;
  5536. }
  5537. for (int index = 0; index < AC_QUANTITY; index++)
  5538. {
  5539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5540. {
  5541. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5542. }
  5543. }// END OF AC_QUANTITY
  5544. }
  5545. //====================================== Stop Transaction Time =====================================================
  5546. struct timeval tmnow;
  5547. struct tm *tm;
  5548. char buf[28];//, usec_buf[6];
  5549. gettimeofday(&tmnow, NULL);
  5550. time_t t;
  5551. t = time(NULL);
  5552. /*UTC time and date*/
  5553. tm = gmtime(&t);
  5554. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5556. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5557. random_uuid(guid);
  5558. /***********************************transactionData******************************************************/
  5559. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5561. //=================================
  5562. // Transaction_Begin
  5563. //=================================
  5564. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5565. {
  5566. //============================================ Energy.Active.Import.Interval ================================
  5567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5570. 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*/]);
  5571. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5572. 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))
  5573. {
  5574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5575. }
  5576. else
  5577. {
  5578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5579. }
  5580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5582. }
  5583. //=================================
  5584. // Transaction_End
  5585. //=================================
  5586. // ================================= Current.Import L1 ===============================================
  5587. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5588. {
  5589. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5590. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5591. {
  5592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5593. {
  5594. tempIndex = ((gun_index==2) ? 1: 0);
  5595. }
  5596. else
  5597. {
  5598. tempIndex = gun_index;
  5599. }
  5600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5601. {
  5602. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5603. {
  5604. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5605. }
  5606. }// End of for CHAdeMO_QUANTITY
  5607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5608. }
  5609. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5610. {
  5611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5612. {
  5613. tempIndex = ((gun_index==2) ? 1: 0);
  5614. }
  5615. else
  5616. {
  5617. tempIndex = gun_index;
  5618. }
  5619. for (int index = 0; index < CCS_QUANTITY; index++)
  5620. {
  5621. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5622. {
  5623. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5624. }
  5625. }// End of for CCS_QUANTITY
  5626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5627. }
  5628. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5629. {
  5630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5631. {
  5632. tempIndex = ((gun_index==2) ? 1: 0);
  5633. }
  5634. else
  5635. {
  5636. tempIndex = gun_index;
  5637. }
  5638. for (int index = 0; index < GB_QUANTITY; index++)
  5639. {
  5640. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5641. {
  5642. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5643. }
  5644. }// End of for GB_QUANTITY
  5645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5646. }
  5647. else if(gunType[gun_index] == GUN_TYPE_DO)
  5648. {
  5649. tempIndex = gun_index;
  5650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5651. {
  5652. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5653. {
  5654. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5655. }
  5656. }
  5657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5658. }
  5659. else
  5660. {
  5661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5662. {
  5663. tempIndex = 2;
  5664. }
  5665. else
  5666. {
  5667. tempIndex = gun_index;
  5668. }
  5669. for (int index = 0; index < AC_QUANTITY; index++)
  5670. {
  5671. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5672. {
  5673. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5674. }
  5675. }// End of for AC_QUANTITY
  5676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5677. }
  5678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5683. }
  5684. // ================================= Energy.Active.Import.Interval ==============================================
  5685. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5686. {
  5687. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5688. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5689. {
  5690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5691. {
  5692. tempIndex = ((gun_index==2) ? 1: 0);
  5693. }
  5694. else
  5695. {
  5696. tempIndex = gun_index;
  5697. }
  5698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5699. {
  5700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5701. {
  5702. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5703. }
  5704. }// END OF CHAdeMO_QUANTITY
  5705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5706. }
  5707. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5708. {
  5709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5710. {
  5711. tempIndex = ((gun_index==2) ? 1: 0);
  5712. }
  5713. else
  5714. {
  5715. tempIndex = gun_index;
  5716. }
  5717. for (int index = 0; index < CCS_QUANTITY; index++)
  5718. {
  5719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5720. {
  5721. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5722. }
  5723. }// END OF CCS_QUANTITY
  5724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5725. }
  5726. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5727. {
  5728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5729. {
  5730. tempIndex = ((gun_index==2) ? 1: 0);
  5731. }
  5732. else
  5733. {
  5734. tempIndex = gun_index;
  5735. }
  5736. for (int index = 0; index < GB_QUANTITY; index++)
  5737. {
  5738. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5739. {
  5740. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5741. }
  5742. }// END OF GB_QUANTITY
  5743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5744. }
  5745. else if(gunType[gun_index] == GUN_TYPE_DO)
  5746. {
  5747. tempIndex = gun_index;
  5748. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5749. {
  5750. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5751. {
  5752. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5753. }
  5754. }
  5755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5756. }
  5757. else
  5758. {
  5759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5760. {
  5761. tempIndex = 2;
  5762. }
  5763. else
  5764. {
  5765. tempIndex = gun_index;
  5766. }
  5767. for (int index = 0; index < AC_QUANTITY; index++)
  5768. {
  5769. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5770. {
  5771. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5772. }
  5773. }// END OF AC_QUANTITY
  5774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5775. }
  5776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5781. }
  5782. //=================================== Power.Active.Import ==================================================
  5783. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5784. {
  5785. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5786. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5787. {
  5788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5789. {
  5790. tempIndex = ((gun_index==2) ? 1: 0);
  5791. }
  5792. else
  5793. {
  5794. tempIndex = gun_index;
  5795. }
  5796. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5797. {
  5798. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5799. {
  5800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5801. }
  5802. } // End for CHAdeMO_QUANTITY
  5803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5804. }
  5805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5806. {
  5807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5808. {
  5809. tempIndex = ((gun_index==2) ? 1: 0);
  5810. }
  5811. else
  5812. {
  5813. tempIndex = gun_index;
  5814. }
  5815. for (int index = 0; index < CCS_QUANTITY; index++)
  5816. {
  5817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5818. {
  5819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5820. }
  5821. } // END for CCS_QUANTITY
  5822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5823. }
  5824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5825. {
  5826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5827. {
  5828. tempIndex = ((gun_index==2) ? 1: 0);
  5829. }
  5830. else
  5831. {
  5832. tempIndex = gun_index;
  5833. }
  5834. for (int index = 0; index < GB_QUANTITY; index++)
  5835. {
  5836. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5837. {
  5838. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5839. }
  5840. }// END for GB_QUANTITY
  5841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5842. }
  5843. else if(gunType[gun_index] == GUN_TYPE_DO)
  5844. {
  5845. tempIndex = gun_index;
  5846. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5847. {
  5848. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5849. {
  5850. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5851. }
  5852. }
  5853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5854. }
  5855. else
  5856. {
  5857. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5858. {
  5859. tempIndex = 2;
  5860. }
  5861. else
  5862. {
  5863. tempIndex = gun_index;
  5864. }
  5865. for (int index = 0; index < AC_QUANTITY; index++)
  5866. {
  5867. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5868. {
  5869. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5870. }
  5871. } // END for AC_QUANTITY
  5872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5873. }
  5874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5879. }
  5880. //============================ Voltage L1 ====================================
  5881. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5882. {
  5883. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5884. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5885. {
  5886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5887. {
  5888. tempIndex = ((gun_index==2) ? 1: 0);
  5889. }
  5890. else
  5891. {
  5892. tempIndex = gun_index;
  5893. }
  5894. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5895. {
  5896. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5897. {
  5898. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5899. }
  5900. } // END OF FOR CHAdeMO_QUANTITY
  5901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5902. }
  5903. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5904. {
  5905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5906. {
  5907. tempIndex = ((gun_index==2) ? 1: 0);
  5908. }
  5909. else
  5910. {
  5911. tempIndex = gun_index;
  5912. }
  5913. for (int index = 0; index < CCS_QUANTITY; index++)
  5914. {
  5915. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5916. {
  5917. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5918. }
  5919. } // END OF FOR CCS_QUANTITY
  5920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5921. }
  5922. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5923. {
  5924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5925. {
  5926. tempIndex = ((gun_index==2) ? 1: 0);
  5927. }
  5928. else
  5929. {
  5930. tempIndex = gun_index;
  5931. }
  5932. for (int index = 0; index < GB_QUANTITY; index++)
  5933. {
  5934. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5935. {
  5936. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5937. }
  5938. } // END OF FOR GB_QUANTITY
  5939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5940. }
  5941. else if(gunType[gun_index] == GUN_TYPE_DO)
  5942. {
  5943. tempIndex = gun_index;
  5944. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5945. {
  5946. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5947. {
  5948. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5949. }
  5950. }
  5951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5952. }
  5953. else
  5954. {
  5955. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5956. {
  5957. tempIndex = 2;
  5958. }
  5959. else
  5960. {
  5961. tempIndex = gun_index;
  5962. }
  5963. for (int index = 0; index < AC_QUANTITY; index++)
  5964. {
  5965. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5966. {
  5967. 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
  5968. }
  5969. } // END OF FOR AC_QUANTITY
  5970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5971. }
  5972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5977. }
  5978. //====================== End SoC ================================
  5979. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5980. {
  5981. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5982. 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))
  5983. {
  5984. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5985. {
  5986. tempIndex = ((gun_index==2) ? 1: 0);
  5987. }
  5988. else
  5989. {
  5990. tempIndex = gun_index;
  5991. }
  5992. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5993. {
  5994. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5995. {
  5996. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5997. {
  5998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5999. }
  6000. }
  6001. }
  6002. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6003. {
  6004. for (int index = 0; index < CCS_QUANTITY; index++)
  6005. {
  6006. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6007. {
  6008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6009. }
  6010. }
  6011. }
  6012. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6013. {
  6014. for (int index = 0; index < GB_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6017. {
  6018. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6019. }
  6020. }
  6021. }
  6022. else if(gunType[gun_index] == GUN_TYPE_DO)
  6023. {
  6024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6025. {
  6026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6027. {
  6028. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6029. }
  6030. }
  6031. }
  6032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6038. } // END FOR DC CASE
  6039. }
  6040. // ================================= Current.Import L2 ===============================================
  6041. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6042. {
  6043. // AC 3 phse L2 current
  6044. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6045. {
  6046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6047. {
  6048. tempIndex = 2;
  6049. }
  6050. else
  6051. {
  6052. tempIndex = gun_index;
  6053. }
  6054. for (int index = 0; index < AC_QUANTITY; index++)
  6055. {
  6056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6057. {
  6058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6059. }
  6060. }// End of for AC_QUANTITY
  6061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6062. }
  6063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6068. }
  6069. // ================================= Current.Import L3 ===============================================
  6070. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6071. {
  6072. // AC 3 phse L3 current
  6073. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6074. {
  6075. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6076. {
  6077. tempIndex = 2;
  6078. }
  6079. else
  6080. {
  6081. tempIndex = gun_index;
  6082. }
  6083. for (int index = 0; index < AC_QUANTITY; index++)
  6084. {
  6085. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6086. {
  6087. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6088. }
  6089. }// End of for AC_QUANTITY
  6090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6091. }
  6092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6097. }
  6098. //============================ Voltage L2 ====================================
  6099. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6100. {
  6101. // AC 3 phse L2 voltage
  6102. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6103. {
  6104. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6105. {
  6106. tempIndex = 2;
  6107. }
  6108. else
  6109. {
  6110. tempIndex = gun_index;
  6111. }
  6112. for (int index = 0; index < AC_QUANTITY; index++)
  6113. {
  6114. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6115. {
  6116. 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
  6117. }
  6118. } // END OF FOR AC_QUANTITY
  6119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6120. }
  6121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6126. }
  6127. //============================ Voltage L3 ====================================
  6128. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6129. {
  6130. // AC 3 phse L3 voltage
  6131. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6132. {
  6133. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6134. {
  6135. tempIndex = 2;
  6136. }
  6137. else
  6138. {
  6139. tempIndex = gun_index;
  6140. }
  6141. for (int index = 0; index < AC_QUANTITY; index++)
  6142. {
  6143. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6144. {
  6145. 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
  6146. }
  6147. } // END OF FOR AC_QUANTITY
  6148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6149. }
  6150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6155. }
  6156. //====================== Start SoC ================================
  6157. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6158. {
  6159. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6160. 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))
  6161. {
  6162. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6163. {
  6164. tempIndex = ((gun_index==2) ? 1: 0);
  6165. }
  6166. else
  6167. {
  6168. tempIndex = gun_index;
  6169. }
  6170. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6171. {
  6172. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6173. {
  6174. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6175. {
  6176. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6177. }
  6178. }
  6179. }
  6180. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6181. {
  6182. for (int index = 0; index < CCS_QUANTITY; index++)
  6183. {
  6184. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6185. {
  6186. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6187. }
  6188. }
  6189. }
  6190. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6191. {
  6192. for (int index = 0; index < GB_QUANTITY; index++)
  6193. {
  6194. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6195. {
  6196. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6197. }
  6198. }
  6199. }
  6200. else if(gunType[gun_index] == GUN_TYPE_DO)
  6201. {
  6202. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6203. {
  6204. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6205. {
  6206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6207. }
  6208. }
  6209. }
  6210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6216. } // END FOR DC CASE
  6217. }
  6218. //================================================ Message create ====================================================
  6219. json_object *StopTransaction = json_object_new_object();
  6220. json_object *transactionDatas = json_object_new_array();
  6221. json_object *sampledValues = json_object_new_array();
  6222. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6223. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6224. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6225. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6226. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6227. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6228. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6229. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6230. {
  6231. json_object *transactionData = json_object_new_object();
  6232. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6233. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6234. {
  6235. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6236. {
  6237. json_object *sampledValue = json_object_new_object();
  6238. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6239. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6240. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6241. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6242. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6243. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6244. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6245. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6246. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6247. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6248. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6249. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6250. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6251. json_object_array_add(sampledValues, sampledValue);
  6252. }
  6253. }
  6254. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6255. json_object_array_add(transactionDatas, transactionData);
  6256. }
  6257. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6258. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6259. ,MESSAGE_TYPE_CALL
  6260. ,guid
  6261. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6262. json_object_put(StopTransaction);
  6263. #if 1 // for TempStopTransaction
  6264. //Delete TempStopTransaction
  6265. if((access(TempStopTransaction,F_OK))!=-1)
  6266. {
  6267. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6268. }
  6269. #endif
  6270. #if 1
  6271. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6272. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6273. {
  6274. result = PASS;
  6275. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6276. }
  6277. #endif
  6278. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6279. OCPP_insert_transaction_msg(NO, queuedata);
  6280. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6281. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6282. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6283. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6284. {
  6285. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6286. }
  6287. //for test
  6288. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6289. return result;
  6290. }
  6291. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6292. {
  6293. mtrace();
  6294. int result = FAIL;
  6295. char guid[37]={0};
  6296. char tempdata[65]={0};
  6297. int tempIndex = 0;
  6298. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6299. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6300. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6301. //set value
  6302. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6303. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6304. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6305. -1);
  6306. random_uuid(guid);
  6307. //UTC Date time
  6308. struct timeval tmnow;
  6309. struct tm *tm;
  6310. char buf[28];//, usec_buf[6];
  6311. gettimeofday(&tmnow, NULL);
  6312. time_t t;
  6313. t = time(NULL);
  6314. /*UTC time and date*/
  6315. tm = gmtime(&t);
  6316. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6317. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6318. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6319. //********************************(1)Current.Import L1************************************************/
  6320. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6321. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6322. (dataType == ReadingContext_Trigger))
  6323. {
  6324. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6325. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6326. {
  6327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6328. {
  6329. tempIndex = ((gun_index==2) ? 1: 0);
  6330. }
  6331. else
  6332. {
  6333. tempIndex = gun_index;
  6334. }
  6335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6336. {
  6337. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6338. {
  6339. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6340. }
  6341. }
  6342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6343. }
  6344. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6345. {
  6346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6347. {
  6348. tempIndex = ((gun_index==2) ? 1: 0);
  6349. }
  6350. else
  6351. {
  6352. tempIndex = gun_index;
  6353. }
  6354. for (int index = 0; index < CCS_QUANTITY; index++)
  6355. {
  6356. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6357. {
  6358. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6359. }
  6360. }
  6361. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6362. }
  6363. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6364. {
  6365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6366. {
  6367. tempIndex = ((gun_index==2) ? 1: 0);
  6368. }
  6369. else
  6370. {
  6371. tempIndex = gun_index;
  6372. }
  6373. for (int index = 0; index < GB_QUANTITY; index++)
  6374. {
  6375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6376. {
  6377. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6378. }
  6379. }
  6380. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6381. }
  6382. else if(gunType[gun_index] == GUN_TYPE_DO)
  6383. {
  6384. tempIndex = gun_index;
  6385. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6386. {
  6387. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6388. {
  6389. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6390. }
  6391. }
  6392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6393. }
  6394. else
  6395. {
  6396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6397. {
  6398. tempIndex = 2;
  6399. }
  6400. else
  6401. {
  6402. tempIndex = gun_index;
  6403. }
  6404. for (int index = 0; index < AC_QUANTITY; index++)
  6405. {
  6406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6407. {
  6408. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6409. }
  6410. }
  6411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6412. }
  6413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6418. }
  6419. //********************************(2)Energy.Active.Import.Register ************************************************/
  6420. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6421. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6422. (dataType == ReadingContext_Trigger))
  6423. {
  6424. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6425. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6426. {
  6427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6428. {
  6429. tempIndex = ((gun_index==2) ? 1: 0);
  6430. }
  6431. else
  6432. {
  6433. tempIndex = gun_index;
  6434. }
  6435. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6436. {
  6437. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6438. {
  6439. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6440. }
  6441. }
  6442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6443. }
  6444. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6445. {
  6446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6447. {
  6448. tempIndex = ((gun_index==2) ? 1: 0);
  6449. }
  6450. else
  6451. {
  6452. tempIndex = gun_index;
  6453. }
  6454. for (int index = 0; index < CCS_QUANTITY; index++)
  6455. {
  6456. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6457. {
  6458. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6459. }
  6460. }
  6461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6462. }
  6463. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6464. {
  6465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6466. {
  6467. tempIndex = ((gun_index==2) ? 1: 0);
  6468. }
  6469. else
  6470. {
  6471. tempIndex = gun_index;
  6472. }
  6473. for (int index = 0; index < GB_QUANTITY; index++)
  6474. {
  6475. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6476. {
  6477. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6478. }
  6479. }
  6480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6481. }
  6482. else if(gunType[gun_index] == GUN_TYPE_DO)
  6483. {
  6484. tempIndex = gun_index;
  6485. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6486. {
  6487. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6488. {
  6489. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6490. }
  6491. }
  6492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6493. }
  6494. else
  6495. {
  6496. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6497. {
  6498. tempIndex = 2;
  6499. }
  6500. else
  6501. {
  6502. tempIndex = gun_index;
  6503. }
  6504. for (int index = 0; index < AC_QUANTITY; index++)
  6505. {
  6506. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6507. {
  6508. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6509. }
  6510. }
  6511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6512. }
  6513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6518. }
  6519. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6520. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6521. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6522. (dataType == ReadingContext_Trigger))
  6523. {
  6524. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6525. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6526. {
  6527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6528. {
  6529. tempIndex = ((gun_index==2) ? 1: 0);
  6530. }
  6531. else
  6532. {
  6533. tempIndex = gun_index;
  6534. }
  6535. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6536. {
  6537. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6538. {
  6539. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6540. }
  6541. } // END OF FOR CHAdeMO_QUANTITY
  6542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6543. }
  6544. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6545. {
  6546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6547. {
  6548. tempIndex = ((gun_index==2) ? 1: 0);
  6549. }
  6550. else
  6551. {
  6552. tempIndex = gun_index;
  6553. }
  6554. for (int index = 0; index < CCS_QUANTITY; index++)
  6555. {
  6556. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6557. {
  6558. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6559. }
  6560. } // END OF CCS_QUANTITY
  6561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6562. }
  6563. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6564. {
  6565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6566. {
  6567. tempIndex = ((gun_index==2) ? 1: 0);
  6568. }
  6569. else
  6570. {
  6571. tempIndex = gun_index;
  6572. }
  6573. for (int index = 0; index < GB_QUANTITY; index++)
  6574. {
  6575. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6576. {
  6577. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6578. }
  6579. } // END OF GB_QUANTITY
  6580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6581. }
  6582. else if(gunType[gun_index] == GUN_TYPE_DO)
  6583. {
  6584. tempIndex = gun_index;
  6585. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6586. {
  6587. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6588. {
  6589. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6590. }
  6591. }
  6592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6593. }
  6594. else
  6595. {
  6596. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6597. {
  6598. tempIndex = 2;
  6599. }
  6600. else
  6601. {
  6602. tempIndex = gun_index;
  6603. }
  6604. for (int index = 0; index < AC_QUANTITY; index++)
  6605. {
  6606. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6607. {
  6608. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6609. }
  6610. }
  6611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6612. }
  6613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6618. }
  6619. //********************************(4)Power.Active.Import************************************************/
  6620. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6621. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6622. (dataType == ReadingContext_Trigger))
  6623. {
  6624. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6625. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6626. {
  6627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6628. {
  6629. tempIndex = ((gun_index==2) ? 1: 0);
  6630. }
  6631. else
  6632. {
  6633. tempIndex = gun_index;
  6634. }
  6635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6636. {
  6637. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6638. {
  6639. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6640. }
  6641. } // END OF FOR
  6642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6643. }
  6644. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6645. {
  6646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6647. {
  6648. tempIndex = ((gun_index==2) ? 1: 0);
  6649. }
  6650. else
  6651. {
  6652. tempIndex = gun_index;
  6653. }
  6654. for (int index = 0; index < CCS_QUANTITY; index++)
  6655. {
  6656. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6657. {
  6658. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6659. }
  6660. }
  6661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6662. }
  6663. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6664. {
  6665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6666. {
  6667. tempIndex = ((gun_index==2) ? 1: 0);
  6668. }
  6669. else
  6670. {
  6671. tempIndex = gun_index;
  6672. }
  6673. for (int index = 0; index < GB_QUANTITY; index++)
  6674. {
  6675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6676. {
  6677. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6678. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6679. }
  6680. }
  6681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6682. }
  6683. else if(gunType[gun_index] == GUN_TYPE_DO)
  6684. {
  6685. tempIndex = gun_index;
  6686. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6687. {
  6688. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6689. {
  6690. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6691. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6692. }
  6693. }
  6694. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6695. }
  6696. else
  6697. {
  6698. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6699. {
  6700. tempIndex = 2;
  6701. }
  6702. else
  6703. {
  6704. tempIndex = gun_index;
  6705. }
  6706. for (int index = 0; index < AC_QUANTITY; index++)
  6707. {
  6708. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6709. {
  6710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6711. }
  6712. }
  6713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6714. }
  6715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6718. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6719. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6720. }
  6721. //***********************************************(5)VOLTAGE L1******************************************************/
  6722. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6723. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6724. (dataType == ReadingContext_Trigger))
  6725. {
  6726. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6727. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6728. {
  6729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6730. {
  6731. tempIndex = ((gun_index==2) ? 1: 0);
  6732. }
  6733. else
  6734. {
  6735. tempIndex = gun_index;
  6736. }
  6737. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6738. {
  6739. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6740. {
  6741. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6742. }
  6743. }
  6744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6745. }
  6746. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6747. {
  6748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6749. {
  6750. tempIndex = ((gun_index==2) ? 1: 0);
  6751. }
  6752. else
  6753. {
  6754. tempIndex = gun_index;
  6755. }
  6756. for (int index = 0; index < CCS_QUANTITY; index++)
  6757. {
  6758. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6759. {
  6760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6761. }
  6762. }
  6763. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6764. }
  6765. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6766. {
  6767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6768. {
  6769. tempIndex = ((gun_index==2) ? 1: 0);
  6770. }
  6771. else
  6772. {
  6773. tempIndex = gun_index;
  6774. }
  6775. for (int index = 0; index < GB_QUANTITY; index++)
  6776. {
  6777. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6778. {
  6779. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6780. }
  6781. }
  6782. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6783. }
  6784. else if(gunType[gun_index] == GUN_TYPE_DO)
  6785. {
  6786. tempIndex = gun_index;
  6787. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6788. {
  6789. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6790. {
  6791. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6792. }
  6793. }
  6794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6795. }
  6796. else
  6797. {
  6798. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6799. {
  6800. tempIndex = 2;
  6801. }
  6802. else
  6803. {
  6804. tempIndex = gun_index;
  6805. }
  6806. for (int index = 0; index < AC_QUANTITY; index++)
  6807. {
  6808. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6809. {
  6810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6811. }
  6812. }
  6813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6814. }
  6815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6818. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6819. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6820. }
  6821. //***********************************************(6)SOC******************************************************/
  6822. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6823. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6824. (dataType == ReadingContext_Trigger))
  6825. {
  6826. 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))
  6827. {
  6828. //idx_sample=5;
  6829. //sampledValue = NULL;
  6830. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6831. {
  6832. tempIndex = ((gun_index==2) ? 1: 0);
  6833. }
  6834. else
  6835. {
  6836. tempIndex = gun_index;
  6837. }
  6838. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6839. {
  6840. //tempIndex = ((gun_index==2) ? 1: 0);
  6841. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6842. {
  6843. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6844. {
  6845. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6846. }
  6847. }
  6848. }
  6849. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6850. {
  6851. //tempIndex = ((gun_index==2) ? 1: 0);
  6852. for (int index = 0; index < CCS_QUANTITY; index++)
  6853. {
  6854. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6855. {
  6856. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6857. }
  6858. }
  6859. }
  6860. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6861. {
  6862. //tempIndex = ((gun_index==2) ? 1: 0);
  6863. for (int index = 0; index < GB_QUANTITY; index++)
  6864. {
  6865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6866. {
  6867. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6868. }
  6869. }
  6870. }
  6871. else if(gunType[gun_index] == GUN_TYPE_DO)
  6872. {
  6873. //tempIndex = ((gun_index==2) ? 1: 0);
  6874. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6875. {
  6876. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6877. {
  6878. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6879. }
  6880. }
  6881. }
  6882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6885. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6887. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6888. }
  6889. }
  6890. //********************************(7)Current.Import L2************************************************/
  6891. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6892. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6893. (dataType == ReadingContext_Trigger))
  6894. {
  6895. // Only for AC 3 phase
  6896. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6897. {
  6898. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6899. {
  6900. tempIndex = 2;
  6901. }
  6902. else
  6903. {
  6904. tempIndex = gun_index;
  6905. }
  6906. for (int index = 0; index < AC_QUANTITY; index++)
  6907. {
  6908. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6909. {
  6910. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6911. }
  6912. }
  6913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6914. }
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6920. }
  6921. //********************************(8)Current.Import L3************************************************/
  6922. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6923. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6924. (dataType == ReadingContext_Trigger))
  6925. {
  6926. // Only for AC 3 phase
  6927. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6928. {
  6929. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6930. {
  6931. tempIndex = 2;
  6932. }
  6933. else
  6934. {
  6935. tempIndex = gun_index;
  6936. }
  6937. for (int index = 0; index < AC_QUANTITY; index++)
  6938. {
  6939. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6940. {
  6941. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6942. }
  6943. }
  6944. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6945. }
  6946. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6947. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6948. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6949. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6950. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6951. }
  6952. //***********************************************(9)VOLTAGE L2******************************************************/
  6953. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6954. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6955. (dataType == ReadingContext_Trigger))
  6956. {
  6957. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6958. {
  6959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6960. {
  6961. tempIndex = 2;
  6962. }
  6963. else
  6964. {
  6965. tempIndex = gun_index;
  6966. }
  6967. for (int index = 0; index < AC_QUANTITY; index++)
  6968. {
  6969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6970. {
  6971. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6972. }
  6973. }
  6974. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6975. }
  6976. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6977. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6978. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6979. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6980. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6981. }
  6982. //***********************************************(10)VOLTAGE L3******************************************************/
  6983. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6984. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6985. (dataType == ReadingContext_Trigger))
  6986. {
  6987. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6988. {
  6989. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6990. {
  6991. tempIndex = 2;
  6992. }
  6993. else
  6994. {
  6995. tempIndex = gun_index;
  6996. }
  6997. for (int index = 0; index < AC_QUANTITY; index++)
  6998. {
  6999. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7000. {
  7001. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7002. }
  7003. }
  7004. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7005. }
  7006. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7007. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7008. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7011. }
  7012. //***********************************************(11)Current.Offered******************************************************/
  7013. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7014. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7015. (dataType == ReadingContext_Trigger))
  7016. {
  7017. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7018. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7019. {
  7020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7021. {
  7022. tempIndex = ((gun_index==2) ? 1: 0);
  7023. }
  7024. else
  7025. {
  7026. tempIndex = gun_index;
  7027. }
  7028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7029. {
  7030. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7031. {
  7032. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7033. }
  7034. } // END OF FOR CHAdeMO_QUANTITY
  7035. }
  7036. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7037. {
  7038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7039. {
  7040. tempIndex = ((gun_index==2) ? 1: 0);
  7041. }
  7042. else
  7043. {
  7044. tempIndex = gun_index;
  7045. }
  7046. for (int index = 0; index < CCS_QUANTITY; index++)
  7047. {
  7048. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7049. {
  7050. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7051. }
  7052. } // END OF CCS_QUANTITY
  7053. }
  7054. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7055. {
  7056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7057. {
  7058. tempIndex = ((gun_index==2) ? 1: 0);
  7059. }
  7060. else
  7061. {
  7062. tempIndex = gun_index;
  7063. }
  7064. for (int index = 0; index < GB_QUANTITY; index++)
  7065. {
  7066. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7067. {
  7068. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7069. }
  7070. } // END OF GB_QUANTITY
  7071. }
  7072. else if(gunType[gun_index] == GUN_TYPE_DO)
  7073. {
  7074. tempIndex = gun_index;
  7075. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7078. {
  7079. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7080. }
  7081. }
  7082. }
  7083. else
  7084. {
  7085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7086. {
  7087. tempIndex = 2;
  7088. }
  7089. else
  7090. {
  7091. tempIndex = gun_index;
  7092. }
  7093. for (int index = 0; index < AC_QUANTITY; index++)
  7094. {
  7095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7096. {
  7097. uint16_t currentOffer;
  7098. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7099. {
  7100. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7101. }
  7102. else
  7103. {
  7104. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7105. }
  7106. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7107. }
  7108. }
  7109. }
  7110. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7111. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7112. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7113. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7114. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7115. }
  7116. //***********************************************(12)Power.Offered******************************************************/
  7117. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7118. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7119. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7120. {
  7121. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7122. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7123. {
  7124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7125. {
  7126. tempIndex = ((gun_index==2) ? 1: 0);
  7127. }
  7128. else
  7129. {
  7130. tempIndex = gun_index;
  7131. }
  7132. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7133. {
  7134. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7135. {
  7136. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7137. }
  7138. } // END OF FOR CHAdeMO_QUANTITY
  7139. }
  7140. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7141. {
  7142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7143. {
  7144. tempIndex = ((gun_index==2) ? 1: 0);
  7145. }
  7146. else
  7147. {
  7148. tempIndex = gun_index;
  7149. }
  7150. for (int index = 0; index < CCS_QUANTITY; index++)
  7151. {
  7152. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7153. {
  7154. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7155. }
  7156. } // END OF CCS_QUANTITY
  7157. }
  7158. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7159. {
  7160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7161. {
  7162. tempIndex = ((gun_index==2) ? 1: 0);
  7163. }
  7164. else
  7165. {
  7166. tempIndex = gun_index;
  7167. }
  7168. for (int index = 0; index < GB_QUANTITY; index++)
  7169. {
  7170. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7171. {
  7172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7173. }
  7174. } // END OF GB_QUANTITY
  7175. }
  7176. else if(gunType[gun_index] == GUN_TYPE_DO)
  7177. {
  7178. tempIndex = gun_index;
  7179. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7180. {
  7181. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7182. {
  7183. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7184. }
  7185. }
  7186. }
  7187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7190. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7191. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7192. }
  7193. // Message create ====================================================================================================
  7194. if(TRUE)
  7195. {
  7196. json_object *MeterValueReq = json_object_new_object();
  7197. json_object *MeterValues = json_object_new_array();
  7198. json_object *sampledValues = json_object_new_array();
  7199. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7200. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7201. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7202. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7203. {
  7204. json_object *MeterValue = json_object_new_object();
  7205. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7206. {
  7207. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7208. {
  7209. json_object *sampledValue = json_object_new_object();
  7210. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7211. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7212. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7213. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7214. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7215. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7216. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7217. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7218. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7219. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7220. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7221. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7222. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7223. json_object_array_add(sampledValues, sampledValue);
  7224. }
  7225. }
  7226. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7227. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7228. json_object_array_add(MeterValues, MeterValue);
  7229. }
  7230. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7231. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7232. ,gun_index + 1
  7233. ,MESSAGE_TYPE_CALL
  7234. ,guid
  7235. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7236. json_object_put(MeterValueReq);
  7237. }
  7238. // Put request guid to hash map
  7239. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7240. 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*/)
  7241. {
  7242. result = PASS;
  7243. //DEBUG_INFO("MeterValues mapitem pass\n");
  7244. }
  7245. if((dataType != ReadingContext_Trigger) &&
  7246. (dataType != ReadingContext_Sample_Clock) &&
  7247. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7248. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7249. else
  7250. {
  7251. if(FirstHeartBeat)
  7252. LWS_Send(queuedata +2);
  7253. }
  7254. return result;
  7255. }
  7256. int sendLogStatusNotificationRequest(char *status)
  7257. {
  7258. mtrace();
  7259. int result = PASS;
  7260. char message[4096]={0};
  7261. char guid[37]={0};
  7262. char tempdata[128]={0};
  7263. json_object *LogStatusNotification = json_object_new_object();
  7264. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7265. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7266. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7267. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7268. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7269. random_uuid(guid);
  7270. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7271. json_object_put(LogStatusNotification);
  7272. LWS_Send(message);
  7273. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7274. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7275. {
  7276. result = PASS;
  7277. }
  7278. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7279. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7280. return result;
  7281. }
  7282. int sendSecurityEventNotificationRequest()
  7283. {
  7284. mtrace();
  7285. int result = PASS;
  7286. char message[4096]={0};
  7287. char guid[37]={0};
  7288. char tempdata[128]={0};
  7289. json_object *SecurityEventNotification = json_object_new_object();
  7290. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7291. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7292. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7293. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7294. random_uuid(guid);
  7295. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7296. json_object_put(SecurityEventNotification);
  7297. LWS_Send(message);
  7298. sprintf(tempdata, "SecurityEventNotification,0");
  7299. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7300. {
  7301. result = PASS;
  7302. }
  7303. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7304. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7305. return result;
  7306. }
  7307. int sendSignCertificateRequest()
  7308. {
  7309. mtrace();
  7310. int result = PASS;
  7311. char message[4096]={0};
  7312. char guid[37]={0};
  7313. char tempdata[128]={0};
  7314. json_object *SignCertificate = json_object_new_object();
  7315. DEBUG_INFO("sendSignCertificateRequest...\n");
  7316. // Read csr file content
  7317. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7318. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7319. char *line = NULL;
  7320. size_t len = 0;
  7321. while(getline(&line, &len, fp) != -1)
  7322. {
  7323. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7324. {
  7325. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7326. }
  7327. }
  7328. fclose(fp);
  7329. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7330. random_uuid(guid);
  7331. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7332. json_object_put(SignCertificate);
  7333. LWS_Send(message);
  7334. sprintf(tempdata, "SignCertificate,0");
  7335. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7336. {
  7337. result = PASS;
  7338. }
  7339. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7340. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7341. return result;
  7342. }
  7343. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7344. {
  7345. mtrace();
  7346. int result = PASS;
  7347. char message[110]={0};
  7348. char guid[37]={0};
  7349. char tempdata[65]={0};
  7350. json_object *FirmwareStatusNotification = json_object_new_object();
  7351. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7352. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7353. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7354. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7355. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7356. random_uuid(guid);
  7357. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7358. json_object_put(FirmwareStatusNotification);
  7359. LWS_Send(message);
  7360. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7361. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7362. {
  7363. result = PASS;
  7364. }
  7365. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7366. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7367. return result;
  7368. }
  7369. //==========================================
  7370. // send confirm routine
  7371. //==========================================
  7372. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7373. {
  7374. mtrace();
  7375. int result = FAIL;
  7376. char message[100]={0};
  7377. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7378. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7379. LWS_Send(message);
  7380. result = TRUE;
  7381. return result;
  7382. }
  7383. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7384. {
  7385. mtrace();
  7386. int result = FAIL;
  7387. char message[100]={0};
  7388. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7389. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7390. LWS_Send(message);
  7391. result = TRUE;
  7392. return result;
  7393. }
  7394. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7395. {
  7396. mtrace();
  7397. int result = FAIL;
  7398. char message[100]={0};
  7399. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7400. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7401. LWS_Send(message);
  7402. result = TRUE;
  7403. return result;
  7404. }
  7405. int sendClearCacheConfirmation(char *uuid,char *payload)
  7406. {
  7407. mtrace();
  7408. int result = FAIL;
  7409. char message[500]={0};
  7410. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7411. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7412. LWS_Send(message);
  7413. return result;
  7414. }
  7415. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7416. {
  7417. mtrace();
  7418. int result = FAIL;
  7419. char message[500]={0};
  7420. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7421. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7422. LWS_Send(message);
  7423. return result;
  7424. }
  7425. int sendDataTransferConfirmation(char *uuid,char *payload)
  7426. {
  7427. mtrace();
  7428. char statusStr[20]={0};
  7429. char dataStr[10]={0};
  7430. char sstr[20]={0};
  7431. int c = 0;
  7432. char *loc;
  7433. int result = FAIL;
  7434. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7435. /**********************status**************************/
  7436. loc = strstr(payload, "status");
  7437. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7438. c = 0;
  7439. while (loc[3+strlen("status")+c] != '\"')
  7440. {
  7441. sstr[c] = loc[3+strlen("status")+c];
  7442. c++;
  7443. }
  7444. sstr[c] = '\0';
  7445. strcpy(statusStr, sstr);
  7446. /**********************data**************************/
  7447. loc = strstr(payload, "data");
  7448. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7449. c = 0;
  7450. while (loc[3+strlen("data")+c] != '\"')
  7451. {
  7452. sstr[c] = loc[3+strlen("data")+c];
  7453. c++;
  7454. }
  7455. sstr[c] = '\0';
  7456. strcpy(dataStr, sstr);
  7457. return result;
  7458. }
  7459. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7460. {
  7461. mtrace();
  7462. int result = FAIL;
  7463. char message[1000]={0};
  7464. int CompositeScheduleIndex = 0;
  7465. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7466. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7467. if(nPeriod == 0)
  7468. {
  7469. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7470. {
  7471. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7472. ,MESSAGE_TYPE_CALLRESULT
  7473. ,uuid
  7474. ,payload
  7475. ,connectorIdInt);
  7476. }
  7477. else
  7478. {
  7479. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7480. ,MESSAGE_TYPE_CALLRESULT
  7481. ,uuid
  7482. ,payload
  7483. ,connectorIdInt
  7484. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7485. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7486. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7487. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7488. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7489. }
  7490. }
  7491. else
  7492. {
  7493. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7494. ,MESSAGE_TYPE_CALLRESULT
  7495. ,uuid
  7496. ,payload
  7497. ,connectorIdInt
  7498. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7499. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7500. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7501. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7502. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7503. {
  7504. if (idx_sample == 0)
  7505. {
  7506. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7507. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7508. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7509. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7510. }
  7511. else
  7512. {
  7513. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7514. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7515. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7516. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7517. }
  7518. }
  7519. sprintf(message + strlen(message), "]}}]");
  7520. }
  7521. LWS_Send(message);
  7522. result = TRUE;
  7523. return result;
  7524. }
  7525. int sendGetConfigurationConfirmation(char *uuid)
  7526. {
  7527. mtrace();
  7528. int result = FAIL;
  7529. int MaxKeySupported = 0;
  7530. int sentConfigurationNumber= 0;
  7531. int sentunConfigurationNumber= 0;
  7532. char message[1024*10]={0};
  7533. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7534. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7535. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7536. ,MESSAGE_TYPE_CALLRESULT
  7537. ,uuid );
  7538. //configuration key
  7539. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7540. {
  7541. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7542. {
  7543. if (sentConfigurationNumber == 0)
  7544. {
  7545. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7546. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7547. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7548. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7549. }
  7550. else
  7551. {
  7552. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7553. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7554. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7555. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7556. }
  7557. sentConfigurationNumber = sentConfigurationNumber + 1;
  7558. }
  7559. }
  7560. sprintf(message + strlen(message), "]");
  7561. if(UnknownKeynum != 0)
  7562. {
  7563. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7564. //unkown key
  7565. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7566. {
  7567. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7568. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7569. if(sentunConfigurationNumber == 0)
  7570. {
  7571. sprintf(message + strlen(message), "\"%s\""
  7572. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7573. }
  7574. else
  7575. {
  7576. sprintf(message + strlen(message), ",\"%s\""
  7577. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7578. }
  7579. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7580. }
  7581. sprintf(message + strlen(message), "]");
  7582. }
  7583. sprintf(message + strlen(message), "}]");
  7584. LWS_Send(message);
  7585. return result;
  7586. }
  7587. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7588. {
  7589. mtrace();
  7590. int result = FAIL;
  7591. char message[400]={0};
  7592. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7593. if(strcmp(payload,"")==0)
  7594. {
  7595. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7596. }
  7597. else
  7598. {
  7599. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7600. }
  7601. LWS_Send(message);
  7602. result = TRUE;
  7603. return result;
  7604. }
  7605. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7606. {
  7607. mtrace();
  7608. int result = FAIL;
  7609. char message[80]={0};
  7610. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7611. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7612. LWS_Send(message);
  7613. result = TRUE;
  7614. return result;
  7615. }
  7616. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7617. {
  7618. mtrace();
  7619. int result = FAIL;
  7620. char message[80]={0};
  7621. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7622. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7623. LWS_Send(message);
  7624. result = TRUE;
  7625. return result;
  7626. }
  7627. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7628. {
  7629. mtrace();
  7630. int result = FAIL;
  7631. char message[80]={0};
  7632. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7633. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7634. LWS_Send(message);
  7635. result = TRUE;
  7636. return result;
  7637. }
  7638. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7639. {
  7640. mtrace();
  7641. int result = FAIL;
  7642. char message[80]={0};
  7643. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7644. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7645. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7646. LWS_Send(message);
  7647. result = TRUE;
  7648. return result;
  7649. }
  7650. int sendResetConfirmation(char *uuid,char *payload)
  7651. {
  7652. mtrace();
  7653. int result = FAIL;
  7654. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7655. char message[80]={0};
  7656. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7657. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7658. LWS_Send(message);
  7659. result = TRUE;
  7660. return result;
  7661. }
  7662. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7663. {
  7664. mtrace();
  7665. int result = FAIL;
  7666. char message[500]={0};
  7667. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7668. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7669. LWS_Send(message);
  7670. result = TRUE;
  7671. return result;
  7672. }
  7673. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7674. {
  7675. mtrace();
  7676. int result = FAIL;
  7677. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7678. char message[80]={0};
  7679. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7680. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7681. LWS_Send(message);
  7682. result = TRUE;
  7683. return result;
  7684. }
  7685. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7686. {
  7687. mtrace();
  7688. int result = FAIL;
  7689. char message[80]={0};
  7690. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7691. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7692. LWS_Send(message);
  7693. result = TRUE;
  7694. return result;
  7695. }
  7696. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7697. {
  7698. mtrace();
  7699. int result = FAIL;
  7700. char message[80]={0};
  7701. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7702. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7703. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7704. LWS_Send(message);
  7705. result = TRUE;
  7706. return result;
  7707. }
  7708. int sendUpdateFirmwareConfirmation(char *uuid)
  7709. {
  7710. mtrace();
  7711. int result = FAIL;
  7712. char message[60]={0};
  7713. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7714. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7715. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7716. LWS_Send(message);
  7717. result = TRUE;
  7718. return result;
  7719. }
  7720. int sendCertificateSignedConfirmation(char *uuid)
  7721. {
  7722. mtrace();
  7723. int result = PASS;
  7724. char message[4096]={0};
  7725. json_object *CertificateSigned = json_object_new_object();
  7726. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7727. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7728. sprintf(message,"[%d,\"%s\",%s]"
  7729. ,MESSAGE_TYPE_CALLRESULT
  7730. ,uuid
  7731. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7732. json_object_put(CertificateSigned);
  7733. LWS_Send(message);
  7734. return result;
  7735. }
  7736. int sendDeleteCertificateConfirmation(char *uuid)
  7737. {
  7738. mtrace();
  7739. int result = PASS;
  7740. char message[4096]={0};
  7741. json_object *DeleteCertificate = json_object_new_object();
  7742. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7743. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7744. sprintf(message,"[%d,\"%s\",%s]"
  7745. ,MESSAGE_TYPE_CALLRESULT
  7746. ,uuid
  7747. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7748. json_object_put(DeleteCertificate);
  7749. LWS_Send(message);
  7750. return result;
  7751. }
  7752. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7753. {
  7754. mtrace();
  7755. int result = PASS;
  7756. char message[4096]={0};
  7757. json_object *ExtendedTriggerMessage = json_object_new_object();
  7758. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7759. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7760. sprintf(message,"[%d,\"%s\",%s]"
  7761. ,MESSAGE_TYPE_CALLRESULT
  7762. ,uuid
  7763. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7764. json_object_put(ExtendedTriggerMessage);
  7765. LWS_Send(message);
  7766. return result;
  7767. }
  7768. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7769. {
  7770. mtrace();
  7771. int result = PASS;
  7772. char message[4096]={0};
  7773. json_object *GetInstalledCertificateIds = json_object_new_object();
  7774. json_object *certificateHashDataDatas = json_object_new_array();
  7775. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7776. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7777. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7778. {
  7779. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7780. {
  7781. json_object *certificateHashData = json_object_new_object();
  7782. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7783. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7784. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7785. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7786. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7787. }
  7788. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7789. }
  7790. else
  7791. {
  7792. json_object_put(certificateHashDataDatas);
  7793. }
  7794. sprintf(message,"[%d,\"%s\",%s]"
  7795. ,MESSAGE_TYPE_CALLRESULT
  7796. ,uuid
  7797. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7798. json_object_put(GetInstalledCertificateIds);
  7799. LWS_Send(message);
  7800. return result;
  7801. }
  7802. int sendGetLogConfirmation(char *uuid)
  7803. {
  7804. mtrace();
  7805. int result = PASS;
  7806. char message[4096]={0};
  7807. json_object *GetLog = json_object_new_object();
  7808. DEBUG_INFO("sendGetLogConfirmation...\n");
  7809. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7810. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7811. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7812. sprintf(message,"[%d,\"%s\",%s]"
  7813. ,MESSAGE_TYPE_CALLRESULT
  7814. ,uuid
  7815. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7816. json_object_put(GetLog);
  7817. LWS_Send(message);
  7818. return result;
  7819. }
  7820. int sendInstallCertificateConfirmation(char *uuid)
  7821. {
  7822. mtrace();
  7823. int result = PASS;
  7824. char message[4096]={0};
  7825. json_object *InstallCertificate = json_object_new_object();
  7826. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7827. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7828. sprintf(message,"[%d,\"%s\",%s]"
  7829. ,MESSAGE_TYPE_CALLRESULT
  7830. ,uuid
  7831. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7832. json_object_put(InstallCertificate);
  7833. LWS_Send(message);
  7834. return result;
  7835. }
  7836. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7837. {
  7838. mtrace();
  7839. int result = PASS;
  7840. char message[4096]={0};
  7841. json_object *SignedUpdateFirmware = json_object_new_object();
  7842. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7843. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7844. sprintf(message,"[%d,\"%s\",%s]"
  7845. ,MESSAGE_TYPE_CALLRESULT
  7846. ,uuid
  7847. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7848. json_object_put(SignedUpdateFirmware);
  7849. LWS_Send(message);
  7850. return result;
  7851. }
  7852. int sendUnknownConfirmation(char *uuid)
  7853. {
  7854. mtrace();
  7855. int result = PASS;
  7856. char message[256]={0};
  7857. DEBUG_INFO("sendUnknownConfirmation...\n");
  7858. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7859. LWS_Send(message);
  7860. return result;
  7861. }
  7862. //==========================================
  7863. // Handle server request routine Start
  7864. //==========================================
  7865. int handleCancelReservationRequest(char *uuid, char *payload)
  7866. {
  7867. mtrace();
  7868. int result = FAIL;
  7869. int gunNO = 0;
  7870. int reservationIdInt = -1;
  7871. char comfirmstr[20];
  7872. DEBUG_INFO("handleCancelReservationRequest...\n");
  7873. json_object *CancelReservation;
  7874. CancelReservation = json_tokener_parse(payload);
  7875. if(!is_error(CancelReservation))
  7876. {
  7877. // Required data
  7878. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7879. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7880. }
  7881. json_object_put(CancelReservation);
  7882. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7883. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7884. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7885. if(reservationIdInt != -1)
  7886. {
  7887. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7888. //check Transaction active
  7889. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7891. {
  7892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7893. {
  7894. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7895. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7896. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7897. {
  7898. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7899. }
  7900. else
  7901. {
  7902. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7903. }
  7904. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7905. goto end;
  7906. }
  7907. }
  7908. for (int index = 0; index < CCS_QUANTITY; index++)
  7909. {
  7910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7911. {
  7912. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7913. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7914. if(gunType[2] == GUN_TYPE_CCS)
  7915. {
  7916. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7917. }
  7918. else
  7919. {
  7920. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7921. }
  7922. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7923. goto end;
  7924. }
  7925. }
  7926. for (int index = 0; index < GB_QUANTITY; index++)
  7927. {
  7928. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7929. {
  7930. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7931. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7932. if(gunType[2] == GUN_TYPE_GBT)
  7933. {
  7934. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7935. }
  7936. else
  7937. {
  7938. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7939. }
  7940. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7941. goto end;
  7942. }
  7943. }
  7944. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7945. {
  7946. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7947. {
  7948. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7949. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7950. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7951. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7952. goto end;
  7953. }
  7954. }
  7955. for (int index = 0; index < AC_QUANTITY; index++)
  7956. {
  7957. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7958. {
  7959. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7960. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7961. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7962. {
  7963. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7964. }
  7965. else
  7966. {
  7967. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7968. }
  7969. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7970. goto end;
  7971. }
  7972. }
  7973. }
  7974. //The reservationId does NOT match the reservationId
  7975. sendCancelReservationConfirmation(uuid, comfirmstr);
  7976. end:
  7977. // Fill in ocpp packet uuid
  7978. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7979. return result;
  7980. }
  7981. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7982. {
  7983. mtrace();
  7984. int result = FAIL;
  7985. int gunIndex = -1;
  7986. char typeStr[16]={0};
  7987. char comfirmstr[20];
  7988. int specificId = FALSE;
  7989. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7990. json_object *ChangeAvailability;
  7991. ChangeAvailability = json_tokener_parse(payload);
  7992. if(!is_error(ChangeAvailability))
  7993. {
  7994. // Required data
  7995. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7996. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7997. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7998. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7999. }
  8000. json_object_put(ChangeAvailability);
  8001. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8002. {
  8003. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8004. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8005. }
  8006. else if(gunIndex == 0)
  8007. {
  8008. for(int i=0; i < gunTotalNumber; i++)
  8009. {
  8010. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8011. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8012. }
  8013. }
  8014. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8015. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8016. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8017. {
  8018. specificId = TRUE;
  8019. }
  8020. if(specificId == FALSE)
  8021. goto end;
  8022. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8023. {
  8024. //----------------------gunIndex is 0 ------------------------------------------------//
  8025. if(gunIndex == 0)
  8026. {
  8027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8028. {
  8029. for(int i=0; i < gunTotalNumber; i++)
  8030. {
  8031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8032. {
  8033. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8034. {
  8035. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8036. {
  8037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8038. goto end;
  8039. }
  8040. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8041. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8042. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8043. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8044. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8045. {
  8046. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8047. goto end;
  8048. }
  8049. }
  8050. }//END FOR CHAdeMO_QUANTITY
  8051. for (int index = 0; index < CCS_QUANTITY; index++)
  8052. {
  8053. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8054. {
  8055. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8056. {
  8057. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8058. goto end;
  8059. }
  8060. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8061. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8062. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8063. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8064. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8065. {
  8066. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8067. goto end;
  8068. }
  8069. }
  8070. }//END FOR CCS_QUANTITY
  8071. for (int index = 0; index < GB_QUANTITY; index++)
  8072. {
  8073. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8074. {
  8075. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8076. {
  8077. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8078. goto end;
  8079. }
  8080. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8081. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8082. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8083. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8084. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8085. {
  8086. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8087. goto end;
  8088. }
  8089. }
  8090. }// END FOR GB_QUANTITY
  8091. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8092. {
  8093. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8094. {
  8095. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8096. {
  8097. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8098. goto end;
  8099. }
  8100. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8101. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8102. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8103. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8104. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8105. {
  8106. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8107. goto end;
  8108. }
  8109. }
  8110. }// END FOR GENERAL_GUN_QUANTITY
  8111. for (int index = 0; index < AC_QUANTITY; index++)
  8112. {
  8113. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8114. {
  8115. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8116. {
  8117. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8118. goto end;
  8119. }
  8120. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8121. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8122. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8123. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8124. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8125. {
  8126. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8127. goto end;
  8128. }
  8129. }
  8130. }//END FOR AC_QUANTITY
  8131. }// END FOR gunTotalNumber
  8132. }
  8133. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8134. {
  8135. for(int i=0; i < gunTotalNumber; i++)
  8136. {
  8137. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8138. {
  8139. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8140. goto end;
  8141. }
  8142. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8143. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8144. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8145. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8146. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8147. {
  8148. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8149. goto end;
  8150. }
  8151. }
  8152. }
  8153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8154. goto end;
  8155. }
  8156. //----------------------gunIndex is not 0 ------------------------------------------------//
  8157. //check Transaction active
  8158. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8159. {
  8160. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8161. {
  8162. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8163. {
  8164. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8165. goto end;
  8166. }
  8167. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8168. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8169. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8170. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8171. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8172. {
  8173. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8174. goto end;
  8175. }
  8176. else
  8177. {
  8178. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8179. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8180. goto end;
  8181. }
  8182. }
  8183. }//END FOR CHAdeMO_QUANTITY
  8184. for (int index = 0; index < CCS_QUANTITY; index++)
  8185. {
  8186. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8187. {
  8188. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8189. {
  8190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8191. goto end;
  8192. }
  8193. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8194. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8195. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8196. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8197. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8198. {
  8199. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8200. goto end;
  8201. }
  8202. else
  8203. {
  8204. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8205. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8206. goto end;
  8207. }
  8208. }
  8209. }//END FOR CCS_QUANTITY
  8210. for (int index = 0; index < GB_QUANTITY; index++)
  8211. {
  8212. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8213. {
  8214. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8215. {
  8216. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8217. goto end;
  8218. }
  8219. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8220. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8221. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8222. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8223. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8224. {
  8225. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8226. goto end;
  8227. }
  8228. else
  8229. {
  8230. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8231. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8232. goto end;
  8233. }
  8234. }
  8235. }// END FOR GB_QUANTITY
  8236. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8237. {
  8238. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8239. {
  8240. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8241. {
  8242. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8243. goto end;
  8244. }
  8245. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8246. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8247. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8248. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8249. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8250. {
  8251. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8252. goto end;
  8253. }
  8254. else
  8255. {
  8256. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8257. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8258. goto end;
  8259. }
  8260. }
  8261. }// END FOR GENERAL_GUN_QUANTITY
  8262. for (int index = 0; index < AC_QUANTITY; index++)
  8263. {
  8264. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8265. {
  8266. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8267. {
  8268. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8269. goto end;
  8270. }
  8271. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8272. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8273. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8274. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8275. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8276. {
  8277. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8278. goto end;
  8279. }
  8280. else
  8281. {
  8282. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8283. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8284. goto end;
  8285. }
  8286. }
  8287. }//END FOR AC_QUANTITY
  8288. }//END FOR AvailabilityTypeStr[Inoperative]
  8289. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8290. {
  8291. //----------------------gunIndex is 0 ------------------------------------------------//
  8292. if(gunIndex == 0)
  8293. {
  8294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8295. {
  8296. for(int i=0; i < gunTotalNumber; i++)
  8297. {
  8298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8299. {
  8300. 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
  8301. {
  8302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8303. goto end;
  8304. }
  8305. }//END FOR CHAdeMO_QUANTITY
  8306. for (int index = 0; index < CCS_QUANTITY; index++)
  8307. {
  8308. 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
  8309. {
  8310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8311. goto end;
  8312. }
  8313. }//END FOR CCS_QUANTITY
  8314. for (int index = 0; index < GB_QUANTITY; index++)
  8315. {
  8316. 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
  8317. {
  8318. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8320. goto end;
  8321. }
  8322. }// END FOR GB_QUANTITY
  8323. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8324. {
  8325. 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
  8326. {
  8327. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8329. goto end;
  8330. }
  8331. }// END FOR GENERAL_GUN_QUANTITY
  8332. for (int index = 0; index < AC_QUANTITY; index++)
  8333. {
  8334. 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
  8335. {
  8336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8337. goto end;
  8338. }
  8339. }//END FOR CHAdeMO_QUANTITY
  8340. }// END FOR gunTotalNumber
  8341. }
  8342. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8343. {
  8344. for(int i=0; i < gunTotalNumber; i++)
  8345. {
  8346. for (int index = 0; index < AC_QUANTITY; index++)
  8347. {
  8348. 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
  8349. {
  8350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8351. goto end;
  8352. }
  8353. }//END FOR CHAdeMO_QUANTITY
  8354. } // END FOR gunTotalNumber
  8355. }
  8356. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8357. goto end;
  8358. }
  8359. //----------------------gunIndex is not 0 ------------------------------------------------//
  8360. //check Transaction active
  8361. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8362. {
  8363. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8364. {
  8365. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8366. goto end;
  8367. }
  8368. }//END FOR CHAdeMO_QUANTITY
  8369. for (int index = 0; index < CCS_QUANTITY; index++)
  8370. {
  8371. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8372. {
  8373. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8374. goto end;
  8375. }
  8376. }//END FOR CCS_QUANTITY
  8377. for (int index = 0; index < GB_QUANTITY; index++)
  8378. {
  8379. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8380. {
  8381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8382. goto end;
  8383. }
  8384. }// END FOR GB_QUANTITY
  8385. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8386. {
  8387. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8388. {
  8389. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8390. goto end;
  8391. }
  8392. }// END FOR GENERAL_GUN_QUANTITY
  8393. for (int index = 0; index < AC_QUANTITY; index++)
  8394. {
  8395. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8396. {
  8397. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8398. goto end;
  8399. }
  8400. }//END FOR AC_QUANTITY
  8401. }//END FOR AvailabilityTypeStr[Operative]
  8402. end:
  8403. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8404. {
  8405. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8406. }
  8407. else
  8408. {
  8409. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8410. }
  8411. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8412. {
  8413. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8414. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8415. }
  8416. else if(gunIndex == 0)
  8417. {
  8418. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8419. {
  8420. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8421. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8422. }
  8423. }
  8424. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8425. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8426. return result;
  8427. }
  8428. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8429. {
  8430. mtrace();
  8431. int valueInvalid = NO;
  8432. int result = FAIL;
  8433. char keystr[40]={0};
  8434. char valuestr[501]={0}; //value should be limited in 500 bytes
  8435. char comfirmstr[20]={0};
  8436. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8437. json_object *ChangeConfiguration;
  8438. ChangeConfiguration = json_tokener_parse(payload);
  8439. if(!is_error(ChangeConfiguration))
  8440. {
  8441. // Required data
  8442. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8443. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8444. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8445. {
  8446. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8447. }
  8448. else
  8449. {
  8450. valueInvalid = YES;
  8451. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8452. }
  8453. }
  8454. json_object_put(ChangeConfiguration);
  8455. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8456. {
  8457. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8458. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8459. }
  8460. else
  8461. {
  8462. int status = setKeyValue(keystr, valuestr);
  8463. switch(status)
  8464. {
  8465. case ConfigurationStatus_Accepted:
  8466. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8467. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8468. StoreConfigurationTable();
  8469. break;
  8470. case RebootRequired:
  8471. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8472. StoreConfigurationTable();
  8473. break;
  8474. case NotSupported:
  8475. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8476. break;
  8477. case ConfigurationStatus_Rejected:
  8478. default:
  8479. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8480. break;
  8481. }
  8482. }
  8483. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8484. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8485. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8486. {
  8487. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8488. SetOcppConnStatus(FALSE);
  8489. }
  8490. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8491. {
  8492. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8493. }
  8494. return result;
  8495. }
  8496. int handleClearCacheRequest(char *uuid, char *payload)
  8497. {
  8498. mtrace();
  8499. int result = FAIL;
  8500. char comfirmstr[20];
  8501. char rmFileCmd[100]={0};
  8502. struct stat stats;
  8503. DEBUG_INFO("handleClearCacheRequest...\n");
  8504. stat("/Storage/OCPP", &stats);
  8505. // Check for directory existence
  8506. if (S_ISDIR(stats.st_mode) == 1)
  8507. {}
  8508. else
  8509. {
  8510. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8511. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8512. system(rmFileCmd);
  8513. }
  8514. if(OCPP_cleanLocalCache())
  8515. {
  8516. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8517. }
  8518. else
  8519. {
  8520. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8521. }
  8522. sendClearCacheConfirmation(uuid, comfirmstr);
  8523. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8524. return result;
  8525. }
  8526. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8527. {
  8528. mtrace();
  8529. int result = FAIL;
  8530. int resultRename;
  8531. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8532. char chargingProfilePurposeStr[26]={0};
  8533. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8534. char tempchargingProfilePurposeStr[26]={0};
  8535. char str[100]={0};
  8536. char fname[200]={0};
  8537. char comfirmstr[20]={0};
  8538. char word[1600]={0};
  8539. int clearflag = FALSE;
  8540. int chargingProfileIdIsNULL = FALSE;
  8541. int connectorIsNULL = FALSE;
  8542. int chargingProfilePurposeIsNULL = FALSE;
  8543. int stackLevelIsNULL = FALSE;
  8544. //int GotoEnd = FALSE;
  8545. FILE *fptr1, *fptr2;
  8546. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8547. int n_chargingProfile=0;
  8548. int isEmptyFile = FALSE;
  8549. char sLineWord[1600]={0};
  8550. char chargingProfiles[10][100]={0};
  8551. int ChargeProfileCount = 0;
  8552. int ch;
  8553. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8554. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8555. json_object *ClearChargingProfile;
  8556. ClearChargingProfile = json_tokener_parse(payload);
  8557. if(!is_error(ClearChargingProfile))
  8558. {
  8559. // Optional data
  8560. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8561. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8562. else
  8563. chargingProfileIdIsNULL = TRUE;
  8564. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8565. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8566. else
  8567. connectorIsNULL = TRUE;
  8568. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8569. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8570. else
  8571. chargingProfilePurposeIsNULL = TRUE;
  8572. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8573. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8574. else
  8575. stackLevelIsNULL = TRUE;
  8576. }
  8577. json_object_put(ClearChargingProfile);
  8578. if(connectorIsNULL == FALSE)
  8579. {
  8580. switch(connectorIdInt)
  8581. {
  8582. case 0:
  8583. if(chargingProfilePurposeIsNULL == TRUE)
  8584. {
  8585. int l = 0;
  8586. strcpy(fname, ChargePointMaxProfile_JSON);
  8587. if((access(fname,F_OK))!=-1)
  8588. {
  8589. strcpy(chargingProfiles[l], fname);
  8590. l = l + 1;
  8591. }
  8592. strcpy(fname, TxDefaultProfile_0_JSON);
  8593. if((access(fname,F_OK))!=-1)
  8594. {
  8595. strcpy(chargingProfiles[l], fname);
  8596. l = l + 1;
  8597. }
  8598. ChargeProfileCount = l;
  8599. }
  8600. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8601. {
  8602. strcpy(fname, ChargePointMaxProfile_JSON);
  8603. if((access(fname,F_OK))!=-1)
  8604. {
  8605. strcpy(chargingProfiles[0], fname);
  8606. ChargeProfileCount = 1;
  8607. }
  8608. }
  8609. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8610. {
  8611. strcpy(fname, TxDefaultProfile_0_JSON);
  8612. if((access(fname,F_OK))!=-1)
  8613. {
  8614. strcpy(chargingProfiles[0], fname);
  8615. ChargeProfileCount = 1;
  8616. }
  8617. }
  8618. break;
  8619. default:
  8620. if(chargingProfilePurposeIsNULL == TRUE)
  8621. {
  8622. int m = 0;
  8623. memset(fname, 0, ARRAY_SIZE(fname));
  8624. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8625. if((access(fname,F_OK))!=-1)
  8626. {
  8627. strcpy(chargingProfiles[m], fname);
  8628. m = m + 1;
  8629. }
  8630. memset(fname, 0, ARRAY_SIZE(fname));
  8631. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8632. if((access(fname,F_OK))!=-1)
  8633. {
  8634. strcpy(chargingProfiles[m], fname);
  8635. m = m + 1;
  8636. }
  8637. ChargeProfileCount = m;
  8638. }
  8639. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8640. {
  8641. //strcpy(fname, TxDefaultProfile_1_JSON);
  8642. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8643. if((access(fname,F_OK))!=-1)
  8644. {
  8645. strcpy(chargingProfiles[0], fname);
  8646. ChargeProfileCount = 1;
  8647. }
  8648. }
  8649. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8650. {
  8651. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8652. if((access(fname,F_OK))!=-1)
  8653. {
  8654. strcpy(chargingProfiles[0], fname);
  8655. ChargeProfileCount = 1;
  8656. }
  8657. //strcpy(fname, TxProfile_1_JSON);
  8658. }
  8659. //strcpy(fname, ChargePointMaxProfile_JSON );
  8660. break;
  8661. }
  8662. }
  8663. else // Check all Charging Profiles
  8664. {
  8665. int i = 0;
  8666. char fnametemp[200]={0};
  8667. ChargeProfileCount = 0;
  8668. //Check ChargePointMaxProfile.json exit
  8669. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8670. {
  8671. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8672. i = i + 1;
  8673. }
  8674. //Check TxDefaultProfile_0.json exit
  8675. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8676. {
  8677. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8678. i = i + 1;
  8679. }
  8680. //Check TxDefaultProfile_%d.json
  8681. for(int j=1; j <= gunTotalNumber; j++)
  8682. {
  8683. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8684. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8685. if((access(fnametemp,F_OK))!=-1)
  8686. {
  8687. strcpy(chargingProfiles[i], fnametemp);
  8688. i = i + 1;
  8689. }
  8690. }
  8691. //Check TxProfile_%d.json
  8692. for(int j=1; j <= gunTotalNumber; j++)
  8693. {
  8694. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8695. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8696. if((access(fnametemp,F_OK))!=-1)
  8697. {
  8698. strcpy(chargingProfiles[i], fnametemp);
  8699. i = i + 1;
  8700. }
  8701. }
  8702. ChargeProfileCount = i;
  8703. }// End connectorIsNULL is TRUE
  8704. if(ChargeProfileCount == 0)
  8705. {
  8706. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8707. goto end;
  8708. }
  8709. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8710. {
  8711. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8712. goto end;
  8713. }
  8714. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8715. {
  8716. memset(str, 0, ARRAY_SIZE(str));
  8717. // clear temp file
  8718. sprintf(str,"rm -f %s",temp);
  8719. system(str);
  8720. for(int k=0; k < ChargeProfileCount; k++)
  8721. {
  8722. memset(str, 0, ARRAY_SIZE(str));
  8723. //clear file in C
  8724. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8725. system(str);
  8726. }
  8727. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8728. goto end;
  8729. }
  8730. else if(connectorIsNULL == TRUE)
  8731. {
  8732. for(int k=0; k < ChargeProfileCount; k++)
  8733. {
  8734. fptr1 = fopen(chargingProfiles[k], "r");
  8735. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8736. //Check Charging Profile Count
  8737. while(fscanf(fptr1, "%s", word) != EOF)
  8738. {
  8739. //DEBUG_INFO("word=%s\n",word);
  8740. if(strstr(word, "chargingProfileId")!= NULL)
  8741. {
  8742. //DEBUG_INFO("test chargingProfileId \n");
  8743. n_chargingProfile = n_chargingProfile + 1;
  8744. //DEBUG_INFO("chargingProfileId Found\n");
  8745. }
  8746. }
  8747. rewind(fptr1);
  8748. //search Charging Profile Element
  8749. //int i= 0;
  8750. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8751. {
  8752. json_object *tmpProfilee;
  8753. tmpProfilee = json_tokener_parse(sLineWord);
  8754. if(!is_error(tmpProfilee))
  8755. {
  8756. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8757. {
  8758. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8759. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8760. }
  8761. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8762. {
  8763. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8764. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8765. }
  8766. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8767. {
  8768. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8769. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8770. }
  8771. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8772. {
  8773. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8774. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8775. }
  8776. }
  8777. json_object_put(tmpProfilee);
  8778. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8779. {
  8780. //------- not write to fptr2-------//
  8781. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8782. //clearflag = TRUE;
  8783. }
  8784. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8785. {
  8786. //------- not write to fptr2-------//
  8787. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8788. }
  8789. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8790. {
  8791. //------- not write to fptr2-------//
  8792. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8793. }
  8794. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8795. {
  8796. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8797. }
  8798. else
  8799. {
  8800. fprintf(fptr2, sLineWord);//writing data into file
  8801. }
  8802. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8803. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8804. if(clearflag == TRUE)
  8805. {
  8806. fclose(fptr1);
  8807. fclose(fptr2);
  8808. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8809. system(str);
  8810. // clear temp file
  8811. sprintf(str,"rm -f %s",temp);
  8812. system(str);
  8813. }
  8814. else
  8815. {
  8816. fclose(fptr1);
  8817. fclose(fptr2);
  8818. memset(str, 0, ARRAY_SIZE(str));
  8819. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8820. system(str);
  8821. resultRename = rename(temp, chargingProfiles[k]);
  8822. if(resultRename == 0)
  8823. {
  8824. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8825. }
  8826. else
  8827. {
  8828. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8829. }
  8830. if(comfirmstr[0]== 0)
  8831. {
  8832. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8833. }
  8834. //Check chargingProfile is empty file
  8835. /*------ Read the file ----------------*/
  8836. fptr1=fopen(chargingProfiles[k],"r");
  8837. ch=fgetc(fptr1);
  8838. rewind(fptr1);
  8839. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8840. if(ch!=EOF)
  8841. {
  8842. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8843. {
  8844. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8845. if(sLineWord[0]=='\0')
  8846. {
  8847. isEmptyFile = TRUE;
  8848. break;
  8849. }
  8850. else
  8851. {
  8852. isEmptyFile = FALSE;
  8853. break;
  8854. }
  8855. }
  8856. }
  8857. else
  8858. isEmptyFile = TRUE;
  8859. fclose(fptr1);
  8860. if(isEmptyFile == TRUE)
  8861. {
  8862. memset(str, 0, ARRAY_SIZE(str));
  8863. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8864. system(str);
  8865. }
  8866. }
  8867. }// End of while(int k=0; k < ChargePointCount; k++)
  8868. }
  8869. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8870. {
  8871. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8872. for(int k=0; k < ChargeProfileCount; k++)
  8873. {
  8874. fptr1 = fopen(chargingProfiles[k], "r");
  8875. fptr2 = fopen(temp, "w+");
  8876. //Check Charging Profile Count
  8877. while(fscanf(fptr1, "%s", word) != EOF)
  8878. {
  8879. //DEBUG_INFO("word=%s\n",word);
  8880. if(strstr(word, "chargingProfileId")!= NULL)
  8881. {
  8882. n_chargingProfile = n_chargingProfile + 1;
  8883. }
  8884. }
  8885. rewind(fptr1);
  8886. //search Charging Profile Element
  8887. //int i= 0;
  8888. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8889. {
  8890. json_object *tmpProfilee;
  8891. tmpProfilee = json_tokener_parse(sLineWord);
  8892. if(!is_error(tmpProfilee))
  8893. {
  8894. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8895. {
  8896. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8897. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8898. }
  8899. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8900. {
  8901. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8902. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8903. }
  8904. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8905. {
  8906. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8907. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8908. }
  8909. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8910. {
  8911. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8912. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8913. }
  8914. }
  8915. json_object_put(tmpProfilee);
  8916. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8917. {
  8918. //------- not write to fptr2-------//
  8919. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8920. //clearflag = TRUE;
  8921. }
  8922. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8923. {
  8924. //------- not write to fptr2-------//
  8925. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8926. }
  8927. else if(stackLevelIsNULL == TRUE)
  8928. {
  8929. //Clear Whole File
  8930. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8931. clearflag = TRUE;
  8932. break;
  8933. }
  8934. else
  8935. {
  8936. fprintf(fptr2, sLineWord);//writing data into file
  8937. }
  8938. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8939. }
  8940. if(clearflag == TRUE)
  8941. {
  8942. fclose(fptr1);
  8943. fclose(fptr2);
  8944. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8945. system(str);
  8946. // clear temp file
  8947. sprintf(str,"rm -f %s",temp);
  8948. system(str);
  8949. }
  8950. else
  8951. {
  8952. fclose(fptr1);
  8953. fclose(fptr2);
  8954. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8955. system(str);
  8956. resultRename = rename(temp, chargingProfiles[k]);
  8957. if(resultRename == 0)
  8958. {
  8959. DEBUG_INFO("File ChargingProfile renamed successfully");
  8960. }
  8961. else
  8962. {
  8963. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8964. }
  8965. if(comfirmstr[0]== 0)
  8966. {
  8967. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8968. }
  8969. //Check chargingProfile is empty file
  8970. /*------ Read the file ----------------*/
  8971. fptr1=fopen(chargingProfiles[k],"r");
  8972. ch=fgetc(fptr1);
  8973. rewind(fptr1);
  8974. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8975. if(ch!=EOF)
  8976. {
  8977. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8978. {
  8979. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8980. if(sLineWord[0]=='\0')
  8981. {
  8982. isEmptyFile = TRUE;
  8983. break;
  8984. }
  8985. else
  8986. {
  8987. isEmptyFile = FALSE;
  8988. break;
  8989. }
  8990. }
  8991. }
  8992. else
  8993. isEmptyFile = TRUE;
  8994. fclose(fptr1);
  8995. if(isEmptyFile == TRUE)
  8996. {
  8997. memset(str, 0, ARRAY_SIZE(str));
  8998. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8999. system(str);
  9000. }
  9001. /*------- End of reading ---------------*/
  9002. }
  9003. } // while(int k=0; k < ChargeProfileCount; k++)
  9004. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9005. end:
  9006. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9007. {
  9008. if(connectorIdInt == 0)
  9009. {
  9010. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9011. {
  9012. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9013. }
  9014. }
  9015. else
  9016. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9017. }
  9018. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9019. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9020. return result;
  9021. }
  9022. void createFirmwareVersionByDataTransfer(void)
  9023. {
  9024. json_object *FirmwareDataTransfer = json_object_new_object();
  9025. // AC & DC model
  9026. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9027. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9028. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9029. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9030. // DC model
  9031. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9032. {
  9033. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9034. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9035. (gunType[3] != GUN_TYPE_UNKNOWN))
  9036. {
  9037. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9038. }
  9039. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9040. {
  9041. // DS DM DW
  9042. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9043. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9044. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9045. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9046. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9047. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9048. }
  9049. else
  9050. {
  9051. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9052. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9053. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9054. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9055. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9056. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9057. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9058. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9059. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9060. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9061. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9062. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9063. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9064. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9065. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9066. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9067. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9068. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9069. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9070. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9071. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9072. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9073. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9074. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9075. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9076. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9077. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9078. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9079. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9080. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9081. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9082. }
  9083. }
  9084. // 4G model
  9085. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9086. {
  9087. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9088. }
  9089. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9090. json_object_put(FirmwareDataTransfer);
  9091. }
  9092. int handleDataTransferRequest(char *uuid, char *payload)
  9093. {
  9094. mtrace();
  9095. json_object *response = json_object_new_object();
  9096. int result = FAIL;
  9097. char tempvendorId[255]={0};
  9098. char tempmessageId[50]={0};
  9099. char tempdata[512]={0};
  9100. char message[2048]={0};
  9101. DEBUG_INFO("handleDataTransferRequest...\n");
  9102. if((uuid != NULL) && (payload != NULL))
  9103. {
  9104. json_object *DataTransfer;
  9105. DataTransfer = json_tokener_parse(payload);
  9106. if(!is_error(DataTransfer))
  9107. {
  9108. // Required data
  9109. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9110. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9111. // Optional data
  9112. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9113. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9114. if(json_object_object_get(DataTransfer, "data") != NULL)
  9115. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9116. result = PASS;
  9117. }
  9118. json_object_put(DataTransfer);
  9119. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9120. {
  9121. // Send all moudle firmware version on EVSE
  9122. createFirmwareVersionByDataTransfer();
  9123. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9124. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9125. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9126. json_object_put(response);
  9127. }
  9128. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9129. {
  9130. system("/usr/bin/run_tmate_restart.sh &");
  9131. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9132. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9133. json_object_put(response);
  9134. }
  9135. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9136. {
  9137. json_object *data;
  9138. data = json_tokener_parse(tempdata);
  9139. if(!is_error(data))
  9140. {
  9141. 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))
  9142. {
  9143. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9144. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9145. if(json_object_object_get(data, "SOC") != NULL)
  9146. {
  9147. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9148. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9149. }
  9150. if(json_object_object_get(data, "Energy") != NULL)
  9151. {
  9152. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9153. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9154. }
  9155. if(json_object_object_get(data, "Duration") != NULL)
  9156. {
  9157. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9158. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9159. }
  9160. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9161. }
  9162. else
  9163. {
  9164. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9165. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9166. }
  9167. }
  9168. else
  9169. {
  9170. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9171. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9172. }
  9173. json_object_put(data);
  9174. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9175. json_object_put(response);
  9176. }
  9177. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9178. {
  9179. json_object *data;
  9180. data = json_tokener_parse(tempdata);
  9181. if(!is_error(data))
  9182. {
  9183. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9184. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9185. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9186. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9187. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9188. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9189. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9190. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9191. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9192. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9193. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9194. }
  9195. else
  9196. {
  9197. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9198. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9199. }
  9200. json_object_put(data);
  9201. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9202. json_object_put(response);
  9203. }
  9204. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9205. {
  9206. json_object *data;
  9207. data = json_tokener_parse(tempdata);
  9208. if(!is_error(data))
  9209. {
  9210. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9211. if(json_object_object_get(data, "idToken") != NULL)
  9212. {
  9213. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9214. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9215. }
  9216. if(json_object_object_get(data, "price") != NULL)
  9217. {
  9218. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9219. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9220. }
  9221. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9222. }
  9223. else
  9224. {
  9225. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9226. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9227. }
  9228. json_object_put(data);
  9229. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9230. json_object_put(response);
  9231. }
  9232. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9233. {
  9234. json_object *data;
  9235. data = json_tokener_parse(tempdata);
  9236. if(!is_error(data))
  9237. {
  9238. if(json_object_object_get(data, "txId") != NULL)
  9239. {
  9240. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9241. for(int idx = 0;idx<gunTotalNumber;idx++)
  9242. {
  9243. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9244. {
  9245. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9246. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9247. if(json_object_object_get(data, "description") != NULL)
  9248. {
  9249. // California pricing V1.0
  9250. DEBUG_INFO("California pricing V1.0\n");
  9251. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9252. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9253. }
  9254. else
  9255. {
  9256. // California pricing V1.1
  9257. DEBUG_INFO("California pricing V1.1\n");
  9258. if(json_object_object_get(data, "timestamp") != NULL)
  9259. {
  9260. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9261. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9262. }
  9263. if(json_object_object_get(data, "meterValue") != NULL)
  9264. {
  9265. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9266. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9267. }
  9268. if(json_object_object_get(data, "cost") != NULL)
  9269. {
  9270. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9271. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9272. }
  9273. if(json_object_object_get(data, "state") != NULL)
  9274. {
  9275. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9276. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9277. }
  9278. if(json_object_object_get(data, "chargingPrice") != NULL)
  9279. {
  9280. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9281. {
  9282. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9283. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9284. }
  9285. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9286. {
  9287. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9288. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9289. }
  9290. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9291. {
  9292. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9293. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9294. }
  9295. }
  9296. if(json_object_object_get(data, "idlePrice") != NULL)
  9297. {
  9298. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9299. {
  9300. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9301. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9302. }
  9303. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9304. {
  9305. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9306. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9307. }
  9308. }
  9309. if(json_object_object_get(data, "nextPeriod") != NULL)
  9310. {
  9311. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9312. {
  9313. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9314. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9315. }
  9316. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9317. {
  9318. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9319. {
  9320. 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")));
  9321. 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"));
  9322. }
  9323. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9324. {
  9325. 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")));
  9326. 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"));
  9327. }
  9328. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9329. {
  9330. 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")));
  9331. 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"));
  9332. }
  9333. }
  9334. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9335. {
  9336. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9337. {
  9338. 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")));
  9339. 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"));
  9340. }
  9341. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9342. {
  9343. 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")));
  9344. 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"));
  9345. }
  9346. }
  9347. }
  9348. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9349. {
  9350. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9351. {
  9352. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9353. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9354. }
  9355. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9356. {
  9357. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9358. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9359. }
  9360. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9361. {
  9362. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9363. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9364. }
  9365. }
  9366. }
  9367. }
  9368. }
  9369. }
  9370. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9371. }
  9372. else
  9373. {
  9374. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9375. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9376. }
  9377. json_object_put(data);
  9378. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9379. json_object_put(response);
  9380. }
  9381. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9382. {
  9383. json_object *data;
  9384. data = json_tokener_parse(tempdata);
  9385. if(!is_error(data))
  9386. {
  9387. if(json_object_object_get(data, "txId") != NULL)
  9388. {
  9389. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9390. for(int idx = 0;idx<gunTotalNumber;idx++)
  9391. {
  9392. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9393. {
  9394. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9395. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9396. if(json_object_object_get(data, "description") != NULL)
  9397. {
  9398. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9399. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9400. }
  9401. }
  9402. }
  9403. }
  9404. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9405. }
  9406. else
  9407. {
  9408. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9409. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9410. }
  9411. json_object_put(data);
  9412. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9413. json_object_put(response);
  9414. }
  9415. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9416. {
  9417. json_object *data;
  9418. data = json_tokener_parse(tempdata);
  9419. if(!is_error(data))
  9420. {
  9421. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9422. if(json_object_object_get(data, "Content_Type") != NULL)
  9423. {
  9424. 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))
  9425. {
  9426. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9427. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9428. {
  9429. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9430. }
  9431. }
  9432. else
  9433. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9434. }
  9435. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9436. }
  9437. else
  9438. {
  9439. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9440. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9441. }
  9442. json_object_put(data);
  9443. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9444. json_object_put(response);
  9445. }
  9446. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9447. {
  9448. json_object *data;
  9449. data = json_tokener_parse(tempdata);
  9450. if(!is_error(data))
  9451. {
  9452. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9453. if(json_object_object_get(data, "ConnectorId") != NULL)
  9454. {
  9455. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9456. }
  9457. if(json_object_object_get(data, "SerialNo") != NULL)
  9458. {
  9459. sprintf((char *)ShmOCPP16Data->TcciCustomData.LineStatusPage.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9460. }
  9461. if(json_object_object_get(data, "Page_Index") != NULL)
  9462. {
  9463. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9464. }
  9465. if(json_object_object_get(data, "Duration") != NULL)
  9466. {
  9467. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9468. }
  9469. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9470. }
  9471. else
  9472. {
  9473. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9474. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9475. }
  9476. json_object_put(data);
  9477. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9478. json_object_put(response);
  9479. }
  9480. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9481. {
  9482. json_object *data;
  9483. data = json_tokener_parse(tempdata);
  9484. if(!is_error(data))
  9485. {
  9486. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9487. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9488. {
  9489. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9490. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9491. else
  9492. {
  9493. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9494. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9495. }
  9496. }
  9497. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9498. {
  9499. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9500. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9501. else
  9502. {
  9503. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9504. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9505. }
  9506. }
  9507. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9508. {
  9509. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9510. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9511. else
  9512. {
  9513. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9514. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9515. }
  9516. }
  9517. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9518. {
  9519. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9520. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9521. else
  9522. {
  9523. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9524. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9525. }
  9526. }
  9527. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9528. {
  9529. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9530. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9531. else
  9532. {
  9533. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9534. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9535. }
  9536. }
  9537. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9538. {
  9539. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9540. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9541. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9542. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9543. else
  9544. {
  9545. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9546. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9547. }
  9548. }
  9549. if(json_object_object_get(data, "isAuthentication") != NULL)
  9550. {
  9551. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9552. {
  9553. case 0:
  9554. case 1:
  9555. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9556. break;
  9557. default:
  9558. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9559. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9560. break;
  9561. }
  9562. }
  9563. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9564. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9565. }
  9566. else
  9567. {
  9568. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9569. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9570. }
  9571. json_object_put(data);
  9572. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9573. json_object_put(response);
  9574. }
  9575. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9576. {
  9577. json_object *data;
  9578. data = json_tokener_parse(tempdata);
  9579. if(!is_error(data))
  9580. {
  9581. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9582. {
  9583. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9584. {
  9585. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9586. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9587. }
  9588. else
  9589. {
  9590. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9591. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9592. }
  9593. }
  9594. else
  9595. {
  9596. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9597. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9598. }
  9599. }
  9600. else
  9601. {
  9602. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9603. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9604. }
  9605. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9606. json_object_put(response);
  9607. }
  9608. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9609. {
  9610. json_object *data;
  9611. data = json_tokener_parse(tempdata);
  9612. if(!is_error(data))
  9613. {
  9614. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9615. if(json_object_object_get(data, "stationName") != NULL)
  9616. {
  9617. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9618. }
  9619. else
  9620. {
  9621. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9622. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9623. }
  9624. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9625. {
  9626. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9627. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9628. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9629. }
  9630. }
  9631. else
  9632. {
  9633. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9634. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9635. }
  9636. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9637. json_object_put(response);
  9638. }
  9639. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9640. {
  9641. json_object *data;
  9642. data = json_tokener_parse(tempdata);
  9643. if(!is_error(data))
  9644. {
  9645. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9646. if(json_object_object_get(data, "weatherId") != NULL)
  9647. {
  9648. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9649. }
  9650. else
  9651. {
  9652. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9653. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9654. }
  9655. if(json_object_object_get(data, "Temperature") != NULL)
  9656. {
  9657. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9658. }
  9659. else
  9660. {
  9661. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9662. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9663. }
  9664. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9665. {
  9666. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9667. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9668. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9669. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9670. );
  9671. }
  9672. }
  9673. else
  9674. {
  9675. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9676. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9677. }
  9678. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9679. json_object_put(response);
  9680. }
  9681. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9682. {
  9683. json_object *data;
  9684. data = json_tokener_parse(tempdata);
  9685. if(!is_error(data))
  9686. {
  9687. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9688. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9689. {
  9690. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9691. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9692. }
  9693. else
  9694. {
  9695. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9696. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9697. }
  9698. }
  9699. else
  9700. {
  9701. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9702. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9703. }
  9704. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9705. json_object_put(response);
  9706. }
  9707. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9708. {
  9709. json_object *data;
  9710. data = json_tokener_parse(tempdata);
  9711. if(!is_error(data))
  9712. {
  9713. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9714. {
  9715. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9716. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9717. if(gun_index < gunTotalNumber)
  9718. {
  9719. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9720. {
  9721. json_object *responsedata = json_object_new_object();
  9722. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  9723. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9724. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.LineStatusPage.SerialNo[gun_index]));
  9725. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  9726. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9727. }
  9728. else
  9729. {
  9730. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9731. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9732. }
  9733. }
  9734. else
  9735. {
  9736. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9737. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9738. }
  9739. }
  9740. else
  9741. {
  9742. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9743. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9744. }
  9745. }
  9746. else
  9747. {
  9748. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9749. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9750. }
  9751. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9752. json_object_put(response);
  9753. }
  9754. else
  9755. {
  9756. // Can not find valid message id
  9757. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9758. }
  9759. }
  9760. else
  9761. {
  9762. // Payload is null
  9763. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9764. }
  9765. LWS_Send(message);
  9766. return result;
  9767. }
  9768. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9769. {
  9770. mtrace();
  9771. int result = FAIL;
  9772. int connectorIdInt, durationInt;
  9773. char chargingRateUnitStr[4]={0};
  9774. char comfirmstr[20];
  9775. int confirmPeriods = 0;
  9776. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9777. json_object *GetCompositeSchedule;
  9778. GetCompositeSchedule = json_tokener_parse(payload);
  9779. if(!is_error(GetCompositeSchedule))
  9780. {
  9781. // Required data
  9782. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9783. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9784. else
  9785. connectorIdInt = -1;
  9786. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9787. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9788. else
  9789. durationInt = 86400;
  9790. // Optional data
  9791. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9792. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9793. }
  9794. json_object_put(GetCompositeSchedule);
  9795. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9796. if((connectorIdInt == 0) ||
  9797. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9798. {
  9799. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9800. struct StructChargingProfile tmpProfile[1];
  9801. if(strstr(chargingRateUnitStr, "W") != NULL)
  9802. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9803. else
  9804. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9805. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9806. {
  9807. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9808. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9809. }
  9810. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9811. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9812. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9813. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9814. {
  9815. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9816. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9817. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9818. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9819. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9820. {
  9821. confirmPeriods = idx;
  9822. break;
  9823. }
  9824. }
  9825. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9826. {
  9827. confirmPeriods += 1;
  9828. }
  9829. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9830. }
  9831. else
  9832. {
  9833. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9834. }
  9835. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9836. return result;
  9837. }
  9838. int handleGetConfigurationRequest(char *uuid, char *payload)
  9839. {
  9840. mtrace();
  9841. int result = FAIL;
  9842. int MaxKeySupported = 0;
  9843. int n_keys = 0;
  9844. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9845. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9846. json_object *GetConfiguration;
  9847. GetConfiguration = json_tokener_parse(payload);
  9848. if(!is_error(GetConfiguration))
  9849. {
  9850. // Optional data
  9851. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9852. {
  9853. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9854. {
  9855. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9856. n_keys = idx + 1;
  9857. }
  9858. }
  9859. }
  9860. json_object_put(GetConfiguration);
  9861. UnknownKeynum = 0;
  9862. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9863. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9864. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9865. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9866. if(n_keys != 0)
  9867. {
  9868. for(int i=0;i<n_keys;i++)
  9869. {
  9870. getKeyValue(requestKey[i]);
  9871. }
  9872. }
  9873. else
  9874. {
  9875. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9876. getKeyValue("");
  9877. }
  9878. processUnkownKey();
  9879. sendGetConfigurationConfirmation(uuid);
  9880. return result;
  9881. }
  9882. static char fnamePlusPath[100]={0};
  9883. static char fnamePWithNoPath[60]={0};
  9884. void checkUploadLog(void)
  9885. {
  9886. FILE *fp;
  9887. /* Open the command for reading. */
  9888. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9889. if (fp == NULL) {
  9890. DEBUG_WARN("Failed to run command\n" );
  9891. exit(1);
  9892. }
  9893. int ftppathlen = 0;
  9894. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9895. int i = 0;
  9896. /* Read the output a line at a time - output it. */
  9897. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9898. if(i==0)
  9899. {
  9900. ftppathlen = strlen(fnamePlusPath);
  9901. DEBUG_INFO("%s\n", fnamePlusPath);
  9902. fnamePlusPath[ftppathlen]='\0';
  9903. break;
  9904. }
  9905. i= i+1;
  9906. }
  9907. /* close */
  9908. pclose(fp);
  9909. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9910. {
  9911. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9912. {
  9913. fnamePlusPath[k]='\0';
  9914. }
  9915. }
  9916. i=1;
  9917. //char fname[60]={0};
  9918. while(i < ftppathlen)
  9919. {
  9920. int len=ftppathlen-i;
  9921. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9922. {
  9923. DEBUG_INFO("compare '/' all right\n");
  9924. break;
  9925. }
  9926. i=i+1;
  9927. }
  9928. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9929. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9930. fnamePWithNoPath[i+1] = '\0';
  9931. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9932. {
  9933. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9934. {
  9935. fnamePWithNoPath[j]='\0';
  9936. }
  9937. }
  9938. FILE* fp1 = fopen(fnamePlusPath, "r");
  9939. if (fp1)
  9940. {
  9941. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9942. // file exists
  9943. fclose(fp1);
  9944. }
  9945. else
  9946. {
  9947. // file doesn't exist
  9948. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9949. }
  9950. }
  9951. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9952. {
  9953. mtrace();
  9954. int result = FAIL;
  9955. time_t CurrentTime;
  9956. struct tm *tm;
  9957. pthread_t th_Status;
  9958. CurrentTime = time(NULL);
  9959. tm = localtime(&CurrentTime);
  9960. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9961. 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);
  9962. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9963. if(!interLock.isGetDiagnosticGoing)
  9964. {
  9965. interLock.isGetDiagnosticGoing = 1;
  9966. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9967. sleep(1);
  9968. }
  9969. else
  9970. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9971. return result;
  9972. }
  9973. void* GetDiagnosticsProcess(void* data)
  9974. {
  9975. pthread_detach(pthread_self());
  9976. mtrace();
  9977. int retriesInt=0, retryIntervalInt=0;
  9978. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9979. 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};
  9980. int port=0;
  9981. int isSuccess = FALSE;
  9982. char cmdBuf[2048];
  9983. struct tm *tmNow;
  9984. time_t CurrentTime;
  9985. struct tm tmStart;
  9986. struct tm tmStop;
  9987. CurrentTime = time(NULL);
  9988. tmNow=localtime(&CurrentTime);
  9989. uint16_t targetYear, targetMonth;
  9990. json_object *GetDiagnostics;
  9991. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9992. GetDiagnostics = json_tokener_parse(data);
  9993. if(!is_error(GetDiagnostics))
  9994. {
  9995. // Required data
  9996. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9997. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9998. // Optional data
  9999. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10000. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10001. else
  10002. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10003. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10004. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10005. else
  10006. retryIntervalInt = 30;
  10007. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10008. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10009. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10010. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10011. }
  10012. json_object_put(GetDiagnostics);
  10013. // Pack log to compress file
  10014. 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) &&
  10015. (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))
  10016. {
  10017. // Pack system log
  10018. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10019. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10020. targetYear = tmStart.tm_year;
  10021. targetMonth = tmStart.tm_mon;
  10022. do
  10023. {
  10024. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10025. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10026. if(targetMonth+1>=13)
  10027. {
  10028. targetYear += 1;
  10029. targetMonth = 1;
  10030. }
  10031. else
  10032. {
  10033. targetMonth += 1;
  10034. }
  10035. }while((targetYear < (tmNow->tm_year+1900)) ||
  10036. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10037. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10038. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10039. system(cmdBuf);
  10040. // Pack charging & event log
  10041. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10042. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10043. targetYear = tmStart.tm_year;
  10044. targetMonth = tmStart.tm_mon;
  10045. do
  10046. {
  10047. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10048. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10049. if(targetMonth+1>=13)
  10050. {
  10051. targetYear += 1;
  10052. targetMonth = 1;
  10053. }
  10054. else
  10055. {
  10056. targetMonth += 1;
  10057. }
  10058. }while((targetYear < (tmNow->tm_year+1900)) ||
  10059. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10060. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10061. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10062. system(cmdBuf);
  10063. // Combine log file
  10064. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10065. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10066. }
  10067. else
  10068. {
  10069. system("exec /root/logPackTools 'log' 6");
  10070. }
  10071. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10072. system(cmdBuf);
  10073. checkUploadLog();
  10074. //****************location*******************/
  10075. if(strcmp(locationstr,"")==0)
  10076. {
  10077. DEBUG_INFO("location is <Empty>!\n");
  10078. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10079. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10080. goto end;
  10081. }
  10082. memset(protocol, 0, ARRAY_SIZE(protocol));
  10083. memset(user, 0, ARRAY_SIZE(user) );
  10084. memset(password, 0, ARRAY_SIZE(password));
  10085. memset(host, 0, ARRAY_SIZE(host));
  10086. memset(path, 0, ARRAY_SIZE(path));
  10087. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10088. memset(host1, 0, ARRAY_SIZE(host1));
  10089. memset(path1, 0, ARRAY_SIZE(path1));
  10090. /*location: ftp://user:password@host:port/path*/
  10091. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10092. if((access(fnamePlusPath,F_OK))!=-1)
  10093. {
  10094. DEBUG_INFO("fnamePlusPath exist.\n");
  10095. }
  10096. else
  10097. {
  10098. DEBUG_INFO("fnamePlusPath not exist!\n");
  10099. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10100. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10101. goto end;
  10102. }
  10103. if(strchr(locationstr,'@')==NULL)
  10104. {
  10105. sscanf(locationstr,
  10106. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10107. protocol, host, &port, path);
  10108. strcpy(user,"anonymous");
  10109. strcpy(password,"");
  10110. }
  10111. else
  10112. {
  10113. //DEBUG_INFO("pch=%s\n", pch);
  10114. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10115. protocol, user, password, host, &port, path);
  10116. }
  10117. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10118. {
  10119. DEBUG_INFO("protocol is not ftp/http ! \n");
  10120. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10121. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10122. goto end;
  10123. }
  10124. if(strncmp(locationstr,"http", 4) == 0)
  10125. {
  10126. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10127. sprintf(ftppath,"/%s", path);
  10128. do
  10129. {
  10130. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10131. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10132. sleep(3);
  10133. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10134. if(!isSuccess)
  10135. {
  10136. DEBUG_INFO("Diagnostics fail.\n");
  10137. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10138. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10139. sleep(retryIntervalInt);
  10140. }
  10141. else
  10142. {
  10143. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10144. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10145. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10146. }
  10147. retriesInt--;
  10148. }while((isSuccess == 0)&&(retriesInt >= 0));
  10149. }
  10150. else
  10151. {
  10152. sscanf(host,"%[^/]%s",host1, path1);
  10153. if(strlen(path) > 0)
  10154. sprintf(ftppath,"/%s", path);
  10155. else
  10156. sprintf(ftppath,"/%s", path1);
  10157. int ftppathlen=strlen(ftppath);
  10158. int i=1;
  10159. char filenametemp[50];
  10160. while(i < ftppathlen)
  10161. {
  10162. int len=ftppathlen-i;
  10163. if(ftppath[len]== 47) // '/' ascll code: 47
  10164. {
  10165. DEBUG_INFO("find '/' all right\n");
  10166. break;
  10167. }
  10168. i=i+1;
  10169. }
  10170. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10171. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10172. filenametemp[i+1] = 0;
  10173. if(port == 0)
  10174. port = 21;
  10175. do
  10176. {
  10177. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10178. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10179. sleep(3);
  10180. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10181. if(!isSuccess)
  10182. {
  10183. DEBUG_INFO("Diagnostics fail.\n");
  10184. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10185. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10186. sleep(retryIntervalInt);
  10187. }
  10188. else
  10189. {
  10190. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10191. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10192. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10193. }
  10194. retriesInt--;
  10195. }while((!isSuccess)&&(retriesInt >= 0));
  10196. }
  10197. end:
  10198. system("rm -f /mnt/*");
  10199. sleep(5);
  10200. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10201. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10202. interLock.isGetDiagnosticGoing = 0;
  10203. pthread_exit(NULL);
  10204. }
  10205. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10206. {
  10207. mtrace();
  10208. int result = FAIL;
  10209. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10210. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10211. {
  10212. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10213. locallistVersion = -1;
  10214. }
  10215. else
  10216. {
  10217. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10218. OCPP_getListVerion();
  10219. }
  10220. //from db.OCPP_getListVerion
  10221. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10222. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10223. sendGetLocalListVersionConfirmation(uuid,"");
  10224. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10225. return result;
  10226. }
  10227. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10228. {
  10229. mtrace();
  10230. int result = FAIL;
  10231. int connectorIdInt=-1;
  10232. int tempIndex = 0;
  10233. int connectorIdIsNULL, chargingProfileIsNULL;
  10234. char comfirmstr[20]={0};
  10235. char cmdBuf[512];
  10236. json_object *RemoteStartTransaction;
  10237. FILE *fp;
  10238. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10239. if(server_pending == TRUE)
  10240. {
  10241. return 0;
  10242. }
  10243. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10244. RemoteStartTransaction = json_tokener_parse(payload);
  10245. if(!is_error(RemoteStartTransaction))
  10246. {
  10247. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10248. {
  10249. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10250. }
  10251. else
  10252. {
  10253. connectorIdIsNULL = TRUE;
  10254. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10255. {
  10256. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10257. {
  10258. connectorIdIsNULL = FALSE;
  10259. connectorIdInt = (gun_index+1);
  10260. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10261. break;
  10262. }
  10263. }
  10264. }
  10265. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10266. {
  10267. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10268. // Required data
  10269. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10270. // Optional data
  10271. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10272. {
  10273. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10274. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10275. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10276. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10277. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10278. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10279. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10280. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10281. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10282. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10283. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10284. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10285. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10286. {
  10287. 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")));
  10288. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10289. 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"));
  10290. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10291. 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"));
  10292. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10293. 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")));
  10294. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10295. {
  10296. 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++)
  10297. {
  10298. 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"));
  10299. 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"));
  10300. 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)
  10301. 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"));
  10302. }
  10303. }
  10304. }
  10305. }
  10306. else
  10307. {
  10308. chargingProfileIsNULL = TRUE;
  10309. }
  10310. }
  10311. }
  10312. else
  10313. {
  10314. connectorIdIsNULL = TRUE;
  10315. }
  10316. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10317. {
  10318. DEBUG_WARN("Connector id is NULL\n.");
  10319. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10320. goto end;
  10321. }
  10322. /*
  10323. enum _SYSTEM_STATUS
  10324. {
  10325. S_BOOTING = 0,
  10326. S_IDLE, = 1
  10327. S_AUTHORIZING, = 2
  10328. S_REASSIGN_CHECK, = 3
  10329. S_REASSIGN, = 4
  10330. S_PRECHARGE, = 5
  10331. S_PREPARING_FOR_EV, = 6
  10332. S_PREPARING_FOR_EVSE, = 7
  10333. S_CHARGING, = 8
  10334. S_TERMINATING, = 9
  10335. S_COMPLETE, = 10
  10336. S_ALARM, = 11
  10337. S_FAULT = 12
  10338. }
  10339. */
  10340. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10341. {
  10342. //check Transaction active
  10343. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10344. {
  10345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10346. {
  10347. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10348. }
  10349. else
  10350. {
  10351. tempIndex = connectorIdInt -1;
  10352. }
  10353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10354. {
  10355. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10356. {
  10357. 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))
  10358. {
  10359. //Reserved
  10360. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10361. }
  10362. 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))
  10363. {
  10364. //Reserved
  10365. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10366. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10367. goto end;
  10368. }
  10369. else
  10370. {
  10371. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10372. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10373. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10374. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10375. {
  10376. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10377. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10378. goto end;
  10379. }
  10380. }//END FOR ELSE
  10381. }
  10382. }// END FOR CHAdeMO_QUANTITY
  10383. }
  10384. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10385. {
  10386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10387. {
  10388. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10389. }
  10390. else
  10391. {
  10392. tempIndex = connectorIdInt -1;
  10393. }
  10394. for (int index = 0; index < CCS_QUANTITY; index++)
  10395. {
  10396. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10397. {
  10398. 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))
  10399. {
  10400. //Reserved
  10401. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10402. }
  10403. 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))
  10404. {
  10405. //Reserved
  10406. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10407. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10408. goto end;
  10409. }
  10410. else
  10411. {
  10412. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10413. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10414. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10415. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10416. {
  10417. DEBUG_WARN("CCS connector not allow start\n.");
  10418. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10419. goto end;
  10420. }
  10421. }// END FOR ELSE
  10422. }
  10423. }// END FOR CCS_QUANTITY
  10424. }
  10425. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10426. {
  10427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10428. {
  10429. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10430. }
  10431. else
  10432. {
  10433. tempIndex = connectorIdInt -1;
  10434. }
  10435. for (int index = 0; index < GB_QUANTITY; index++)
  10436. {
  10437. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10438. {
  10439. 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))
  10440. {
  10441. //Reserved
  10442. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10443. }
  10444. 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))
  10445. {
  10446. //Reserved
  10447. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10448. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10449. goto end;
  10450. }
  10451. else
  10452. {
  10453. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10454. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10455. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10456. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10457. {
  10458. DEBUG_WARN("GB connector not allow start\n.");
  10459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10460. goto end;
  10461. }
  10462. }// END FOR ELSE
  10463. }
  10464. } // END FOR GB_QUANTITY
  10465. }
  10466. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10467. {
  10468. tempIndex = connectorIdInt -1;
  10469. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10470. {
  10471. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10472. {
  10473. 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))
  10474. {
  10475. //Reserved
  10476. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10477. }
  10478. 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))
  10479. {
  10480. //Reserved
  10481. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10482. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10483. goto end;
  10484. }
  10485. else
  10486. {
  10487. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10488. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10489. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10490. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10491. {
  10492. DEBUG_WARN("GB connector not allow start\n.");
  10493. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10494. goto end;
  10495. }
  10496. }// END FOR ELSE
  10497. }
  10498. } // END FOR GB_QUANTITY
  10499. }
  10500. else
  10501. {
  10502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10503. {
  10504. tempIndex = 2;
  10505. }
  10506. else
  10507. {
  10508. tempIndex = connectorIdInt -1;
  10509. }
  10510. for (int index = 0; index < AC_QUANTITY; index++)
  10511. {
  10512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10513. {
  10514. 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))
  10515. {
  10516. //Reserved
  10517. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10518. }
  10519. 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))
  10520. {
  10521. //Reserved
  10522. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10523. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10524. goto end;
  10525. }
  10526. else
  10527. {
  10528. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10529. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10530. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10531. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10532. {
  10533. DEBUG_WARN("AC connector not allow start\n.");
  10534. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10535. goto end;
  10536. }
  10537. }//END FOR ELSE
  10538. }
  10539. }// END FOR AC_QUANTITY
  10540. }
  10541. if(chargingProfileIsNULL == FALSE)
  10542. {
  10543. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10544. {
  10545. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10546. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10547. //memset idTag
  10548. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10549. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10550. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10551. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10552. // Save profile to file
  10553. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10554. system(cmdBuf);
  10555. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10556. fp = fopen(cmdBuf, "w");
  10557. 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));
  10558. fclose(fp);
  10559. }
  10560. else
  10561. {
  10562. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10563. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10564. }
  10565. }
  10566. else
  10567. {
  10568. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10569. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10570. //memset idTag
  10571. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10572. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10573. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10574. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10575. }
  10576. }
  10577. else
  10578. {
  10579. DEBUG_WARN("Connector id over\n.");
  10580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10581. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10582. }
  10583. end:
  10584. json_object_put(RemoteStartTransaction);
  10585. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10586. {
  10587. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10588. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10589. }
  10590. //OCPP send RemoteStartConfirmation by first.
  10591. sendRemoteStartConfirmation(uuid, comfirmstr);
  10592. return result;
  10593. }
  10594. int handleRemoteStartRequest(char *uuid, char *payload)
  10595. {
  10596. mtrace();
  10597. int result = PASS;
  10598. int connectorIdInt=-1;
  10599. int tempIndex = 0;
  10600. char comfirmstr[20]={0};
  10601. char cmdBuf[512];
  10602. json_object *RemoteStartTransaction;
  10603. FILE *fp;
  10604. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10605. if(server_pending == TRUE)
  10606. {
  10607. result = FAIL;
  10608. }
  10609. RemoteStartTransaction = json_tokener_parse(payload);
  10610. if(!is_error(RemoteStartTransaction))
  10611. {
  10612. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10613. {
  10614. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10615. }
  10616. else
  10617. {
  10618. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10619. {
  10620. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10621. {
  10622. connectorIdInt = (gun_index+1);
  10623. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10624. break;
  10625. }
  10626. }
  10627. }
  10628. if(connectorIdInt == 0)
  10629. {
  10630. DEBUG_WARN("Connector id shall not equal 0.\n");
  10631. result = FAIL;
  10632. }
  10633. else if(connectorIdInt == -1)
  10634. {
  10635. DEBUG_INFO("Connector id does not specific.\n");
  10636. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10637. {
  10638. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10639. // Required data
  10640. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10641. // Optional data
  10642. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10643. {
  10644. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10645. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10646. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10647. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10648. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10649. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10650. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10651. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10652. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10653. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10654. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10655. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10656. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10657. {
  10658. 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")));
  10659. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10660. 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"));
  10661. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10662. 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"));
  10663. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10664. 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")));
  10665. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10666. {
  10667. 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++)
  10668. {
  10669. 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"));
  10670. 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"));
  10671. 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)
  10672. 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"));
  10673. }
  10674. }
  10675. }
  10676. }
  10677. else
  10678. {
  10679. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10680. }
  10681. }
  10682. }
  10683. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10684. {
  10685. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10686. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10687. // Required data
  10688. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10689. // Optional data
  10690. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10691. {
  10692. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10693. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10694. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10695. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10696. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10697. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10698. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10699. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10700. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10701. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10702. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10703. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10704. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10705. {
  10706. 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")));
  10707. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10708. 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"));
  10709. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10710. 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"));
  10711. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10712. 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")));
  10713. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10714. {
  10715. 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++)
  10716. {
  10717. 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"));
  10718. 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"));
  10719. 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)
  10720. 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"));
  10721. }
  10722. }
  10723. }
  10724. }
  10725. else
  10726. {
  10727. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10728. }
  10729. }
  10730. else
  10731. {
  10732. DEBUG_WARN("Connector id is over maximun value.\n");
  10733. result = FAIL;
  10734. }
  10735. }
  10736. if(result == PASS)
  10737. {
  10738. if(connectorIdInt > 0)
  10739. {
  10740. //check Transaction active
  10741. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10742. {
  10743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10744. {
  10745. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10746. }
  10747. else
  10748. {
  10749. tempIndex = connectorIdInt -1;
  10750. }
  10751. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10752. {
  10753. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10754. {
  10755. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10756. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10757. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10758. {
  10759. //Reserved
  10760. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10761. }
  10762. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10763. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10764. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10765. {
  10766. //Reserved
  10767. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10768. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10769. goto end;
  10770. }
  10771. else
  10772. {
  10773. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10774. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10775. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10776. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10777. {
  10778. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10779. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10780. goto end;
  10781. }
  10782. }//END FOR ELSE
  10783. }
  10784. }// END FOR CHAdeMO_QUANTITY
  10785. }
  10786. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10787. {
  10788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10789. {
  10790. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10791. }
  10792. else
  10793. {
  10794. tempIndex = connectorIdInt -1;
  10795. }
  10796. for (int index = 0; index < CCS_QUANTITY; index++)
  10797. {
  10798. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10799. {
  10800. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10801. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10802. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10803. {
  10804. //Reserved
  10805. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10806. }
  10807. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10808. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10809. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10810. {
  10811. //Reserved
  10812. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10813. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10814. goto end;
  10815. }
  10816. else
  10817. {
  10818. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10819. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10820. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10821. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10822. {
  10823. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10824. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10825. goto end;
  10826. }
  10827. }// END FOR ELSE
  10828. }
  10829. }// END FOR CCS_QUANTITY
  10830. }
  10831. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10832. {
  10833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10834. {
  10835. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10836. }
  10837. else
  10838. {
  10839. tempIndex = connectorIdInt -1;
  10840. }
  10841. for (int index = 0; index < GB_QUANTITY; index++)
  10842. {
  10843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10844. {
  10845. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10846. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10847. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10848. {
  10849. //Reserved
  10850. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10851. }
  10852. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10853. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10854. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10855. {
  10856. //Reserved
  10857. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10858. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10859. goto end;
  10860. }
  10861. else
  10862. {
  10863. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10864. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10865. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10866. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10867. {
  10868. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10869. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10870. goto end;
  10871. }
  10872. }// END FOR ELSE
  10873. }
  10874. } // END FOR GB_QUANTITY
  10875. }
  10876. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10877. {
  10878. tempIndex = connectorIdInt -1;
  10879. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10880. {
  10881. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10882. {
  10883. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10884. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10885. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10886. {
  10887. //Reserved
  10888. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10889. }
  10890. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10891. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10892. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10893. {
  10894. //Reserved
  10895. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10896. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10897. goto end;
  10898. }
  10899. else
  10900. {
  10901. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10902. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10903. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10904. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10905. {
  10906. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10907. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10908. goto end;
  10909. }
  10910. }// END FOR ELSE
  10911. }
  10912. } // END FOR GB_QUANTITY
  10913. }
  10914. else
  10915. {
  10916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10917. {
  10918. tempIndex = 2;
  10919. }
  10920. else
  10921. {
  10922. tempIndex = connectorIdInt -1;
  10923. }
  10924. for (int index = 0; index < AC_QUANTITY; index++)
  10925. {
  10926. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10927. {
  10928. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10929. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10930. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10931. {
  10932. //Reserved
  10933. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10934. }
  10935. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10936. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10937. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10938. {
  10939. //Reserved
  10940. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10941. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10942. goto end;
  10943. }
  10944. else
  10945. {
  10946. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10947. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10948. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10949. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10950. {
  10951. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10952. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10953. goto end;
  10954. }
  10955. }//END FOR ELSE
  10956. }
  10957. }// END FOR AC_QUANTITY
  10958. }
  10959. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10960. {
  10961. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10962. {
  10963. // Save profile to file
  10964. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10965. system(cmdBuf);
  10966. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10967. fp = fopen(cmdBuf, "w");
  10968. 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));
  10969. fclose(fp);
  10970. }
  10971. else
  10972. {
  10973. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10974. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10975. goto end;
  10976. }
  10977. }
  10978. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10979. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10980. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10981. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10982. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10983. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10984. }
  10985. else
  10986. {
  10987. uint8_t isHasIdleConnector = FALSE;
  10988. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10989. {
  10990. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10991. {
  10992. isHasIdleConnector = TRUE;
  10993. break;
  10994. }
  10995. }
  10996. if(isHasIdleConnector == TRUE)
  10997. {
  10998. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10999. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11000. {
  11001. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11002. {
  11003. // Save profile to file
  11004. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11005. system(cmdBuf);
  11006. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11007. fp = fopen(cmdBuf, "w");
  11008. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11009. fclose(fp);
  11010. refreshStartTimer(&clientTime.RemoteStartWait);
  11011. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11012. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11013. }
  11014. else
  11015. {
  11016. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11017. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11018. }
  11019. }
  11020. else
  11021. {
  11022. refreshStartTimer(&clientTime.RemoteStartWait);
  11023. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11024. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11025. }
  11026. }
  11027. else
  11028. {
  11029. DEBUG_INFO("There is not any connector is idle.\n");
  11030. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11031. }
  11032. }
  11033. }
  11034. else
  11035. {
  11036. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11037. }
  11038. end:
  11039. json_object_put(RemoteStartTransaction);
  11040. sendRemoteStartConfirmation(uuid, comfirmstr);
  11041. return result;
  11042. }
  11043. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11044. {
  11045. mtrace();
  11046. int result = FAIL;
  11047. int match = FALSE;
  11048. int GunNO = 0;
  11049. int tempIndex = 0;
  11050. int transactionIdInt=0;
  11051. int transactionIdIsNULL= TRUE;
  11052. char comfirmstr[20];
  11053. json_object *RemoteStopTransaction;
  11054. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11055. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11056. if(server_pending == TRUE)
  11057. {
  11058. return 0;
  11059. }
  11060. RemoteStopTransaction = json_tokener_parse(payload);
  11061. if(!is_error(RemoteStopTransaction))
  11062. {
  11063. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11064. {
  11065. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11066. transactionIdIsNULL = FALSE;
  11067. }
  11068. }
  11069. json_object_put(RemoteStopTransaction);
  11070. if(transactionIdIsNULL == FALSE)
  11071. {
  11072. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11073. {
  11074. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11075. {
  11076. //check Transaction active
  11077. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11078. {
  11079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11080. {
  11081. tempIndex = ((gun_index==2) ? 1: 0);
  11082. }
  11083. else
  11084. {
  11085. tempIndex = gun_index;
  11086. }
  11087. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11088. {
  11089. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11090. {
  11091. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11092. {
  11093. match = TRUE;
  11094. GunNO = gun_index;
  11095. }
  11096. }
  11097. }// END FOR CHAdeMO_QUANTITY
  11098. }
  11099. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11100. {
  11101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11102. {
  11103. tempIndex = ((gun_index==2) ? 1: 0);
  11104. }
  11105. else
  11106. {
  11107. tempIndex = gun_index;
  11108. }
  11109. for (int index = 0; index < CCS_QUANTITY; index++)
  11110. {
  11111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11112. {
  11113. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11114. {
  11115. match = TRUE;
  11116. GunNO = gun_index;
  11117. }
  11118. }
  11119. }// END FOR CCS_QUANTITY
  11120. }
  11121. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11122. {
  11123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11124. {
  11125. tempIndex = ((gun_index==2) ? 1: 0);
  11126. }
  11127. else
  11128. {
  11129. tempIndex = gun_index;
  11130. }
  11131. for (int index = 0; index < GB_QUANTITY; index++)
  11132. {
  11133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11134. {
  11135. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11136. {
  11137. match = TRUE;
  11138. GunNO = gun_index;
  11139. }
  11140. }
  11141. }// END FOR GB_QUANTITY
  11142. }
  11143. else if(gunType[gun_index] == GUN_TYPE_DO)
  11144. {
  11145. tempIndex = gun_index;
  11146. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11147. {
  11148. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11149. {
  11150. 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
  11151. {
  11152. match = TRUE;
  11153. GunNO = gun_index;
  11154. }
  11155. }
  11156. }// END FOR GB_QUANTITY
  11157. }
  11158. else
  11159. {
  11160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11161. {
  11162. tempIndex = 2;
  11163. }
  11164. else
  11165. {
  11166. tempIndex = gun_index;
  11167. }
  11168. for (int index = 0; index < AC_QUANTITY; index++)
  11169. {
  11170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11171. {
  11172. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11173. {
  11174. match = TRUE;
  11175. GunNO = gun_index;
  11176. }
  11177. }
  11178. }// END FOR CHAdeMO_QUANTITY
  11179. } // END FOR AC ELSE
  11180. }// CHECK IF ResponseTransactionId == transactionIdInt
  11181. }//END FOR
  11182. if( match == TRUE)
  11183. {
  11184. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11185. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11186. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11187. }
  11188. else
  11189. {
  11190. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11191. }
  11192. }
  11193. else
  11194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11195. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11196. return result;
  11197. }
  11198. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11199. {
  11200. mtrace();
  11201. int result = FAIL;
  11202. int connectorIdInt=0, reservationIdInt=0;
  11203. int tempIndex = 0;
  11204. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11205. char comfirmstr[20]={0};
  11206. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11207. int c = 0;
  11208. char *loc;
  11209. //char *ptr;
  11210. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11211. strcpy(sstrtemp, stringtrimspace(payload));
  11212. //***(1)connectorId ****/
  11213. c=0;
  11214. loc = strstr(sstrtemp, "connectorId");
  11215. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11216. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11217. {
  11218. sstr[c] = loc[strlen("connectorId")+2+c];
  11219. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11220. c++;
  11221. }
  11222. sstr[c] = '\0';
  11223. connectorIdInt = atoi(sstr);
  11224. //***(2)expiryDate ****/
  11225. loc = strstr(sstrtemp, "expiryDate");
  11226. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11227. c = 0;
  11228. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11229. {
  11230. sstr[c] = loc[3+strlen("expiryDate")+c];
  11231. c++;
  11232. }
  11233. sstr[c] = '\0';
  11234. strcpy(expiryDatestr, sstr);
  11235. //***(3)idTag ****/
  11236. loc = strstr(sstrtemp, "idTag");
  11237. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11238. c = 0;
  11239. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11240. {
  11241. sstr[c] = loc[3+strlen("idTag")+c];
  11242. c++;
  11243. }
  11244. sstr[c] = '\0';
  11245. strcpy(idTagstr, sstr);
  11246. //***(4)parentIdTag ****/
  11247. loc = strstr(sstrtemp, "parentIdTag");
  11248. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11249. c = 0;
  11250. if(loc == NULL)
  11251. {
  11252. strcpy(parentIdTagstr, "");
  11253. }
  11254. else
  11255. {
  11256. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11257. {
  11258. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11259. c++;
  11260. }
  11261. sstr[c] = '\0';
  11262. strcpy(parentIdTagstr, sstr);
  11263. }
  11264. //***(5)reservationId ****/
  11265. c=0;
  11266. loc = strstr(sstrtemp, "reservationId");
  11267. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11268. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11269. {
  11270. sstr[c] = loc[strlen("reservationId")+2+c];
  11271. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11272. c++;
  11273. }
  11274. sstr[c] = '\0';
  11275. reservationIdInt = atoi(sstr);
  11276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11277. /*
  11278. enum SYSTEM_STATUS
  11279. {
  11280. SYS_MODE_BOOTING = 0,
  11281. SYS_MODE_IDLE = 1,
  11282. SYS_MODE_AUTHORIZING = 2,
  11283. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11284. SYS_MODE_REASSIGN = 4,
  11285. SYS_MODE_PREPARING = 5,
  11286. SYS_MODE_PREPARE_FOR_EV = 6,
  11287. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11288. SYS_MODE_CHARGING = 8,
  11289. SYS_MODE_TERMINATING = 9,
  11290. SYS_MODE_COMPLETE = 10,
  11291. SYS_MODE_ALARM = 11,
  11292. SYS_MODE_FAULT = 12,
  11293. SYS_MODE_RESERVATION = 13,
  11294. SYS_MODE_BOOKING = 14,
  11295. SYS_MODE_MAINTAIN = 15,
  11296. SYS_MODE_DEBUG = 16,
  11297. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11298. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11299. SYS_MODE_UPDATE = 19
  11300. };
  11301. */
  11302. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11303. {
  11304. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11305. goto end;
  11306. }
  11307. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11308. {
  11309. //check Transaction active
  11310. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11311. {
  11312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11313. {
  11314. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11315. }
  11316. else
  11317. {
  11318. tempIndex = connectorIdInt -1;
  11319. }
  11320. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11321. {
  11322. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11323. {
  11324. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11325. {
  11326. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11327. {
  11328. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11329. {
  11330. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11332. }
  11333. 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'))
  11334. {
  11335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11336. }
  11337. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11338. {
  11339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11340. }
  11341. else
  11342. {
  11343. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11344. }
  11345. }
  11346. 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
  11347. {
  11348. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11349. }
  11350. }
  11351. else
  11352. {
  11353. //replace reservation
  11354. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11355. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11356. }
  11357. }
  11358. } // END FOR CHAdeMO_QUANTITY
  11359. }
  11360. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11361. {
  11362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11363. {
  11364. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11365. }
  11366. else
  11367. {
  11368. tempIndex = connectorIdInt -1;
  11369. }
  11370. for (int index = 0; index < CCS_QUANTITY; index++)
  11371. {
  11372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11373. {
  11374. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11375. {
  11376. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11377. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11378. {
  11379. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11380. {
  11381. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11383. }
  11384. 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'))
  11385. {
  11386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11387. }
  11388. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11389. {
  11390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11391. }
  11392. else
  11393. {
  11394. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11395. }
  11396. }
  11397. 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
  11398. {
  11399. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11400. }
  11401. }
  11402. else
  11403. {
  11404. //replace reservation
  11405. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11406. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11407. }
  11408. }
  11409. } // END FOR CCS_QUANTITY
  11410. }
  11411. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11412. {
  11413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11414. {
  11415. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11416. }
  11417. else
  11418. {
  11419. tempIndex = connectorIdInt -1;
  11420. }
  11421. for (int index = 0; index < GB_QUANTITY; index++)
  11422. {
  11423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11424. {
  11425. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11426. {
  11427. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11428. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11429. {
  11430. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11431. {
  11432. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11434. }
  11435. 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'))
  11436. {
  11437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11438. }
  11439. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11440. {
  11441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11442. }
  11443. else
  11444. {
  11445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11446. }
  11447. }
  11448. 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
  11449. {
  11450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11451. }
  11452. }
  11453. else
  11454. {
  11455. //replace reservation
  11456. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11457. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11458. }
  11459. }
  11460. }// END FOR GB_QUANTITY
  11461. }
  11462. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11463. {
  11464. tempIndex = connectorIdInt -1;
  11465. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11466. {
  11467. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11468. {
  11469. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11470. {
  11471. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11472. 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
  11473. {
  11474. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11475. {
  11476. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11478. }
  11479. 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'))
  11480. {
  11481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11482. }
  11483. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11484. {
  11485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11486. }
  11487. else
  11488. {
  11489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11490. }
  11491. }
  11492. 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
  11493. {
  11494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11495. }
  11496. }
  11497. else
  11498. {
  11499. //replace reservation
  11500. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11501. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11502. }
  11503. }
  11504. }// END FOR GB_QUANTITY
  11505. }
  11506. else
  11507. {
  11508. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11509. {
  11510. tempIndex = 2;
  11511. }
  11512. else
  11513. {
  11514. tempIndex = (connectorIdInt -1);
  11515. }
  11516. for (int index = 0; index < AC_QUANTITY; index++)
  11517. {
  11518. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11519. {
  11520. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11521. {
  11522. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11523. {
  11524. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11525. {
  11526. 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))
  11527. {
  11528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11529. }
  11530. else
  11531. {
  11532. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11534. }
  11535. }
  11536. 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'))
  11537. {
  11538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11539. }
  11540. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11541. {
  11542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11543. }
  11544. else
  11545. {
  11546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11547. }
  11548. }
  11549. 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
  11550. {
  11551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11552. }
  11553. }
  11554. else
  11555. {
  11556. //replace reservation
  11557. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11558. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11559. }
  11560. }
  11561. } // END FOR AC_QUANTITY
  11562. }
  11563. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11564. }
  11565. else if(connectorIdInt == 0)
  11566. {
  11567. //check Transaction active
  11568. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11569. {
  11570. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11571. {
  11572. 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'))
  11573. {
  11574. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11575. goto end;
  11576. }
  11577. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11578. {
  11579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11580. goto end;
  11581. }
  11582. 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
  11583. {
  11584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11585. goto end;
  11586. }
  11587. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11588. {
  11589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11590. goto end;
  11591. }
  11592. }
  11593. }// END FOR CHAdeMO_QUANTITY
  11594. for (int index = 0; index < CCS_QUANTITY; index++)
  11595. {
  11596. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11597. {
  11598. 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'))
  11599. {
  11600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11601. goto end;
  11602. }
  11603. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11604. {
  11605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11606. goto end;
  11607. }
  11608. 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
  11609. {
  11610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11611. goto end;
  11612. }
  11613. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11614. {
  11615. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11616. goto end;
  11617. }
  11618. }
  11619. } // END FOR CCS_QUANTITY
  11620. for (int index = 0; index < GB_QUANTITY; index++)
  11621. {
  11622. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11623. {
  11624. 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'))
  11625. {
  11626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11627. goto end;
  11628. }
  11629. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11630. {
  11631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11632. goto end;
  11633. }
  11634. 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
  11635. {
  11636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11637. goto end;
  11638. }
  11639. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11640. {
  11641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11642. goto end;
  11643. }
  11644. }
  11645. } // END FOR GB_QUANTITY
  11646. for (int index = 0; index < AC_QUANTITY; index++)
  11647. {
  11648. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11649. {
  11650. 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'))
  11651. {
  11652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11653. goto end;
  11654. }
  11655. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11656. {
  11657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11658. goto end;
  11659. }
  11660. 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
  11661. {
  11662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11663. goto end;
  11664. }
  11665. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11666. {
  11667. 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))
  11668. {
  11669. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11670. goto end;
  11671. }
  11672. }
  11673. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11674. {
  11675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11676. goto end;
  11677. }
  11678. }
  11679. }// END FOR AC_QUANTITY
  11680. //The connectorId is 0
  11681. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11683. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11684. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11685. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11686. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11687. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11688. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11689. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11690. result = TRUE;
  11691. return result;
  11692. }
  11693. else
  11694. {
  11695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11696. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11697. }
  11698. if(strcmp(comfirmstr,"Accepted") == 0)
  11699. {
  11700. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11701. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11702. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11703. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11704. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11705. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11706. result = TRUE;
  11707. return result;
  11708. }
  11709. end:
  11710. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11711. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11712. return result;
  11713. }
  11714. int handleResetRequest(char *uuid, char *payload)
  11715. {
  11716. mtrace();
  11717. int result = FAIL;
  11718. char sstr[10]={0},sstrtemp[30]={ 0 };
  11719. char typestr[10]={0};
  11720. char comfirmstr[20]={0};
  11721. int c = 0;
  11722. char *loc;
  11723. DEBUG_INFO("handleResetRequest...\n");
  11724. strcpy(sstrtemp, stringtrimspace(payload));
  11725. loc = strstr(sstrtemp, "type");
  11726. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11727. c = 0;
  11728. while (loc[3+strlen("type")+c] != '\"')
  11729. {
  11730. sstr[c] = loc[3+strlen("type")+c];
  11731. c++;
  11732. }
  11733. sstr[c] = '\0';
  11734. strcpy(typestr,sstr);
  11735. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11736. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11737. {
  11738. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11739. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11740. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11741. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11742. }
  11743. else
  11744. {
  11745. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11746. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11747. result = PASS;
  11748. }
  11749. sendResetConfirmation(uuid, comfirmstr);
  11750. return result;
  11751. }
  11752. int handleSendLocalListRequest(char *uuid, char *payload)
  11753. {
  11754. mtrace();
  11755. int result = FAIL;
  11756. char comfirmstr[20];
  11757. int checkState_Faulted = FALSE;
  11758. json_object *SendLocalList;
  11759. DEBUG_INFO("handleSendLocalListRequest...\n");
  11760. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11761. {
  11762. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11763. goto end;
  11764. }
  11765. //check Charge Point state
  11766. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11767. {
  11768. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11769. {
  11770. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11771. }
  11772. }
  11773. for (int index = 0; index < CCS_QUANTITY; index++)
  11774. {
  11775. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11776. {
  11777. checkState_Faulted = TRUE; //OCPP Status
  11778. }
  11779. }
  11780. for (int index = 0; index < GB_QUANTITY; index++)
  11781. {
  11782. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11783. {
  11784. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11785. }
  11786. }
  11787. //check Charge Point state
  11788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11789. {
  11790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11791. {
  11792. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11793. }
  11794. }
  11795. //check Charge Point state
  11796. for (int index = 0; index < AC_QUANTITY; index++)
  11797. {
  11798. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11799. {
  11800. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11801. }
  11802. }
  11803. if(checkState_Faulted == TRUE)
  11804. {
  11805. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11806. goto end;
  11807. }
  11808. // Parsing payload
  11809. SendLocalList = json_tokener_parse(payload);
  11810. if(!is_error(SendLocalList))
  11811. {
  11812. // Required data
  11813. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11814. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11815. // Optional data
  11816. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11817. {
  11818. //Check UpdateType
  11819. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11820. {
  11821. //Local list full update
  11822. DEBUG_INFO("Local list full update.\n");
  11823. OCPP_getListVerion();
  11824. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11825. {
  11826. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11827. goto end;
  11828. }
  11829. OCPP_cleanLocalList();
  11830. }
  11831. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11832. {
  11833. //Local list different update
  11834. DEBUG_INFO("Local list different update.\n");
  11835. OCPP_getListVerion();
  11836. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11837. {
  11838. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11839. goto end;
  11840. }
  11841. }
  11842. else
  11843. {
  11844. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11845. goto end;
  11846. }
  11847. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11848. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11849. {
  11850. 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")));
  11851. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11852. {
  11853. 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")));
  11854. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11855. 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")));
  11856. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11857. 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")));
  11858. }
  11859. // Add to db
  11860. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11861. {
  11862. //Local list full update
  11863. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11864. idx,
  11865. ShmOCPP16Data->SendLocalList.ListVersion,
  11866. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11867. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11868. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11869. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11870. // update list
  11871. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11872. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11873. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11874. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11875. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11876. }
  11877. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11878. {
  11879. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11880. idx,
  11881. ShmOCPP16Data->SendLocalList.ListVersion,
  11882. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11883. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11884. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11885. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11886. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11887. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11888. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11889. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11890. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11891. }
  11892. }
  11893. }
  11894. else
  11895. {
  11896. //Check UpdateType
  11897. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11898. {
  11899. //Local list full update
  11900. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11901. OCPP_cleanLocalList();
  11902. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11903. goto end;
  11904. }
  11905. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11906. {
  11907. //Local list different update
  11908. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11909. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11910. goto end;
  11911. }
  11912. }
  11913. result = PASS;
  11914. }
  11915. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11916. end:
  11917. json_object_put(SendLocalList);
  11918. sendSendLocalListConfirmation(uuid, comfirmstr);
  11919. return result;
  11920. }
  11921. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11922. {
  11923. mtrace();
  11924. int result = FAIL;
  11925. struct StructSetChargingProfile SetProfileReq = {0};
  11926. int tempchargingProfileIdInt;
  11927. int chargingSchedulePeriodCount = 0;
  11928. char comfirmstr[20]={0};
  11929. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11930. char rmFileCmd[128]={0};
  11931. int profileQuantity = 0;
  11932. json_object *SetChargingProfile;
  11933. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11934. SetChargingProfile = json_tokener_parse(payload);
  11935. if(!is_error(SetChargingProfile))
  11936. {
  11937. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11938. {
  11939. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11940. }
  11941. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11942. {
  11943. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11944. {
  11945. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11946. }
  11947. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11948. {
  11949. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11950. }
  11951. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11952. {
  11953. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11954. }
  11955. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11956. {
  11957. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11958. }
  11959. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11960. {
  11961. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11962. }
  11963. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11964. {
  11965. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11966. }
  11967. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11968. {
  11969. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11970. }
  11971. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11972. {
  11973. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11974. }
  11975. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11976. {
  11977. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11978. {
  11979. 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")));
  11980. }
  11981. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11982. {
  11983. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11984. }
  11985. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11986. {
  11987. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11988. }
  11989. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11990. {
  11991. 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")));
  11992. }
  11993. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11994. {
  11995. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11996. if(chargingSchedulePeriodCount <= 10)
  11997. {
  11998. 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++)
  11999. {
  12000. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  12001. {
  12002. 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"));
  12003. }
  12004. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  12005. {
  12006. 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"));
  12007. }
  12008. 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)
  12009. {
  12010. 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"));
  12011. }
  12012. }
  12013. }
  12014. }
  12015. }
  12016. }
  12017. }
  12018. // Profile periods quantity check
  12019. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12020. {
  12021. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12022. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12023. goto end;
  12024. }
  12025. // Check invalid limit
  12026. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12027. {
  12028. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12029. {
  12030. 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)))) ||
  12031. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12032. {
  12033. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12034. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12035. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12036. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12037. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12038. goto end;
  12039. }
  12040. }
  12041. }
  12042. else
  12043. {
  12044. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12045. {
  12046. 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))
  12047. {
  12048. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12049. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12050. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12051. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12052. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12053. goto end;
  12054. }
  12055. }
  12056. }
  12057. // Profile purpose info check
  12058. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12059. {
  12060. FILE *fp;
  12061. char dataLine[4096]={0};
  12062. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12063. if(SetProfileReq.ConnectorId != 0)
  12064. {
  12065. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12066. DEBUG_WARN("Profile connector id is not 0.\n");
  12067. goto end;
  12068. }
  12069. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12070. if (!fp)
  12071. {
  12072. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12073. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12074. }
  12075. else
  12076. {
  12077. while(fscanf(fp, "%s", dataLine) != EOF)
  12078. {
  12079. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12080. {
  12081. profileQuantity += 1;
  12082. }
  12083. }
  12084. }
  12085. fclose(fp);
  12086. }
  12087. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12088. {
  12089. FILE *fp;
  12090. char dataLine[4096]={0};
  12091. char filename[128]={0};
  12092. int tmpProfileQuantity;
  12093. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12094. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12095. {
  12096. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12097. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12098. goto end;
  12099. }
  12100. if(SetProfileReq.ConnectorId == 0)
  12101. {
  12102. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12103. {
  12104. tmpProfileQuantity = 0;
  12105. memset(filename, 0, ARRAY_SIZE(filename));
  12106. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12107. fp = fopen(filename, "r");
  12108. if (!fp)
  12109. {
  12110. DEBUG_INFO("%s does not create.\n", filename);
  12111. fp = fopen(filename, "w+");
  12112. }
  12113. else
  12114. {
  12115. while(fscanf(fp, "%s", dataLine) != EOF)
  12116. {
  12117. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12118. {
  12119. tmpProfileQuantity += 1;
  12120. }
  12121. }
  12122. }
  12123. fclose(fp);
  12124. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12125. }
  12126. }
  12127. else
  12128. {
  12129. memset(filename, 0, ARRAY_SIZE(filename));
  12130. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12131. fp = fopen(filename, "r");
  12132. if (!fp)
  12133. {
  12134. DEBUG_INFO("%s does not create.\n", filename);
  12135. fp = fopen(filename, "w+");
  12136. }
  12137. else
  12138. {
  12139. while(fscanf(fp, "%s", dataLine) != EOF)
  12140. {
  12141. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12142. {
  12143. profileQuantity += 1;
  12144. }
  12145. }
  12146. }
  12147. fclose(fp);
  12148. }
  12149. }
  12150. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12151. {
  12152. int isMatchTransactiodId= FALSE;
  12153. FILE *fp;
  12154. char dataLine[4096]={0};
  12155. char filename[128]={0};
  12156. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12157. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12158. if(SetProfileReq.ConnectorId == 0)
  12159. {
  12160. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12161. DEBUG_WARN("Profile connector id is 0.\n");
  12162. goto end;
  12163. }
  12164. int tempIndex = 0;
  12165. //check Transaction active
  12166. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12167. {
  12168. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12169. {
  12170. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12171. }
  12172. else
  12173. {
  12174. tempIndex = SetProfileReq.ConnectorId -1;
  12175. }
  12176. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12177. {
  12178. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12179. {
  12180. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12181. {
  12182. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12183. {
  12184. isMatchTransactiodId = TRUE;
  12185. break;
  12186. }
  12187. }
  12188. }
  12189. }
  12190. }
  12191. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12192. {
  12193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12194. {
  12195. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12196. }
  12197. else
  12198. {
  12199. tempIndex = SetProfileReq.ConnectorId -1;
  12200. }
  12201. for (int index = 0; index < CCS_QUANTITY; index++)
  12202. {
  12203. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12204. {
  12205. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12206. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12207. {
  12208. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12209. {
  12210. isMatchTransactiodId = TRUE;
  12211. break;
  12212. }
  12213. }
  12214. }
  12215. }
  12216. }
  12217. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12218. {
  12219. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12220. {
  12221. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12222. }
  12223. else
  12224. {
  12225. tempIndex = SetProfileReq.ConnectorId -1;
  12226. }
  12227. for (int index = 0; index < GB_QUANTITY; index++)
  12228. {
  12229. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12230. {
  12231. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12232. {
  12233. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12234. {
  12235. isMatchTransactiodId = TRUE;
  12236. break;
  12237. }
  12238. }
  12239. }
  12240. }
  12241. }
  12242. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12243. {
  12244. tempIndex = SetProfileReq.ConnectorId -1;
  12245. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12246. {
  12247. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12248. {
  12249. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12250. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12251. {
  12252. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12253. {
  12254. isMatchTransactiodId = TRUE;
  12255. break;
  12256. }
  12257. }
  12258. }
  12259. }
  12260. }
  12261. else
  12262. {
  12263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12264. {
  12265. tempIndex = 2;
  12266. }
  12267. else
  12268. {
  12269. tempIndex = (SetProfileReq.ConnectorId -1);
  12270. }
  12271. for (int index = 0; index < AC_QUANTITY; index++)
  12272. {
  12273. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12274. {
  12275. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12276. {
  12277. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12278. {
  12279. isMatchTransactiodId = TRUE;
  12280. break;
  12281. }
  12282. }
  12283. }
  12284. }
  12285. }
  12286. //check Transaction active
  12287. if(isMatchTransactiodId == FALSE)
  12288. {
  12289. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12290. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12291. goto end;
  12292. }
  12293. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12294. {
  12295. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12296. DEBUG_WARN("Connector id is over max gun number.\n");
  12297. goto end;
  12298. }
  12299. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12300. fp = fopen(filename, "r");
  12301. if (!fp)
  12302. {
  12303. DEBUG_INFO("%s does not create.\n", filename);
  12304. fp = fopen(filename, "w+");
  12305. }
  12306. else
  12307. {
  12308. //Check Charging Profile Count
  12309. while(fscanf(fp, "%s", dataLine) != EOF)
  12310. {
  12311. //DEBUG_INFO("word=%s\n",word);
  12312. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12313. {
  12314. profileQuantity += 1;
  12315. }
  12316. }
  12317. }
  12318. fclose(fp);
  12319. }
  12320. // Check ChargeProfileMaxStackLevel
  12321. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12322. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12323. {
  12324. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12325. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12326. goto end;
  12327. }
  12328. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12329. {
  12330. FILE *fp;
  12331. char dataLine[4096]={0};
  12332. char fnametemp[128]={0};
  12333. int tmpProfileQuantity;
  12334. //Check ChargePointMaxProfile.json exit
  12335. profileQuantity = 0;
  12336. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12337. {
  12338. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12339. //Check Charging Profile Count
  12340. tmpProfileQuantity = 0;
  12341. while(fscanf(fp, "%s", dataLine) != EOF)
  12342. {
  12343. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12344. {
  12345. profileQuantity += 1;
  12346. tmpProfileQuantity += 1;
  12347. }
  12348. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12349. }
  12350. fclose(fp);
  12351. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12352. }
  12353. //Check TxDefaultProfile_%d.json
  12354. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12355. {
  12356. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12357. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12358. if((access(fnametemp,F_OK))!=-1)
  12359. {
  12360. fp = fopen(fnametemp, "r");
  12361. //Check Charging Profile Count
  12362. tmpProfileQuantity = 0;
  12363. while(fscanf(fp, "%s", dataLine) != EOF)
  12364. {
  12365. //DEBUG_INFO("word=%s\n",word);
  12366. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12367. {
  12368. profileQuantity += 1;
  12369. tmpProfileQuantity += 1;
  12370. }
  12371. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12372. }
  12373. fclose(fp);
  12374. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12375. }
  12376. }
  12377. //Check TxProfile_%d.json
  12378. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12379. {
  12380. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12381. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12382. if((access(fnametemp,F_OK))!=-1)
  12383. {
  12384. fp = fopen(fnametemp, "r");
  12385. //Check Charging Profile Count
  12386. tmpProfileQuantity = 0;
  12387. while(fscanf(fp, "%s", dataLine) != EOF)
  12388. {
  12389. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12390. {
  12391. profileQuantity += 1;
  12392. tmpProfileQuantity += 1;
  12393. }
  12394. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12395. }
  12396. fclose(fp);
  12397. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12398. }
  12399. }
  12400. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12401. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12402. {
  12403. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12404. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12405. goto end;
  12406. }
  12407. }
  12408. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12409. //**********************************Write to File********************************************************/
  12410. {
  12411. FILE *infile;
  12412. FILE *outfile;
  12413. char dataLine[4096]={0};
  12414. char filename[128]={0};
  12415. int chkChar=0;
  12416. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12417. {
  12418. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12419. {
  12420. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12421. }
  12422. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12423. {
  12424. if(SetProfileReq.ConnectorId==0)
  12425. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12426. else
  12427. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12428. }
  12429. else
  12430. {
  12431. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12432. }
  12433. infile = fopen (filename, "r");
  12434. outfile = fopen (tempfile, "w");
  12435. chkChar = fgetc(infile);
  12436. rewind(infile);
  12437. if(chkChar == EOF)
  12438. {
  12439. // Profile is empty
  12440. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12441. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12442. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12443. fclose(infile);
  12444. fclose(outfile);
  12445. sprintf(rmFileCmd,"rm -f %s",filename);
  12446. system(rmFileCmd);
  12447. rename(tempfile, filename);
  12448. }
  12449. else
  12450. {
  12451. // Profile is not empty
  12452. int ChargingProfileAdded = FALSE;
  12453. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12454. {
  12455. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12456. json_object *tmpChargingProfile;
  12457. tmpChargingProfile = json_tokener_parse(dataLine);
  12458. if(!is_error(SetChargingProfile))
  12459. {
  12460. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12461. {
  12462. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12463. {
  12464. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12465. }
  12466. }
  12467. }
  12468. json_object_put(tmpChargingProfile);
  12469. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12470. {
  12471. if(ChargingProfileAdded == FALSE)
  12472. {
  12473. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12474. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12475. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12476. ChargingProfileAdded = TRUE;
  12477. }
  12478. }
  12479. else
  12480. {
  12481. fprintf(outfile,"%s\n",dataLine);
  12482. if(ChargingProfileAdded == FALSE)
  12483. {
  12484. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12485. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12486. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12487. ChargingProfileAdded = TRUE;
  12488. }
  12489. }
  12490. } // end of while loop
  12491. fclose(infile);
  12492. fclose(outfile);
  12493. sprintf(rmFileCmd,"rm -f %s",filename);
  12494. system(rmFileCmd);
  12495. rename(tempfile, filename);
  12496. }
  12497. }
  12498. sleep(1);
  12499. result = TRUE;
  12500. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12501. }
  12502. end:
  12503. json_object_put(SetChargingProfile);
  12504. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12505. {
  12506. if(SetProfileReq.ConnectorId == 0)
  12507. {
  12508. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12509. {
  12510. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12511. }
  12512. }
  12513. else
  12514. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12515. }
  12516. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12517. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12518. return result;
  12519. }
  12520. int handleTriggerMessageRequest(char *uuid, char *payload)
  12521. {
  12522. mtrace();
  12523. int result = FAIL;
  12524. int connectorIdIsNULL = FALSE;
  12525. int connectorIdInt =0;
  12526. char sstr[40]={0},sstrtemp[100]={ 0 };
  12527. char requestedMessagestr[40]={0};
  12528. char comfirmstr[20]={0};
  12529. int c = 0;
  12530. char *loc;
  12531. DEBUG_INFO("handleTriggerMessageRequest\n");
  12532. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12533. strcpy(sstrtemp, stringtrimspace(payload));
  12534. c = 0;
  12535. loc = strstr(sstrtemp, "requestedMessage");
  12536. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12537. {
  12538. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12539. c++;
  12540. }
  12541. sstr[c] = '\0';
  12542. strcpy(requestedMessagestr, sstr);
  12543. c = 0;
  12544. loc = strstr(sstrtemp, "connectorId");
  12545. if(loc == NULL)
  12546. {
  12547. connectorIdIsNULL = TRUE;
  12548. }
  12549. else
  12550. {
  12551. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12552. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12553. {
  12554. sstr[c] = loc[strlen("connectorId")+2+c];
  12555. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12556. c++;
  12557. }
  12558. sstr[c] = '\0';
  12559. connectorIdInt = atoi(sstr);
  12560. }
  12561. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12562. {
  12563. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12564. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12565. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12566. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12567. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12568. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12569. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12570. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12571. {
  12572. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12573. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12574. return TRUE;
  12575. }
  12576. else
  12577. {
  12578. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12579. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12580. }
  12581. }
  12582. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12583. {
  12584. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12585. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12586. return TRUE;
  12587. }
  12588. //==========================
  12589. // Trigger message
  12590. //==========================
  12591. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12592. {
  12593. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12594. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12595. {
  12596. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12597. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12598. }
  12599. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12600. }
  12601. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12602. {
  12603. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12604. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12605. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12606. }
  12607. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12608. {
  12609. //sendBootNotificationRequest();
  12610. server_sign = FALSE;
  12611. }
  12612. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12613. {
  12614. refreshStartTimer(&clientTime.Heartbeat);
  12615. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12616. }
  12617. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12618. {
  12619. if(connectorIdIsNULL == FALSE)
  12620. {
  12621. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12622. {
  12623. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12624. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12625. }
  12626. }
  12627. else
  12628. {
  12629. for(int idx=0;idx< gunTotalNumber;idx++)
  12630. {
  12631. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12632. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12633. }
  12634. }
  12635. }
  12636. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12637. {
  12638. if(connectorIdIsNULL == FALSE)
  12639. {
  12640. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12641. {
  12642. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12643. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12644. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12645. }
  12646. }
  12647. else
  12648. {
  12649. for(int idx=0;idx< gunTotalNumber;idx++)
  12650. {
  12651. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12652. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12653. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12654. }
  12655. }
  12656. }
  12657. return result;
  12658. }
  12659. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12660. {
  12661. mtrace();
  12662. int result = FAIL;
  12663. int connectorIdInt =0;
  12664. char comfirmstr[20]={0};
  12665. int tempIndex = 0;
  12666. json_object *UnlockConnector;
  12667. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12668. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12669. UnlockConnector = json_tokener_parse(payload);
  12670. if(!is_error(UnlockConnector))
  12671. {
  12672. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12673. {
  12674. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12675. }
  12676. }
  12677. json_object_put(UnlockConnector);
  12678. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12679. if(gunTotalNumber == 0)
  12680. {
  12681. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12682. goto end;
  12683. }
  12684. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12685. {
  12686. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12687. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12688. goto end;
  12689. }
  12690. else
  12691. {
  12692. //check Transaction active
  12693. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12694. {
  12695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12696. {
  12697. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12698. }
  12699. else
  12700. {
  12701. tempIndex = connectorIdInt -1;
  12702. }
  12703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12704. {
  12705. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12706. {
  12707. //stop Transaction
  12708. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12709. }
  12710. }
  12711. }
  12712. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12713. {
  12714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12715. {
  12716. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12717. }
  12718. else
  12719. {
  12720. tempIndex = connectorIdInt -1;
  12721. }
  12722. for (int index = 0; index < CCS_QUANTITY; index++)
  12723. {
  12724. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12725. {
  12726. //stop Transaction
  12727. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12728. }
  12729. }
  12730. }
  12731. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12732. {
  12733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12734. {
  12735. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12736. }
  12737. else
  12738. {
  12739. tempIndex = connectorIdInt -1;
  12740. }
  12741. for (int index = 0; index < GB_QUANTITY; index++)
  12742. {
  12743. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12744. {
  12745. //stop Transaction
  12746. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12747. }
  12748. }
  12749. }
  12750. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12751. {
  12752. tempIndex = connectorIdInt -1;
  12753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12754. {
  12755. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12756. {
  12757. //stop Transaction
  12758. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12759. }
  12760. }
  12761. }
  12762. else
  12763. {
  12764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12765. {
  12766. tempIndex = 2;
  12767. }
  12768. else
  12769. {
  12770. tempIndex = connectorIdInt-1;
  12771. }
  12772. for (int index = 0; index < AC_QUANTITY; index++)
  12773. {
  12774. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12775. {
  12776. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12777. }
  12778. }
  12779. }
  12780. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12781. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12782. result = TRUE;
  12783. return result;
  12784. }
  12785. end:
  12786. //json_object_put(obj); --- remove temporally
  12787. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12788. return result;
  12789. }
  12790. static char UpdateFirmwarepayloadData[300]={0};
  12791. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12792. {
  12793. mtrace();
  12794. int result = FAIL;
  12795. pthread_t t;
  12796. sendUpdateFirmwareConfirmation(uuid);
  12797. memset(UpdateFirmwarepayloadData, 0, 300);
  12798. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12799. if(!interLock.isUpdateFirmwareGoing)
  12800. {
  12801. interLock.isUpdateFirmwareGoing = 1;
  12802. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12803. sleep(1);
  12804. }
  12805. else
  12806. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12807. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12808. return result;
  12809. }
  12810. void *UpdateFirmwareProcess(void *data)
  12811. {
  12812. pthread_detach(pthread_self());
  12813. mtrace();
  12814. int retriesInt =0, retryIntervalInt=0;
  12815. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12816. int port=0;
  12817. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12818. int isSuccess = 0;
  12819. char ftpbuf[1024];
  12820. char temp[1024];
  12821. char * pch;
  12822. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12823. json_object *UpdateFirmware;
  12824. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12825. if(!is_error(UpdateFirmware))
  12826. {
  12827. // Required data
  12828. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12829. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12830. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12831. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12832. // Optional data
  12833. if(json_object_object_get(UpdateFirmware, "retries"))
  12834. {
  12835. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12836. }
  12837. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12838. {
  12839. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12840. }
  12841. }
  12842. json_object_put(UpdateFirmware);
  12843. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12844. memset(path, 0, ARRAY_SIZE(path));
  12845. // Wait retrieveData
  12846. if(strlen(retrieveDatestr) > 10)
  12847. {
  12848. do
  12849. {
  12850. sleep(1);
  12851. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12852. }
  12853. // Ready to download
  12854. system("rm -f /mnt/*");
  12855. if(strncmp(locationstr,"http", 4) == 0)
  12856. {
  12857. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12858. sprintf(ftppath,"/%s", path);
  12859. DEBUG_INFO("locationstr: %s\n", locationstr);
  12860. DEBUG_INFO("protocol: %s\n",protocol);
  12861. DEBUG_INFO("host: %s\n",host);
  12862. DEBUG_INFO("path: %s\n",path);
  12863. DEBUG_INFO("ftppath: %s\n",ftppath);
  12864. int ftppathlen=strlen(ftppath);
  12865. int i=1;
  12866. char filenametemp[50];
  12867. while(i < ftppathlen)
  12868. {
  12869. int len=ftppathlen-i;
  12870. if(ftppath[len]== 47) // '/' ascll code: 47
  12871. {
  12872. DEBUG_INFO("compare '/' all right\n");
  12873. break;
  12874. }
  12875. i=i+1;
  12876. }
  12877. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12878. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12879. filenametemp[i+1] = 0;
  12880. do
  12881. {
  12882. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12883. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12884. sleep(1);
  12885. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12886. if(!isSuccess)
  12887. {
  12888. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12889. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12890. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12891. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12892. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12893. }
  12894. else
  12895. {
  12896. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12897. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12898. }
  12899. retriesInt--;
  12900. }while((isSuccess == 0)&&(retriesInt >= 0));
  12901. }
  12902. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12903. {
  12904. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12905. memset(temp, 0, ARRAY_SIZE(temp));
  12906. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12907. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12908. int ftppathlen=strlen(ftpbuf);
  12909. int i=1;
  12910. char filenametemp[50];
  12911. while(i < ftppathlen)
  12912. {
  12913. int len=ftppathlen-i;
  12914. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12915. {
  12916. DEBUG_INFO(" compare '/' all right\n");
  12917. break;
  12918. }
  12919. i=i+1;
  12920. }
  12921. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12922. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12923. filenametemp[i+1] = 0;
  12924. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12925. pch=strchr(temp,'@');
  12926. if(pch==NULL)
  12927. {
  12928. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12929. protocol, host, &port, path);
  12930. strcpy(user,"anonymous");
  12931. strcpy(password,"");
  12932. }
  12933. else
  12934. {
  12935. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12936. protocol, user, password, host, &port, path);
  12937. }
  12938. sscanf(host,"%[^/]%s",host1, path1);
  12939. sprintf(ftppath,"%s", path1);
  12940. //DEBUG_INFO("protocol =%s\n",protocol);
  12941. //DEBUG_INFO("user =%s\n",user);
  12942. //DEBUG_INFO("password =%s\n",password);
  12943. //DEBUG_INFO("host1 =%s\n",host1);
  12944. //DEBUG_INFO("port =%d\n",port);
  12945. //DEBUG_INFO("path1 =%s\n",path1);
  12946. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12947. //ftpFile(host, user, password, port, ftppath, fname);
  12948. //download firmware pthred
  12949. if(port == 0)
  12950. {
  12951. port = 21;
  12952. }
  12953. do
  12954. {
  12955. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12956. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12957. sleep(1);
  12958. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12959. if(!isSuccess)
  12960. {
  12961. //BulldogUtil.sleepMs(interval*1000);
  12962. DEBUG_INFO("Update firmware request and download file fail.\n");
  12963. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12964. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12965. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12966. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12967. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12968. }
  12969. else
  12970. {
  12971. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12972. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12973. }
  12974. retriesInt--;
  12975. }while((!isSuccess)&&(retriesInt >= 0));
  12976. }
  12977. else
  12978. {
  12979. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12980. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12981. sleep(1);
  12982. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12983. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12984. }
  12985. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12986. interLock.isUpdateFirmwareGoing = 0;
  12987. pthread_exit(NULL);
  12988. }
  12989. int handleCertificateSignedRequest(char *uuid, char *payload)
  12990. {
  12991. mtrace();
  12992. int result = PASS;
  12993. json_object *CertificateSigned;
  12994. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12995. CertificateSigned = json_tokener_parse(payload);
  12996. if(!is_error(CertificateSigned))
  12997. {
  12998. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12999. }
  13000. json_object_put(CertificateSigned);
  13001. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13002. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13003. fclose(fp);
  13004. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13005. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13006. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13007. sendCertificateSignedConfirmation(uuid);
  13008. return result;
  13009. }
  13010. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13011. {
  13012. mtrace();
  13013. int result = PASS;
  13014. json_object *DeleteCertificate;
  13015. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13016. DeleteCertificate = json_tokener_parse(payload);
  13017. if(!is_error(DeleteCertificate))
  13018. {
  13019. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13020. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13021. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13022. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13023. }
  13024. json_object_put(DeleteCertificate);
  13025. /*
  13026. * TODO: Delete certificateSigned process
  13027. */
  13028. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13029. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13030. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13031. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13032. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13033. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13034. sendDeleteCertificateConfirmation(uuid);
  13035. return result;
  13036. }
  13037. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13038. {
  13039. mtrace();
  13040. int result = PASS;
  13041. json_object *ExtendedTriggerMessage;
  13042. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13043. ExtendedTriggerMessage = json_tokener_parse(payload);
  13044. if(!is_error(ExtendedTriggerMessage))
  13045. {
  13046. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13047. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13048. {
  13049. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13050. }
  13051. else
  13052. {
  13053. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13054. }
  13055. }
  13056. json_object_put(ExtendedTriggerMessage);
  13057. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13058. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13059. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13060. {
  13061. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13062. }
  13063. else
  13064. {
  13065. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13066. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13067. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13068. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13069. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13070. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13071. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13072. {
  13073. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13074. }
  13075. else
  13076. {
  13077. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13078. }
  13079. }
  13080. sendExtendedTriggerMessageConfirmation(uuid);
  13081. //==========================
  13082. // Trigger message
  13083. //==========================
  13084. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13085. {
  13086. //sendBootNotificationRequest();
  13087. server_sign = FALSE;
  13088. }
  13089. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13090. {
  13091. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13092. }
  13093. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13094. {
  13095. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13096. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13097. {
  13098. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13099. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13100. }
  13101. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13102. }
  13103. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13104. {
  13105. refreshStartTimer(&clientTime.Heartbeat);
  13106. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13107. }
  13108. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13109. {
  13110. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13111. {
  13112. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13113. }
  13114. else
  13115. {
  13116. for(int idx=0;idx< gunTotalNumber;idx++)
  13117. {
  13118. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13119. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13120. }
  13121. }
  13122. }
  13123. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13124. {
  13125. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13126. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13127. {
  13128. 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\" &");
  13129. }
  13130. }
  13131. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13132. {
  13133. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13134. {
  13135. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13136. }
  13137. else
  13138. {
  13139. for(int idx=0;idx< gunTotalNumber;idx++)
  13140. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13141. }
  13142. }
  13143. return result;
  13144. }
  13145. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13146. {
  13147. mtrace();
  13148. int result = PASS;
  13149. json_object *GetInstalledCertificateIds;
  13150. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13151. GetInstalledCertificateIds = json_tokener_parse(payload);
  13152. if(!is_error(GetInstalledCertificateIds))
  13153. {
  13154. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13155. }
  13156. json_object_put(GetInstalledCertificateIds);
  13157. /*
  13158. * TODO: Return installed certificate process
  13159. */
  13160. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13161. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13162. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13163. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13164. sendGetInstalledCertificateIdsConfirmation(uuid);
  13165. return result;
  13166. }
  13167. int handleGetLogRequest(char *uuid, char *payload)
  13168. {
  13169. mtrace();
  13170. int result = PASS;
  13171. json_object *GetLog;
  13172. DEBUG_INFO("handleGetLogRequest...\n");
  13173. GetLog = json_tokener_parse(payload);
  13174. if(!is_error(GetLog))
  13175. {
  13176. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13177. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13178. if(json_object_object_get(GetLog, "retries") != NULL)
  13179. {
  13180. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13181. }
  13182. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13183. {
  13184. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13185. }
  13186. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13187. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13188. {
  13189. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13190. }
  13191. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13192. {
  13193. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13194. }
  13195. }
  13196. json_object_put(GetLog);
  13197. /*
  13198. * TODO: Upload log process
  13199. */
  13200. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13201. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13202. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13203. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13204. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13205. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13206. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13207. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13208. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13209. sendGetLogConfirmation(uuid);
  13210. return result;
  13211. }
  13212. int handleInstallCertificateRequest(char *uuid, char *payload)
  13213. {
  13214. mtrace();
  13215. int result = PASS;
  13216. json_object *InstallCertificate;
  13217. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13218. InstallCertificate = json_tokener_parse(payload);
  13219. if(!is_error(InstallCertificate))
  13220. {
  13221. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13222. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13223. /*
  13224. * TODO: Install certificate process
  13225. */
  13226. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13227. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13228. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13229. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13230. sendInstallCertificateConfirmation(uuid);
  13231. }
  13232. json_object_put(InstallCertificate);
  13233. return result;
  13234. }
  13235. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13236. {
  13237. mtrace();
  13238. int result = PASS;
  13239. json_object *SignedUpdateFirmware;
  13240. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13241. SignedUpdateFirmware = json_tokener_parse(payload);
  13242. if(!is_error(SignedUpdateFirmware))
  13243. {
  13244. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13245. {
  13246. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13247. }
  13248. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13249. {
  13250. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13251. }
  13252. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13253. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13254. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13255. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13256. {
  13257. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13258. }
  13259. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13260. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13261. }
  13262. json_object_put(SignedUpdateFirmware);
  13263. /*
  13264. * TODO: Upgrade firmware process
  13265. */
  13266. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13267. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13268. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13269. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13270. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13271. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13272. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13273. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13274. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13275. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13276. sendInstallCertificateConfirmation(uuid);
  13277. return result;
  13278. }
  13279. int handleUnknownRequest(char *uuid, char *payload)
  13280. {
  13281. mtrace();
  13282. int result = PASS;
  13283. DEBUG_INFO("handleUnknownRequest...\n");
  13284. sendUnknownConfirmation(uuid);
  13285. result = PASS;
  13286. return result;
  13287. }
  13288. //==========================================
  13289. // Handle server response routine
  13290. //==========================================
  13291. void handleAuthorizeResponse(char *payload, int gun_index)
  13292. {
  13293. mtrace();
  13294. char expiryDatestr[30]={0};
  13295. char parentIdTagstr[20]={0};
  13296. char statusstr[20]={0};
  13297. int expiryDateISNULL=FALSE;
  13298. int parentIdTagISNULL=FALSE;
  13299. DEBUG_INFO("handleAuthorizeResponse...\n");
  13300. json_object *Authorize;
  13301. Authorize = json_tokener_parse(payload);
  13302. if(!is_error(Authorize))
  13303. {
  13304. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13305. {
  13306. // Required data
  13307. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13308. // Optional data
  13309. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13310. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13311. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13312. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13313. }
  13314. }
  13315. json_object_put(Authorize);
  13316. if(expiryDateISNULL == FALSE)
  13317. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13318. if(parentIdTagISNULL == FALSE)
  13319. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13320. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13321. //Update idTag information to authorization cache if supproted
  13322. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13323. {
  13324. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13325. }
  13326. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13327. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13328. authorizeRetryTimes = 0;
  13329. }
  13330. void handleBootNotificationResponse(char *payload, int gun_index)
  13331. {
  13332. mtrace();
  13333. char statusStr[12]={0};
  13334. char currentTimeStr[30]={0};
  13335. int intervalInt = 0;
  13336. DEBUG_INFO("handleBootNotificationResponse...\n");
  13337. json_object *BootNotification;
  13338. BootNotification = json_tokener_parse(payload);
  13339. if(!is_error(BootNotification))
  13340. {
  13341. // Required data
  13342. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13343. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13344. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13345. }
  13346. json_object_put(BootNotification);
  13347. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13348. BootNotificationInterval = intervalInt;
  13349. //write back to ShmOCPP16Data->BootNotification
  13350. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13351. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13352. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13353. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13354. {
  13355. if((intervalInt == 0) || (intervalInt >= 10))
  13356. {
  13357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13358. HeartBeatWaitTime = intervalInt;
  13359. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13360. }
  13361. server_sign = TRUE;
  13362. server_pending =FALSE;
  13363. }
  13364. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13365. {
  13366. server_pending = TRUE;
  13367. }
  13368. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13369. srand(time(NULL));
  13370. refreshStartTimer(&clientTime.Heartbeat);
  13371. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13372. SetOcppConnStatus(TRUE);
  13373. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13374. }
  13375. void handleDataTransferResponse(char *payload, int gun_index)
  13376. {
  13377. json_object *DataTransfer = json_tokener_parse(payload);
  13378. if(!is_error(DataTransfer))
  13379. {
  13380. // Required data
  13381. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13382. // Optional data
  13383. if(json_object_object_get(DataTransfer, "data") != NULL)
  13384. {
  13385. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13386. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13387. if(!is_error(Data))
  13388. {
  13389. if(json_object_object_get(Data, "msgId") != NULL)
  13390. {
  13391. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13392. {
  13393. 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")));
  13394. }
  13395. }
  13396. }
  13397. json_object_put(Data);
  13398. }
  13399. }
  13400. json_object_put(DataTransfer);
  13401. }
  13402. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13403. {
  13404. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13405. //struct json_object *obj;
  13406. // obj = json_tokener_parse(payload);
  13407. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13408. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13409. //No fields are defined.
  13410. }
  13411. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13412. {
  13413. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13414. //struct json_object *obj;
  13415. // obj = json_tokener_parse(payload);
  13416. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13417. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13418. //No fields are defined.
  13419. }
  13420. void handleHeartbeatResponse(char *payload, int gun_index)
  13421. {
  13422. mtrace();
  13423. DEBUG_INFO("handleHeartbeatResponse...\n");
  13424. json_object *Heartbeat;
  13425. Heartbeat = json_tokener_parse(payload);
  13426. if(!is_error(Heartbeat))
  13427. {
  13428. // Required data
  13429. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13430. }
  13431. json_object_put(Heartbeat);
  13432. if(FirstHeartBeat == 0)
  13433. {
  13434. FirstHeartBeat = 1;
  13435. DEBUG_INFO("FirstHeartBeat \n");
  13436. }
  13437. HeartBeatWithNOResponse = 0;
  13438. refreshStartTimer(&clientTime.Heartbeat);
  13439. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13440. }
  13441. void handleMeterValuesResponse(char *payload, int gun_index)
  13442. {
  13443. mtrace();
  13444. DEBUG_INFO("handleMeterValuesResponse...\n");
  13445. isQueueSendable = 1;
  13446. }
  13447. void handleStartTransactionResponse(char *payload, int gun_index)
  13448. {
  13449. mtrace();
  13450. //int transactionIdInt = 0;
  13451. FILE *outfile;
  13452. char data[100]={0};
  13453. DEBUG_INFO("handleStartTransactionResponse...\n");
  13454. json_object *StartTransaction;
  13455. StartTransaction = json_tokener_parse(payload);
  13456. if(!is_error(StartTransaction))
  13457. {
  13458. // Required data
  13459. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13460. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13461. // Optional data
  13462. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13463. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13464. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13465. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13466. }
  13467. json_object_put(StartTransaction);
  13468. isQueueSendable = 1;
  13469. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13470. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13471. //-----------Start : write to the Queue TransactionId file -----------------//
  13472. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13473. {}
  13474. else
  13475. {
  13476. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13477. if(log == NULL)
  13478. {
  13479. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13480. return ;
  13481. }
  13482. else
  13483. {
  13484. fclose(log);
  13485. }
  13486. }
  13487. // open file for writing
  13488. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13489. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13490. {
  13491. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13492. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13493. fputs(data, outfile);
  13494. fclose (outfile);
  13495. }
  13496. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13497. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13498. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13499. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13500. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13501. }
  13502. void handleStatusNotificationResponse(char *payload, int gun_index)
  13503. {
  13504. mtrace();
  13505. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13506. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13507. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13508. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13509. }
  13510. void handleStopTransactionnResponse(char *payload, int gun_index)
  13511. {
  13512. mtrace();
  13513. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13514. json_object *StopTransaction;
  13515. StopTransaction = json_tokener_parse(payload);
  13516. if(!is_error(StopTransaction))
  13517. {
  13518. // Optional data
  13519. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13520. {
  13521. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13522. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13523. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13524. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13526. }
  13527. }
  13528. json_object_put(StopTransaction);
  13529. isQueueSendable = 1;
  13530. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13531. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13532. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13533. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13534. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13535. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13536. }
  13537. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13538. {
  13539. mtrace();
  13540. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13541. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13542. }
  13543. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13544. {
  13545. mtrace();
  13546. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13547. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13548. }
  13549. void handleSignCertificateResponse(char *payload, int gun_index)
  13550. {
  13551. mtrace();
  13552. DEBUG_INFO("handleSignCertificateResponse...\n");
  13553. json_object *SignCertificate;
  13554. SignCertificate = json_tokener_parse(payload);
  13555. if(!is_error(SignCertificate))
  13556. {
  13557. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13558. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13559. }
  13560. json_object_put(SignCertificate);
  13561. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13562. }
  13563. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13564. {
  13565. mtrace();
  13566. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13567. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13568. }
  13569. //==========================================
  13570. // Handle Error routine
  13571. //==========================================
  13572. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13573. {
  13574. mtrace();
  13575. #ifdef SystemLogMessage
  13576. DEBUG_INFO("errorCode: %s\n", errorCode);
  13577. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13578. DEBUG_INFO("errorDetails: %s\n", payload);
  13579. #endif
  13580. }
  13581. //===============================================
  13582. // Common routine
  13583. //===============================================
  13584. int initialConfigurationTable(void)
  13585. {
  13586. //clock_t start_t, end_t, total_t;
  13587. FILE *fp;
  13588. FILE *outfile;
  13589. char str[512]={0};
  13590. char sstr[256]={0};
  13591. int c = 0;
  13592. char *loc;
  13593. int confVersion = 13;
  13594. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13595. //start_t = clock();
  13596. //printf("Starting of the program, start_t = %ld\n", start_t);
  13597. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13598. // Check configuration file size is correct
  13599. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13600. {
  13601. struct stat st;
  13602. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13603. if(st.st_size < 3100)
  13604. {
  13605. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13606. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13607. }
  13608. }
  13609. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13610. {
  13611. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13612. if(outfile == NULL)
  13613. {
  13614. DEBUG_INFO("Error opening file\n");
  13615. return FALSE;
  13616. }
  13617. /*Core Profile*/
  13618. //AllowOfflineTxForUnknownId
  13619. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13623. //AuthorizationCacheEnabled
  13624. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13628. //AuthorizeRemoteTxRequests
  13629. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13633. //BlinkRepeat
  13634. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13638. //ClockAlignedDataInterval
  13639. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13643. //ConnectionTimeOut
  13644. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13648. //GetConfigurationMaxKeys
  13649. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13653. // HeartbeatInterval
  13654. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13658. // LightIntensity
  13659. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13663. // LocalAuthorizeOffline
  13664. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13668. // LocalPreAuthorize
  13669. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13673. // MaxEnergyOnInvalidId
  13674. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13678. // MeterValuesAlignedData
  13679. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13681. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13682. 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" );
  13683. else
  13684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13686. // MeterValuesAlignedDataMaxLength
  13687. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13691. else
  13692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13694. // MeterValuesSampledData
  13695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13698. 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" );
  13699. else
  13700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13702. // MeterValuesSampledDataMaxLength
  13703. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13705. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13707. else
  13708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13710. // MeterValueSampleInterval
  13711. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13715. // MinimumStatusDuration
  13716. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13719. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13721. // NumberOfConnectors
  13722. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13725. {
  13726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13727. }
  13728. else
  13729. {
  13730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13731. }
  13732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13733. // ResetRetries
  13734. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13738. // ConnectorPhaseRotation
  13739. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13743. // ConnectorPhaseRotationMaxLength
  13744. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13748. // StopTransactionOnEVSideDisconnect
  13749. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13753. // StopTransactionOnInvalidId
  13754. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13758. // StopTxnAlignedData
  13759. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13763. // StopTxnAlignedDataMaxLength
  13764. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13768. // StopTxnSampledData
  13769. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13771. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13773. else
  13774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13776. // StopTxnSampledDataMaxLength
  13777. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13780. {
  13781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13782. }
  13783. else
  13784. {
  13785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13786. }
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13788. // SupportedFeatureProfiles
  13789. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13793. // SupportedFeatureProfilesMaxLength
  13794. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13798. // TransactionMessageAttempts
  13799. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13802. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13804. // TransactionMessageRetryInterval
  13805. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13808. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13810. // UnlockConnectorOnEVSideDisconnect
  13811. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13815. // WebSocketPingInterval
  13816. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13820. // QueueOffLineMeterValues
  13821. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13825. // AuthorizationKey
  13826. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13830. // SecurityProfile
  13831. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13835. // DefaultPrice
  13836. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13840. // CustomDisplayCostAndPrice
  13841. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13845. // CustomIdleFeeAfterStop
  13846. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13850. // TimeOffset
  13851. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13855. // NextTimeOffsetTransitionDateTime
  13856. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13860. // TimeOffsetNextTransition
  13861. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13865. // SystemUptimeSec
  13866. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13870. // FreeVend
  13871. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13875. // FreeVendIdtag
  13876. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13880. // OcppServer
  13881. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13883. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13885. // MaintainServer
  13886. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13888. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13890. // StatusNotificationPeriodically
  13891. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13895. // StatusNotificationInterval
  13896. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13900. // Configuration Version
  13901. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13905. //* Local Auth List Management Profile*/
  13906. #if 0
  13907. //For OCTT Test Case
  13908. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13911. #endif
  13912. #if 1
  13913. //LocalAuthListEnabled
  13914. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13918. #endif
  13919. //LocalAuthListMaxLength
  13920. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13924. //SendLocalListMaxLength
  13925. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13929. //ReserveConnectorZeroSupported
  13930. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13934. //* Smart Charging Profile */
  13935. //ChargeProfileMaxStackLevel
  13936. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13940. // ChargingScheduleAllowedChargingRateUnit
  13941. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13945. // ChargingScheduleMaxPeriods
  13946. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13950. // ConnectorSwitch3to1PhaseSupported
  13951. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13955. // MaxChargingProfilesInstalled
  13956. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13960. fclose(outfile);
  13961. }
  13962. else
  13963. {
  13964. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13965. char keystr[60]={0};
  13966. char readonlystr[10]={0};
  13967. char valuestr[256]={0};
  13968. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13969. if(fp == NULL) {
  13970. DEBUG_INFO("Error opening file");
  13971. return FALSE;
  13972. }
  13973. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13974. {
  13975. //DEBUG_INFO("Get Configuration \n");
  13976. if(strlen(str) > 0)
  13977. {
  13978. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13979. //*************************key*********************************/
  13980. if(strstr(str, "key") != NULL)
  13981. {
  13982. loc = strstr(str, "key");
  13983. c = 0;
  13984. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13985. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13986. {
  13987. sstr[c] = loc[strlen("key")+3+c];
  13988. c++;
  13989. }
  13990. sstr[c] = '\0';
  13991. strcpy(keystr,sstr);
  13992. }
  13993. //*************************readonly*********************************/
  13994. if(strstr(str, "readonly") != NULL)
  13995. {
  13996. loc = strstr(str, "readonly");
  13997. c = 0;
  13998. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13999. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14000. {
  14001. sstr[c] = loc[strlen("readonly")+2+c];
  14002. c++;
  14003. }
  14004. sstr[c] = '\0';
  14005. strcpy(readonlystr,sstr);
  14006. }
  14007. //*************************value*********************************/
  14008. if(strstr(str, "value") != NULL)
  14009. {
  14010. loc = strstr(str, "value");
  14011. c = 0;
  14012. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14013. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14014. {
  14015. sstr[c] = loc[strlen("value")+3+c];
  14016. c++;
  14017. }
  14018. sstr[c] = '\0';
  14019. strcpy(valuestr,sstr);
  14020. }
  14021. // DEBUG_INFO("keystr=%s\n",keystr);
  14022. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14023. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14024. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14025. {
  14026. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14027. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14029. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14030. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14031. }
  14032. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14033. {
  14034. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14035. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14037. }
  14038. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14039. {
  14040. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14042. }
  14043. if(strcmp(keystr, "BlinkRepeat") == 0)
  14044. {
  14045. //Charger.BlinkRepeat = Integer.parseInt(value);
  14046. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14048. }
  14049. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14050. {
  14051. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14053. }
  14054. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14055. {
  14056. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14058. }
  14059. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14060. {
  14061. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14063. }
  14064. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14065. {
  14066. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14068. HeartBeatWaitTime = atoi(valuestr);
  14069. }
  14070. if(strcmp(keystr, "LightIntensity") == 0)
  14071. {
  14072. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14074. }
  14075. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14076. {
  14077. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14079. }
  14080. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14081. {
  14082. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14084. }
  14085. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14086. {
  14087. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14089. }
  14090. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14091. {
  14092. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14094. }
  14095. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14096. {
  14097. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14099. }
  14100. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14101. {
  14102. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14104. }
  14105. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14106. {
  14107. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14109. }
  14110. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14111. {
  14112. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14114. }
  14115. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14116. {
  14117. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14119. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14120. }
  14121. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14122. {
  14123. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14125. }
  14126. if(strcmp(keystr, "ResetRetries") == 0)
  14127. {
  14128. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14130. }
  14131. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14132. {
  14133. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14135. }
  14136. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14137. {
  14138. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14140. }
  14141. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14142. {
  14143. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14145. }
  14146. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14147. {
  14148. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14150. }
  14151. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14152. {
  14153. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14155. }
  14156. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14157. {
  14158. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14160. }
  14161. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14162. {
  14163. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14165. }
  14166. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14167. {
  14168. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14170. }
  14171. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14172. {
  14173. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14175. }
  14176. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14177. {
  14178. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14180. }
  14181. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14182. {
  14183. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14185. TransactionMessageAttemptsValue = atoi(valuestr);
  14186. }
  14187. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14188. {
  14189. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14191. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14192. }
  14193. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14194. {
  14195. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14197. }
  14198. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14199. {
  14200. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14202. }
  14203. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14204. {
  14205. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14207. }
  14208. if(strcmp(keystr, "AuthorizationKey") == 0)
  14209. {
  14210. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14211. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14213. }
  14214. if(strcmp(keystr, "SecurityProfile") == 0)
  14215. {
  14216. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14218. }
  14219. if(strcmp(keystr, "DefaultPrice") == 0)
  14220. {
  14221. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14223. }
  14224. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14225. {
  14226. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14228. }
  14229. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14230. {
  14231. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14233. }
  14234. if(strcmp(keystr, "TimeOffset") == 0)
  14235. {
  14236. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14238. }
  14239. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14240. {
  14241. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14243. }
  14244. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14245. {
  14246. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14248. }
  14249. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14250. {
  14251. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14253. }
  14254. if(strcmp(keystr, "FreeVend") == 0)
  14255. {
  14256. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14258. }
  14259. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14260. {
  14261. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14263. }
  14264. if(strcmp(keystr, "OcppServer") == 0)
  14265. {
  14266. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14267. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14268. }
  14269. if(strcmp(keystr, "MaintainServer") == 0)
  14270. {
  14271. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14272. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14273. }
  14274. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14275. {
  14276. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14278. }
  14279. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14280. {
  14281. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14283. }
  14284. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14285. {
  14286. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14288. }
  14289. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14290. {
  14291. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14293. }
  14294. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14295. {
  14296. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14298. }
  14299. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14300. {
  14301. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14303. }
  14304. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14305. {
  14306. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14308. }
  14309. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14310. {
  14311. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14313. }
  14314. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14315. {
  14316. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14318. }
  14319. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14320. {
  14321. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14323. }
  14324. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14325. {
  14326. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14328. }
  14329. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14330. {
  14331. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14333. }
  14334. }
  14335. }
  14336. fclose(fp);
  14337. }
  14338. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14339. {
  14340. return PASS;
  14341. }
  14342. else
  14343. {
  14344. return FAIL;
  14345. }
  14346. }
  14347. void StoreConfigurationTable(void)
  14348. {
  14349. FILE *outfile;
  14350. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14351. if(outfile == NULL)
  14352. {
  14353. DEBUG_INFO("Error opening file");
  14354. return ;
  14355. }
  14356. /*Core Profile*/
  14357. //AllowOfflineTxForUnknownId
  14358. /*
  14359. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14360. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14363. */
  14364. //DEBUG_INFO("data=%s\n",data);
  14365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14366. //AuthorizationCacheEnabled
  14367. /*
  14368. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14371. */
  14372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14373. //AuthorizeRemoteTxRequests
  14374. /*
  14375. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14378. */
  14379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14380. //BlinkRepeat
  14381. /*
  14382. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14385. */
  14386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14387. //ClockAlignedDataInterval
  14388. /*
  14389. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14392. */
  14393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14394. //ConnectionTimeOut
  14395. /*
  14396. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14399. */
  14400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14401. //GetConfigurationMaxKeys
  14402. /*
  14403. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14406. */
  14407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14408. // HeartbeatInterval
  14409. /*
  14410. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14413. */
  14414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14415. // LightIntensity
  14416. /*
  14417. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14420. */
  14421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14422. // LocalAuthorizeOffline
  14423. /*
  14424. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14427. */
  14428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14429. // LocalPreAuthorize
  14430. /*
  14431. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14434. */
  14435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14436. // MaxEnergyOnInvalidId
  14437. /*
  14438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14441. */
  14442. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14444. // MeterValuesAlignedData
  14445. /*
  14446. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14449. */
  14450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14451. // MeterValuesAlignedDataMaxLength
  14452. /*
  14453. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14456. */
  14457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14458. // MeterValuesSampledData
  14459. /*
  14460. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14463. */
  14464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14465. // MeterValuesSampledDataMaxLength
  14466. /*
  14467. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14470. */
  14471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14472. // MeterValueSampleInterval
  14473. /*
  14474. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14477. */
  14478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14479. // MinimumStatusDuration
  14480. /*
  14481. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14484. */
  14485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14486. // NumberOfConnectors
  14487. /*
  14488. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14491. {
  14492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14493. }
  14494. else
  14495. {
  14496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14497. }
  14498. */
  14499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14500. // ResetRetries
  14501. /*
  14502. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14505. */
  14506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14507. // ConnectorPhaseRotation
  14508. /*
  14509. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14512. */
  14513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14514. // ConnectorPhaseRotationMaxLength
  14515. /*
  14516. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14519. */
  14520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14521. // StopTransactionOnEVSideDisconnect
  14522. /*
  14523. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14526. */
  14527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14528. // StopTransactionOnInvalidId
  14529. /*
  14530. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14533. */
  14534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14535. // StopTxnAlignedData
  14536. /*
  14537. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14540. */
  14541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14542. // StopTxnAlignedDataMaxLength
  14543. /*
  14544. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14547. */
  14548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14549. // StopTxnSampledData
  14550. /*
  14551. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14554. */
  14555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14556. // StopTxnSampledDataMaxLength
  14557. /*
  14558. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14561. */
  14562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14563. // SupportedFeatureProfiles
  14564. /*
  14565. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14568. */
  14569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14570. // SupportedFeatureProfilesMaxLength
  14571. /*
  14572. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14575. */
  14576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14577. // TransactionMessageAttempts
  14578. /*
  14579. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14582. */
  14583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14584. // TransactionMessageRetryInterval
  14585. /*
  14586. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14589. */
  14590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14591. // UnlockConnectorOnEVSideDisconnect
  14592. /*
  14593. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14596. */
  14597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14598. // WebSocketPingInterval
  14599. /*
  14600. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14603. */
  14604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14605. // QueueOffLineMeterValues
  14606. /*
  14607. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14610. */
  14611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14612. // AuthorizationKey
  14613. /*
  14614. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14617. */
  14618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14619. // SecurityProfile
  14620. /*
  14621. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14624. */
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14626. // DefaultPrice
  14627. /*
  14628. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14631. */
  14632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14633. // CustomDisplayCostAndPrice
  14634. /*
  14635. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14638. */
  14639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14640. // CustomIdleFeeAfterStop
  14641. /*
  14642. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14645. */
  14646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14647. // TimeOffset
  14648. /*
  14649. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14652. */
  14653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14654. // NextTimeOffsetTransitionDateTime
  14655. /*
  14656. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14659. */
  14660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14661. // TimeOffsetNextTransition
  14662. /*
  14663. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14666. */
  14667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14668. // SystemUptimeSec
  14669. /*
  14670. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14673. */
  14674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14675. // FreeVend
  14676. /*
  14677. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14680. */
  14681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14682. // FreeVendIdtag
  14683. /*
  14684. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14687. */
  14688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14689. // OcppServer
  14690. /*
  14691. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14694. */
  14695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14696. // MaintainServer
  14697. /*
  14698. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14701. */
  14702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14703. // StatusNotificationPeriodically
  14704. /*
  14705. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14708. */
  14709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14710. // StatusNotificationInterval
  14711. /*
  14712. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14715. */
  14716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14717. // ConfigurationVersion
  14718. /*
  14719. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14722. */
  14723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14724. //* Local Auth List Management Profile*/
  14725. //LocalAuthListEnabled
  14726. /*
  14727. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14730. */
  14731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14732. //LocalAuthListMaxLength
  14733. /*
  14734. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14737. */
  14738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14739. //SendLocalListMaxLength
  14740. /*
  14741. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14744. */
  14745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14746. //ReserveConnectorZeroSupported
  14747. /*
  14748. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14751. */
  14752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14753. //* Smart Charging Profile */
  14754. //ChargeProfileMaxStackLevel
  14755. /*
  14756. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14759. */
  14760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14761. // ChargingScheduleAllowedChargingRateUnit
  14762. /*
  14763. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14766. */
  14767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14768. // ChargingScheduleMaxPeriods
  14769. /*
  14770. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14773. */
  14774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14775. // ConnectorSwitch3to1PhaseSupported
  14776. /*
  14777. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14780. */
  14781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14782. // MaxChargingProfilesInstalled
  14783. /*
  14784. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14787. */
  14788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14789. fclose(outfile);
  14790. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14791. }
  14792. void getKeyValue(char *keyReq)
  14793. {
  14794. int isEmpty = FALSE;
  14795. int isKnowKey = FALSE;
  14796. DEBUG_INFO("keyReq = %s\n", keyReq);
  14797. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14798. isEmpty = TRUE;
  14799. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14800. {
  14801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14804. {
  14805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14806. }
  14807. else
  14808. {
  14809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14810. }
  14811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14812. isKnowKey = TRUE;
  14813. }
  14814. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14815. {
  14816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14819. {
  14820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14821. }
  14822. else
  14823. {
  14824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14825. }
  14826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14827. isKnowKey = TRUE;
  14828. }
  14829. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14830. {
  14831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14834. {
  14835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14836. }
  14837. else
  14838. {
  14839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14840. }
  14841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14842. isKnowKey = TRUE;
  14843. }
  14844. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14845. {
  14846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14849. {
  14850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14851. }
  14852. else
  14853. {
  14854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14855. }
  14856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14857. isKnowKey = TRUE;
  14858. }
  14859. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14860. {
  14861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14864. {
  14865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14866. }
  14867. else
  14868. {
  14869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14870. }
  14871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14872. isKnowKey = TRUE;
  14873. }
  14874. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14875. {
  14876. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14879. {
  14880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14881. }
  14882. else
  14883. {
  14884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14885. }
  14886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14887. isKnowKey = TRUE;
  14888. }
  14889. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14890. {
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14894. {
  14895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14896. }
  14897. else
  14898. {
  14899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14900. }
  14901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14902. isKnowKey = TRUE;
  14903. }
  14904. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14905. {
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14909. {
  14910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14911. }
  14912. else
  14913. {
  14914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14915. }
  14916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14917. isKnowKey = TRUE;
  14918. }
  14919. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14920. {
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14924. {
  14925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14926. }
  14927. else
  14928. {
  14929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14930. }
  14931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14932. isKnowKey = TRUE;
  14933. }
  14934. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14935. {
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14939. {
  14940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14941. }
  14942. else
  14943. {
  14944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14945. }
  14946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14947. isKnowKey = TRUE;
  14948. }
  14949. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14950. {
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14953. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14954. {
  14955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14956. }
  14957. else
  14958. {
  14959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14960. }
  14961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14962. isKnowKey = TRUE;
  14963. }
  14964. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14965. {
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14969. {
  14970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14971. }
  14972. else
  14973. {
  14974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14975. }
  14976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14977. isKnowKey = TRUE;
  14978. }
  14979. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14980. {
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14984. {
  14985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14986. }
  14987. else
  14988. {
  14989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14990. }
  14991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14992. isKnowKey = TRUE;
  14993. }
  14994. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14995. {
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14999. {
  15000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15001. }
  15002. else
  15003. {
  15004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15005. }
  15006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15007. isKnowKey = TRUE;
  15008. }
  15009. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15010. {
  15011. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15014. {
  15015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15016. }
  15017. else
  15018. {
  15019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15020. }
  15021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15022. isKnowKey = TRUE;
  15023. }
  15024. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15025. {
  15026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15029. {
  15030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15031. }
  15032. else
  15033. {
  15034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15035. }
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15037. isKnowKey = TRUE;
  15038. }
  15039. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15040. {
  15041. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15044. {
  15045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15046. }
  15047. else
  15048. {
  15049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15050. }
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15052. isKnowKey = TRUE;
  15053. }
  15054. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15055. {
  15056. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15059. {
  15060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15061. }
  15062. else
  15063. {
  15064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15065. }
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15067. isKnowKey = TRUE;
  15068. }
  15069. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15070. {
  15071. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15074. {
  15075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15076. }
  15077. else
  15078. {
  15079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15080. }
  15081. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15083. isKnowKey = TRUE;
  15084. }
  15085. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15086. {
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15090. {
  15091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15092. }
  15093. else
  15094. {
  15095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15096. }
  15097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15098. isKnowKey = TRUE;
  15099. }
  15100. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15101. {
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15105. {
  15106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15107. }
  15108. else
  15109. {
  15110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15111. }
  15112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15113. isKnowKey = TRUE;
  15114. }
  15115. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15116. {
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15120. {
  15121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15122. }
  15123. else
  15124. {
  15125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15126. }
  15127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15128. isKnowKey = TRUE;
  15129. }
  15130. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15131. {
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15135. {
  15136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15137. }
  15138. else
  15139. {
  15140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15141. }
  15142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15143. isKnowKey = TRUE;
  15144. }
  15145. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15146. {
  15147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15150. {
  15151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15152. }
  15153. else
  15154. {
  15155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15156. }
  15157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15158. isKnowKey = TRUE;
  15159. }
  15160. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15161. {
  15162. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15165. {
  15166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15167. }
  15168. else
  15169. {
  15170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15171. }
  15172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15173. isKnowKey = TRUE;
  15174. }
  15175. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15176. {
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15180. {
  15181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15182. }
  15183. else
  15184. {
  15185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15186. }
  15187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15188. isKnowKey = TRUE;
  15189. }
  15190. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15191. {
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15195. {
  15196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15197. }
  15198. else
  15199. {
  15200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15201. }
  15202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15203. isKnowKey = TRUE;
  15204. }
  15205. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15206. {
  15207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15210. {
  15211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15212. }
  15213. else
  15214. {
  15215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15216. }
  15217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15218. isKnowKey = TRUE;
  15219. }
  15220. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15221. {
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15225. {
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15227. }
  15228. else
  15229. {
  15230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15231. }
  15232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15233. isKnowKey = TRUE;
  15234. }
  15235. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15236. {
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15240. {
  15241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15242. }
  15243. else
  15244. {
  15245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15246. }
  15247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15248. isKnowKey = TRUE;
  15249. }
  15250. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15251. {
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15255. {
  15256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15257. }
  15258. else
  15259. {
  15260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15261. }
  15262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15263. isKnowKey = TRUE;
  15264. }
  15265. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15266. {
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15270. {
  15271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15272. }
  15273. else
  15274. {
  15275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15276. }
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15278. isKnowKey = TRUE;
  15279. }
  15280. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15281. {
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15285. {
  15286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15287. }
  15288. else
  15289. {
  15290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15291. }
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15293. isKnowKey = TRUE;
  15294. }
  15295. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15296. {
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15300. {
  15301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15302. }
  15303. else
  15304. {
  15305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15306. }
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15308. isKnowKey = TRUE;
  15309. }
  15310. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15311. {
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15315. {
  15316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15317. }
  15318. else
  15319. {
  15320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15321. }
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15323. isKnowKey = TRUE;
  15324. }
  15325. /*
  15326. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15327. {
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15331. {
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15333. }
  15334. else
  15335. {
  15336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15337. }
  15338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15339. isKnowKey = TRUE;
  15340. }*/
  15341. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15342. {
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15346. {
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15348. }
  15349. else
  15350. {
  15351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15352. }
  15353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15354. isKnowKey = TRUE;
  15355. }
  15356. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15357. {
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15361. {
  15362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15363. }
  15364. else
  15365. {
  15366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15367. }
  15368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15369. isKnowKey = TRUE;
  15370. }
  15371. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15372. {
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15376. {
  15377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15378. }
  15379. else
  15380. {
  15381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15382. }
  15383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15384. isKnowKey = TRUE;
  15385. }
  15386. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15387. {
  15388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15391. {
  15392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15393. }
  15394. else
  15395. {
  15396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15397. }
  15398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15399. isKnowKey = TRUE;
  15400. }
  15401. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15402. {
  15403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15406. {
  15407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15408. }
  15409. else
  15410. {
  15411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15412. }
  15413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15414. isKnowKey = TRUE;
  15415. }
  15416. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15417. {
  15418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15421. {
  15422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15423. }
  15424. else
  15425. {
  15426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15427. }
  15428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15429. isKnowKey = TRUE;
  15430. }
  15431. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15432. {
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15436. {
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15438. }
  15439. else
  15440. {
  15441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15442. }
  15443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15444. isKnowKey = TRUE;
  15445. }
  15446. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15447. {
  15448. struct sysinfo s_info;
  15449. int error = sysinfo(&s_info);
  15450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15453. {
  15454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15455. }
  15456. else
  15457. {
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15459. }
  15460. if(error != 0)
  15461. {
  15462. DEBUG_WARN("System uptime get error: %d\n", error);
  15463. }
  15464. else
  15465. {
  15466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15467. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15468. }
  15469. isKnowKey = TRUE;
  15470. }
  15471. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15472. {
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15476. {
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15478. }
  15479. else
  15480. {
  15481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15482. }
  15483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15484. isKnowKey = TRUE;
  15485. }
  15486. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15487. {
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15491. {
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15493. }
  15494. else
  15495. {
  15496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15497. }
  15498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15499. isKnowKey = TRUE;
  15500. }
  15501. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15502. {
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15508. }
  15509. else
  15510. {
  15511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15512. }
  15513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15514. isKnowKey = TRUE;
  15515. }
  15516. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15517. {
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15523. }
  15524. else
  15525. {
  15526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15527. }
  15528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15529. isKnowKey = TRUE;
  15530. }
  15531. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15532. {
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15538. }
  15539. else
  15540. {
  15541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15542. }
  15543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15544. isKnowKey = TRUE;
  15545. }
  15546. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15553. }
  15554. else
  15555. {
  15556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15557. }
  15558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15559. isKnowKey = TRUE;
  15560. }
  15561. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15562. {
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15566. {
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15568. }
  15569. else
  15570. {
  15571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15572. }
  15573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15574. isKnowKey = TRUE;
  15575. }
  15576. #if 1
  15577. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15578. {
  15579. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15581. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15582. {
  15583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15584. }
  15585. else
  15586. {
  15587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15588. }
  15589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15590. isKnowKey = TRUE;
  15591. }
  15592. #endif
  15593. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15594. {
  15595. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15597. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15598. {
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15600. }
  15601. else
  15602. {
  15603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15604. }
  15605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15606. isKnowKey = TRUE;
  15607. }
  15608. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15609. {
  15610. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15612. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15613. {
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15615. }
  15616. else
  15617. {
  15618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15619. }
  15620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15621. isKnowKey = TRUE;
  15622. }
  15623. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15624. {
  15625. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15627. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15628. {
  15629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15630. }
  15631. else
  15632. {
  15633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15634. }
  15635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15636. isKnowKey = TRUE;
  15637. }
  15638. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15639. {
  15640. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15642. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15643. {
  15644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15645. }
  15646. else
  15647. {
  15648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15649. }
  15650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15651. isKnowKey = TRUE;
  15652. }
  15653. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15654. {
  15655. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15657. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15658. {
  15659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15660. }
  15661. else
  15662. {
  15663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15664. }
  15665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15666. isKnowKey = TRUE;
  15667. }
  15668. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15669. {
  15670. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15672. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15673. {
  15674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15675. }
  15676. else
  15677. {
  15678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15679. }
  15680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15681. isKnowKey = TRUE;
  15682. }
  15683. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15684. {
  15685. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15687. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15688. {
  15689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15690. }
  15691. else
  15692. {
  15693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15694. }
  15695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15696. isKnowKey = TRUE;
  15697. }
  15698. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15699. {
  15700. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15702. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15703. {
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15705. }
  15706. else
  15707. {
  15708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15709. }
  15710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15711. isKnowKey = TRUE;
  15712. }
  15713. //=========================================================
  15714. if(!isEmpty && !isKnowKey)
  15715. {
  15716. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15717. strcpy(unknownkey[UnknownKeynum], keyReq);
  15718. UnknownKeynum = UnknownKeynum + 1;
  15719. }
  15720. }
  15721. void processUnkownKey(void)
  15722. {
  15723. DEBUG_INFO("processUnkownKey...\n");
  15724. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15725. for(int index=0; index < UnknownKeynum; index++)
  15726. {
  15727. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15728. {
  15729. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15730. }
  15731. }
  15732. }
  15733. int setKeyValue(char *key, char *value)
  15734. {
  15735. int isSuccess = NotSupported;
  15736. int check_ascii=0;
  15737. char str[501]={0};
  15738. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15739. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15740. {
  15741. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15742. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15743. {
  15744. strcpy(str, (const char*)value);
  15745. for(int i = 0; str[i]; i++){
  15746. str[i] = tolower(str[i]);
  15747. }
  15748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15749. isSuccess = ConfigurationStatus_Accepted;
  15750. }
  15751. else
  15752. {
  15753. isSuccess = ConfigurationStatus_Rejected;
  15754. }
  15755. }
  15756. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15757. {
  15758. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15760. {
  15761. strcpy(str, (const char*)value);
  15762. for(int i = 0; str[i]; i++){
  15763. str[i] = tolower(str[i]);
  15764. }
  15765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15766. isSuccess = ConfigurationStatus_Accepted;
  15767. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15768. }
  15769. else
  15770. {
  15771. isSuccess = ConfigurationStatus_Rejected;
  15772. }
  15773. }
  15774. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15775. {
  15776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15777. {
  15778. strcpy(str, (const char*)value);
  15779. for(int i = 0; str[i]; i++)
  15780. {
  15781. str[i] = tolower(str[i]);
  15782. }
  15783. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15785. isSuccess = ConfigurationStatus_Accepted;
  15786. }
  15787. else
  15788. {
  15789. isSuccess = ConfigurationStatus_Rejected;
  15790. }
  15791. }
  15792. if(strcmp(key, "BlinkRepeat") == 0)
  15793. {
  15794. //Charger.BlinkRepeat = Integer.parseInt(value);
  15795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15796. {
  15797. check_ascii = value[0];
  15798. if( (check_ascii < 48) || (check_ascii > 57) )
  15799. {
  15800. isSuccess = ConfigurationStatus_Rejected;
  15801. }
  15802. else
  15803. {
  15804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15805. isSuccess = ConfigurationStatus_Accepted;
  15806. }
  15807. }
  15808. else
  15809. {
  15810. isSuccess = ConfigurationStatus_Rejected;
  15811. }
  15812. }
  15813. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15814. {
  15815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15816. {
  15817. check_ascii = value[0];
  15818. if( (check_ascii < 48) || (check_ascii > 57) )
  15819. {
  15820. isSuccess = ConfigurationStatus_Rejected;
  15821. }
  15822. else
  15823. {
  15824. if((atoi(value) == 0) || (atoi(value) >= 5))
  15825. {
  15826. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15828. isSuccess = ConfigurationStatus_Accepted;
  15829. }
  15830. else
  15831. isSuccess = ConfigurationStatus_Rejected;
  15832. }
  15833. }
  15834. else
  15835. {
  15836. isSuccess = ConfigurationStatus_Rejected;
  15837. }
  15838. }
  15839. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15840. {
  15841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15842. {
  15843. check_ascii = value[0];
  15844. if( (check_ascii < 48) || (check_ascii > 57) )
  15845. {
  15846. isSuccess = ConfigurationStatus_Rejected;
  15847. }
  15848. else
  15849. {
  15850. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15852. isSuccess = ConfigurationStatus_Accepted;
  15853. }
  15854. }
  15855. else
  15856. {
  15857. isSuccess = ConfigurationStatus_Rejected;
  15858. }
  15859. }
  15860. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15861. {
  15862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15863. {
  15864. check_ascii = value[0];
  15865. if( (check_ascii < 48) || (check_ascii > 57) )
  15866. {
  15867. isSuccess = ConfigurationStatus_Rejected;
  15868. }
  15869. else
  15870. {
  15871. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15873. isSuccess = ConfigurationStatus_Accepted;
  15874. }
  15875. }
  15876. else
  15877. {
  15878. isSuccess = ConfigurationStatus_Rejected;
  15879. }
  15880. }
  15881. if(strcmp(key, "HeartbeatInterval") == 0)
  15882. {
  15883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15884. {
  15885. check_ascii = value[0];
  15886. if( (check_ascii < 48) || (check_ascii > 57) )
  15887. {
  15888. isSuccess = ConfigurationStatus_Rejected;
  15889. }
  15890. else
  15891. {
  15892. if((atoi(value) == 0) || (atoi(value) >= 10))
  15893. {
  15894. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15896. HeartBeatWaitTime = atoi(value);
  15897. isSuccess = ConfigurationStatus_Accepted;
  15898. }
  15899. else
  15900. {
  15901. isSuccess = ConfigurationStatus_Rejected;
  15902. }
  15903. }
  15904. }
  15905. else
  15906. {
  15907. isSuccess = ConfigurationStatus_Rejected;
  15908. }
  15909. }
  15910. if(strcmp(key, "LightIntensity") == 0)
  15911. {
  15912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].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[LightIntensity].ItemData, "%d", atoi(value) );
  15922. isSuccess = ConfigurationStatus_Accepted;
  15923. }
  15924. }
  15925. else
  15926. {
  15927. isSuccess = ConfigurationStatus_Rejected;
  15928. }
  15929. }
  15930. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15931. {
  15932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15933. {
  15934. strcpy(str, (const char*)value);
  15935. for(int i = 0; str[i]; i++)
  15936. {
  15937. str[i] = tolower(str[i]);
  15938. }
  15939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15940. isSuccess = ConfigurationStatus_Accepted;
  15941. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15942. }
  15943. else
  15944. {
  15945. isSuccess = ConfigurationStatus_Rejected;
  15946. }
  15947. }
  15948. if(strcmp(key, "LocalPreAuthorize") == 0)
  15949. {
  15950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15951. {
  15952. strcpy(str, (const char*)value);
  15953. for(int i = 0; str[i]; i++)
  15954. {
  15955. str[i] = tolower(str[i]);
  15956. }
  15957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15958. isSuccess = ConfigurationStatus_Accepted;
  15959. }
  15960. else
  15961. {
  15962. isSuccess = ConfigurationStatus_Rejected;
  15963. }
  15964. }
  15965. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15966. {
  15967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15968. {
  15969. check_ascii = value[0];
  15970. if( (check_ascii < 48) || (check_ascii > 57) )
  15971. {
  15972. isSuccess = ConfigurationStatus_Rejected;
  15973. }
  15974. else
  15975. {
  15976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15977. isSuccess = ConfigurationStatus_Accepted;
  15978. }
  15979. }
  15980. else
  15981. {
  15982. isSuccess = ConfigurationStatus_Rejected;
  15983. }
  15984. }
  15985. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15986. {
  15987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15988. {
  15989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15990. isSuccess = ConfigurationStatus_Accepted;
  15991. }
  15992. else
  15993. {
  15994. isSuccess = ConfigurationStatus_Rejected;
  15995. }
  15996. }
  15997. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15998. {
  15999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16000. {
  16001. check_ascii = value[0];
  16002. if( (check_ascii < 48) || (check_ascii > 57) )
  16003. {
  16004. isSuccess = ConfigurationStatus_Rejected;
  16005. }
  16006. else
  16007. {
  16008. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16010. isSuccess = ConfigurationStatus_Accepted;
  16011. }
  16012. }
  16013. else
  16014. {
  16015. isSuccess = ConfigurationStatus_Rejected;
  16016. }
  16017. }
  16018. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16019. {
  16020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16021. {
  16022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16023. isSuccess = ConfigurationStatus_Accepted;
  16024. }
  16025. else
  16026. {
  16027. isSuccess = ConfigurationStatus_Rejected;
  16028. }
  16029. }
  16030. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16031. {
  16032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16033. {
  16034. check_ascii = value[0];
  16035. if( (check_ascii < 48) || (check_ascii > 57) )
  16036. {
  16037. isSuccess = ConfigurationStatus_Rejected;
  16038. }
  16039. else
  16040. {
  16041. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16043. isSuccess = ConfigurationStatus_Accepted;
  16044. }
  16045. }
  16046. else
  16047. {
  16048. isSuccess = ConfigurationStatus_Rejected;
  16049. }
  16050. }
  16051. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16052. {
  16053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16054. {
  16055. check_ascii = value[0];
  16056. if( (check_ascii < 48) || (check_ascii > 57) )
  16057. {
  16058. isSuccess = ConfigurationStatus_Rejected;
  16059. }
  16060. else
  16061. {
  16062. if((atoi(value) == 0) || (atoi(value) >= 3))
  16063. {
  16064. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16066. isSuccess = ConfigurationStatus_Accepted;
  16067. }
  16068. else
  16069. {
  16070. isSuccess = ConfigurationStatus_Rejected;
  16071. }
  16072. }
  16073. }
  16074. else
  16075. {
  16076. isSuccess = ConfigurationStatus_Rejected;
  16077. }
  16078. }
  16079. if(strcmp(key, "MinimumStatusDuration") == 0)
  16080. {
  16081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16082. {
  16083. check_ascii = value[0];
  16084. if( (check_ascii < 48) || (check_ascii > 57) )
  16085. {
  16086. isSuccess = ConfigurationStatus_Rejected;
  16087. }
  16088. else
  16089. {
  16090. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16091. {
  16092. isSuccess = ConfigurationStatus_Rejected;
  16093. }
  16094. else
  16095. {
  16096. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16098. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16099. isSuccess = ConfigurationStatus_Accepted;
  16100. }
  16101. }
  16102. }
  16103. else
  16104. {
  16105. isSuccess = ConfigurationStatus_Rejected;
  16106. }
  16107. }
  16108. if(strcmp(key, "NumberOfConnectors") == 0)
  16109. {
  16110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16111. {
  16112. check_ascii = value[0];
  16113. if( (check_ascii < 48) || (check_ascii > 57) )
  16114. {
  16115. isSuccess = ConfigurationStatus_Rejected;
  16116. }
  16117. else
  16118. {
  16119. //Charger.ResetRetries = Integer.parseInt(value);
  16120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16121. isSuccess = ConfigurationStatus_Accepted;
  16122. }
  16123. }
  16124. else
  16125. {
  16126. isSuccess = ConfigurationStatus_Rejected;
  16127. }
  16128. }
  16129. if(strcmp(key, "ResetRetries") == 0)
  16130. {
  16131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16132. {
  16133. check_ascii = value[0];
  16134. if( (check_ascii < 48) || (check_ascii > 57) )
  16135. {
  16136. isSuccess = ConfigurationStatus_Rejected;
  16137. }
  16138. else
  16139. {
  16140. //Charger.ResetRetries = Integer.parseInt(value);
  16141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16142. isSuccess = ConfigurationStatus_Accepted;
  16143. }
  16144. }
  16145. else
  16146. {
  16147. isSuccess = ConfigurationStatus_Rejected;
  16148. }
  16149. }
  16150. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16151. {
  16152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16153. {
  16154. strcpy(str, (const char*)value);
  16155. for(int i = 0; str[i]; i++)
  16156. {
  16157. str[i] = tolower(str[i]);
  16158. }
  16159. if(strcmp(str, "notapplicable")== 0)
  16160. {
  16161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16162. isSuccess = ConfigurationStatus_Accepted;
  16163. }
  16164. else if(strcmp(str, "unknown")== 0)
  16165. {
  16166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16167. isSuccess = ConfigurationStatus_Accepted;
  16168. }
  16169. else if(strcmp(str, "rst")== 0)
  16170. {
  16171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16172. isSuccess = ConfigurationStatus_Accepted;
  16173. }
  16174. else if(strcmp(str, "rts")== 0)
  16175. {
  16176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16177. isSuccess = ConfigurationStatus_Accepted;
  16178. }
  16179. else if(strcmp(str, "srt")== 0)
  16180. {
  16181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16182. isSuccess = ConfigurationStatus_Accepted;
  16183. }
  16184. else if(strcmp(str, "str")== 0)
  16185. {
  16186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16187. isSuccess = ConfigurationStatus_Accepted;
  16188. }
  16189. else if(strcmp(str, "trs")== 0)
  16190. {
  16191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16192. isSuccess = ConfigurationStatus_Accepted;
  16193. }
  16194. else if(strcmp(str, "tsr")== 0)
  16195. {
  16196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16197. isSuccess = ConfigurationStatus_Accepted;
  16198. }
  16199. else
  16200. {
  16201. isSuccess = ConfigurationStatus_Rejected;
  16202. }
  16203. }
  16204. else
  16205. {
  16206. isSuccess = ConfigurationStatus_Rejected;
  16207. }
  16208. }
  16209. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16210. {
  16211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16212. {
  16213. check_ascii = value[0];
  16214. if( (check_ascii < 48) || (check_ascii > 57) )
  16215. {
  16216. isSuccess = ConfigurationStatus_Rejected;
  16217. }
  16218. else
  16219. {
  16220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16221. isSuccess = ConfigurationStatus_Accepted;
  16222. }
  16223. }
  16224. else
  16225. {
  16226. isSuccess = ConfigurationStatus_Rejected;
  16227. }
  16228. }
  16229. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16230. {
  16231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16232. {
  16233. strcpy(str, (const char*)value);
  16234. for(int i = 0; str[i]; i++)
  16235. {
  16236. str[i] = tolower(str[i]);
  16237. }
  16238. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16240. isSuccess = ConfigurationStatus_Accepted;
  16241. }
  16242. else
  16243. {
  16244. isSuccess = ConfigurationStatus_Rejected;
  16245. }
  16246. }
  16247. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16248. {
  16249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16250. {
  16251. strcpy(str, (const char*)value);
  16252. for(int i = 0; str[i]; i++)
  16253. {
  16254. str[i] = tolower(str[i]);
  16255. }
  16256. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16258. isSuccess = ConfigurationStatus_Accepted;
  16259. }
  16260. else
  16261. {
  16262. isSuccess = ConfigurationStatus_Rejected;
  16263. }
  16264. }
  16265. if(strcmp(key, "StopTxnAlignedData") == 0)
  16266. {
  16267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16268. {
  16269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16270. isSuccess = ConfigurationStatus_Accepted;
  16271. }
  16272. else
  16273. {
  16274. isSuccess = ConfigurationStatus_Rejected;
  16275. }
  16276. }
  16277. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16278. {
  16279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16280. {
  16281. check_ascii = value[0];
  16282. if( (check_ascii < 48) || (check_ascii > 57) )
  16283. {
  16284. isSuccess = ConfigurationStatus_Rejected;
  16285. }
  16286. else
  16287. {
  16288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16289. isSuccess = ConfigurationStatus_Accepted;
  16290. }
  16291. }
  16292. else
  16293. {
  16294. isSuccess = ConfigurationStatus_Rejected;
  16295. }
  16296. }
  16297. if(strcmp(key, "StopTxnSampledData") == 0)
  16298. {
  16299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16300. {
  16301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16302. isSuccess = ConfigurationStatus_Accepted;
  16303. }
  16304. else
  16305. {
  16306. isSuccess = ConfigurationStatus_Rejected;
  16307. }
  16308. }
  16309. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16310. {
  16311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16312. {
  16313. check_ascii = value[0];
  16314. if( (check_ascii < 48) || (check_ascii > 57) )
  16315. {
  16316. isSuccess = ConfigurationStatus_Rejected;
  16317. }
  16318. else
  16319. {
  16320. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16321. isSuccess = ConfigurationStatus_Accepted;
  16322. }
  16323. }
  16324. else
  16325. {
  16326. isSuccess = ConfigurationStatus_Rejected;
  16327. }
  16328. }
  16329. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16330. {
  16331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16332. {
  16333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16334. isSuccess = ConfigurationStatus_Accepted;
  16335. }
  16336. else
  16337. {
  16338. isSuccess = ConfigurationStatus_Rejected;
  16339. }
  16340. }
  16341. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16342. {
  16343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16344. {
  16345. check_ascii = value[0];
  16346. if( (check_ascii < 48) || (check_ascii > 57) )
  16347. {
  16348. isSuccess = ConfigurationStatus_Rejected;
  16349. }
  16350. else
  16351. {
  16352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16353. isSuccess = ConfigurationStatus_Accepted;
  16354. }
  16355. }
  16356. else
  16357. {
  16358. isSuccess = ConfigurationStatus_Rejected;
  16359. }
  16360. }
  16361. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16362. {
  16363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16364. {
  16365. check_ascii = value[0];
  16366. if( (check_ascii < 48) || (check_ascii > 57) )
  16367. {
  16368. isSuccess = ConfigurationStatus_Rejected;
  16369. }
  16370. else
  16371. {
  16372. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16374. TransactionMessageAttemptsValue = atoi(value);
  16375. isSuccess = ConfigurationStatus_Accepted;
  16376. }
  16377. }
  16378. else
  16379. {
  16380. isSuccess = ConfigurationStatus_Rejected;
  16381. }
  16382. }
  16383. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16384. {
  16385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16386. {
  16387. check_ascii = value[0];
  16388. if( (check_ascii < 48) || (check_ascii > 57) )
  16389. {
  16390. isSuccess = ConfigurationStatus_Rejected;
  16391. }
  16392. else
  16393. {
  16394. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16396. TransactionMessageRetryIntervalValue = atoi(value);
  16397. isSuccess = ConfigurationStatus_Accepted;
  16398. }
  16399. }
  16400. else
  16401. {
  16402. isSuccess = ConfigurationStatus_Rejected;
  16403. }
  16404. }
  16405. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16406. {
  16407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16408. {
  16409. strcpy(str, (const char*)value);
  16410. for(int i = 0; str[i]; i++)
  16411. {
  16412. str[i] = tolower(str[i]);
  16413. }
  16414. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16416. isSuccess = ConfigurationStatus_Accepted;
  16417. }
  16418. else
  16419. {
  16420. isSuccess = ConfigurationStatus_Rejected;
  16421. }
  16422. }
  16423. if(strcmp(key, "WebSocketPingInterval") == 0)
  16424. {
  16425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16426. {
  16427. check_ascii = value[0];
  16428. if( (check_ascii < 48) || (check_ascii > 57) )
  16429. {
  16430. isSuccess = ConfigurationStatus_Rejected;
  16431. }
  16432. else
  16433. {
  16434. if((atoi(value) == 0) || (atoi(value) >= 10))
  16435. {
  16436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16437. isSuccess = ConfigurationStatus_Accepted;
  16438. }
  16439. else
  16440. isSuccess = ConfigurationStatus_Rejected;
  16441. }
  16442. }
  16443. else
  16444. {
  16445. isSuccess = ConfigurationStatus_Rejected;
  16446. }
  16447. }
  16448. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16449. {
  16450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16451. {
  16452. strcpy(str, (const char*)value);
  16453. for(int i = 0; str[i]; i++)
  16454. {
  16455. str[i] = tolower(str[i]);
  16456. }
  16457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16458. isSuccess = ConfigurationStatus_Accepted;
  16459. }
  16460. else
  16461. {
  16462. isSuccess = ConfigurationStatus_Rejected;
  16463. }
  16464. }
  16465. if(strcmp(key, "AuthorizationKey") == 0)
  16466. {
  16467. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16468. {
  16469. strcpy(str, (const char*)value);
  16470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16471. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16472. isSuccess = ConfigurationStatus_Accepted;
  16473. }
  16474. else
  16475. {
  16476. isSuccess = ConfigurationStatus_Rejected;
  16477. }
  16478. }
  16479. if(strcmp(key, "SecurityProfile") == 0)
  16480. {
  16481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16482. {
  16483. check_ascii = value[0];
  16484. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16485. {
  16486. isSuccess = ConfigurationStatus_Rejected;
  16487. }
  16488. else if(check_ascii == 0x33)
  16489. {
  16490. isSuccess = NotSupported;
  16491. }
  16492. else
  16493. {
  16494. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16495. {
  16496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16497. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16498. isSuccess = ConfigurationStatus_Accepted;
  16499. }
  16500. else
  16501. isSuccess = ConfigurationStatus_Rejected;
  16502. }
  16503. }
  16504. else
  16505. {
  16506. isSuccess = ConfigurationStatus_Rejected;
  16507. }
  16508. }
  16509. if(strcmp(key, "DefaultPrice") == 0)
  16510. {
  16511. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16512. {
  16513. strcpy(str, (const char*)value);
  16514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16515. isSuccess = ConfigurationStatus_Accepted;
  16516. }
  16517. else
  16518. {
  16519. isSuccess = ConfigurationStatus_Rejected;
  16520. }
  16521. }
  16522. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16523. {
  16524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16525. {
  16526. strcpy(str, (const char*)value);
  16527. for(int i = 0; str[i]; i++)
  16528. {
  16529. str[i] = tolower(str[i]);
  16530. }
  16531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16532. isSuccess = ConfigurationStatus_Accepted;
  16533. }
  16534. else
  16535. {
  16536. isSuccess = ConfigurationStatus_Rejected;
  16537. }
  16538. }
  16539. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16540. {
  16541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16542. {
  16543. strcpy(str, (const char*)value);
  16544. for(int i = 0; str[i]; i++)
  16545. {
  16546. str[i] = tolower(str[i]);
  16547. }
  16548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16549. isSuccess = ConfigurationStatus_Accepted;
  16550. }
  16551. else
  16552. {
  16553. isSuccess = ConfigurationStatus_Rejected;
  16554. }
  16555. }
  16556. if(strcmp(key, "TimeOffset") == 0)
  16557. {
  16558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16559. {
  16560. strcpy(str, (const char*)value);
  16561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16562. isSuccess = ConfigurationStatus_Accepted;
  16563. }
  16564. else
  16565. {
  16566. isSuccess = ConfigurationStatus_Rejected;
  16567. }
  16568. }
  16569. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16570. {
  16571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16572. {
  16573. strcpy(str, (const char*)value);
  16574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16575. isSuccess = ConfigurationStatus_Accepted;
  16576. }
  16577. else
  16578. {
  16579. isSuccess = ConfigurationStatus_Rejected;
  16580. }
  16581. }
  16582. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16583. {
  16584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16585. {
  16586. strcpy(str, (const char*)value);
  16587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16588. isSuccess = ConfigurationStatus_Accepted;
  16589. }
  16590. else
  16591. {
  16592. isSuccess = ConfigurationStatus_Rejected;
  16593. }
  16594. }
  16595. if(strcmp(key, "SystemUptimeSec") == 0)
  16596. {
  16597. isSuccess = NotSupported;
  16598. }
  16599. if(strcmp(key, "FreeVend") == 0)
  16600. {
  16601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16602. {
  16603. strcpy(str, (const char*)value);
  16604. for(int i = 0; str[i]; i++)
  16605. {
  16606. str[i] = tolower(str[i]);
  16607. }
  16608. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16610. isSuccess = ConfigurationStatus_Accepted;
  16611. }
  16612. else
  16613. {
  16614. isSuccess = ConfigurationStatus_Rejected;
  16615. }
  16616. }
  16617. if(strcmp(key, "FreeVendIdtag") == 0)
  16618. {
  16619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16620. {
  16621. strcpy(str, (const char*)value);
  16622. if(strlen(str) <= 20)
  16623. {
  16624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16625. isSuccess = ConfigurationStatus_Accepted;
  16626. }
  16627. else
  16628. {
  16629. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16630. isSuccess = ConfigurationStatus_Rejected;
  16631. }
  16632. }
  16633. else
  16634. {
  16635. isSuccess = ConfigurationStatus_Rejected;
  16636. }
  16637. }
  16638. if(strcmp(key, "OcppServer") == 0)
  16639. {
  16640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16641. {
  16642. strcpy(str, (const char*)value);
  16643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16644. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16645. isSuccess = ConfigurationStatus_Accepted;
  16646. }
  16647. else
  16648. {
  16649. isSuccess = ConfigurationStatus_Rejected;
  16650. }
  16651. }
  16652. if(strcmp(key, "MaintainServer") == 0)
  16653. {
  16654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16655. {
  16656. strcpy(str, (const char*)value);
  16657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16658. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16659. isSuccess = ConfigurationStatus_Accepted;
  16660. }
  16661. else
  16662. {
  16663. isSuccess = ConfigurationStatus_Rejected;
  16664. }
  16665. }
  16666. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16667. {
  16668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16669. {
  16670. strcpy(str, (const char*)value);
  16671. for(int i = 0; str[i]; i++)
  16672. {
  16673. str[i] = tolower(str[i]);
  16674. }
  16675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16676. isSuccess = ConfigurationStatus_Accepted;
  16677. }
  16678. else
  16679. {
  16680. isSuccess = ConfigurationStatus_Rejected;
  16681. }
  16682. }
  16683. if(strcmp(key, "StatusNotificationInterval") == 0)
  16684. {
  16685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16686. {
  16687. check_ascii = value[0];
  16688. if( (check_ascii < 48) || (check_ascii > 57) )
  16689. {
  16690. isSuccess = ConfigurationStatus_Rejected;
  16691. }
  16692. else
  16693. {
  16694. if((atoi(value) == 0) || (atoi(value) >= 10))
  16695. {
  16696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16697. isSuccess = ConfigurationStatus_Accepted;
  16698. }
  16699. else
  16700. isSuccess = ConfigurationStatus_Rejected;
  16701. }
  16702. }
  16703. else
  16704. {
  16705. isSuccess = ConfigurationStatus_Rejected;
  16706. }
  16707. }
  16708. #if 0
  16709. //For OCPP Test Case
  16710. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16711. {
  16712. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16713. {
  16714. strcpy(str, (const char*)value);
  16715. for(int i = 0; str[i]; i++)
  16716. {
  16717. str[i] = tolower(str[i]);
  16718. }
  16719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16720. isSuccess = ConfigurationStatus_Accepted;
  16721. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16722. }
  16723. else
  16724. {
  16725. isSuccess = ConfigurationStatus_Rejected;
  16726. }
  16727. }
  16728. #endif
  16729. #if 1
  16730. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16731. {
  16732. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16733. {
  16734. strcpy(str, (const char*)value);
  16735. for(int i = 0; str[i]; i++)
  16736. {
  16737. str[i] = tolower(str[i]);
  16738. }
  16739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16740. isSuccess = ConfigurationStatus_Accepted;
  16741. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16742. }
  16743. else
  16744. {
  16745. isSuccess = ConfigurationStatus_Rejected;
  16746. }
  16747. }
  16748. #endif
  16749. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16750. {
  16751. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16752. {
  16753. check_ascii = value[0];
  16754. if( (check_ascii < 48) || (check_ascii > 57) )
  16755. {
  16756. isSuccess = ConfigurationStatus_Rejected;
  16757. }
  16758. else
  16759. {
  16760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16761. isSuccess = ConfigurationStatus_Accepted;
  16762. }
  16763. }
  16764. else
  16765. {
  16766. isSuccess = ConfigurationStatus_Rejected;
  16767. }
  16768. }
  16769. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16770. {
  16771. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16772. {
  16773. check_ascii = value[0];
  16774. if( (check_ascii < 48) || (check_ascii > 57) )
  16775. {
  16776. isSuccess = ConfigurationStatus_Rejected;
  16777. }
  16778. else
  16779. {
  16780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16781. isSuccess = ConfigurationStatus_Accepted;
  16782. }
  16783. }
  16784. else
  16785. {
  16786. isSuccess = ConfigurationStatus_Rejected;
  16787. }
  16788. }
  16789. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16790. {
  16791. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16792. {
  16793. strcpy(str, (const char*)value);
  16794. for(int i = 0; str[i]; i++)
  16795. {
  16796. str[i] = tolower(str[i]);
  16797. }
  16798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16799. isSuccess = ConfigurationStatus_Accepted;
  16800. }
  16801. else
  16802. {
  16803. isSuccess = ConfigurationStatus_Rejected;
  16804. }
  16805. }
  16806. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16807. {
  16808. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16809. {
  16810. check_ascii = value[0];
  16811. if( (check_ascii < 48) || (check_ascii > 57) )
  16812. {
  16813. isSuccess = ConfigurationStatus_Rejected;
  16814. }
  16815. else
  16816. {
  16817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16818. isSuccess = ConfigurationStatus_Accepted;
  16819. }
  16820. }
  16821. else
  16822. {
  16823. isSuccess = ConfigurationStatus_Rejected;
  16824. }
  16825. }
  16826. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16827. {
  16828. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16829. {
  16830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16831. isSuccess = ConfigurationStatus_Accepted;
  16832. }
  16833. else
  16834. {
  16835. isSuccess = ConfigurationStatus_Rejected;
  16836. }
  16837. }
  16838. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16839. {
  16840. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16841. {
  16842. check_ascii = value[0];
  16843. if( (check_ascii < 48) || (check_ascii > 57) )
  16844. {
  16845. isSuccess = ConfigurationStatus_Rejected;
  16846. }
  16847. else
  16848. {
  16849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16850. isSuccess = ConfigurationStatus_Accepted;
  16851. }
  16852. }
  16853. else
  16854. {
  16855. isSuccess = ConfigurationStatus_Rejected;
  16856. }
  16857. }
  16858. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16859. {
  16860. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16861. {
  16862. strcpy(str, (const char*)value);
  16863. for(int i = 0; str[i]; i++)
  16864. {
  16865. str[i] = tolower(str[i]);
  16866. }
  16867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16868. isSuccess = ConfigurationStatus_Accepted;
  16869. }
  16870. else
  16871. {
  16872. isSuccess = ConfigurationStatus_Rejected;
  16873. }
  16874. }
  16875. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16876. {
  16877. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16878. {
  16879. check_ascii = value[0];
  16880. if( (check_ascii < 48) || (check_ascii > 57) )
  16881. {
  16882. isSuccess = ConfigurationStatus_Rejected;
  16883. }
  16884. else
  16885. {
  16886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16887. isSuccess = ConfigurationStatus_Accepted;
  16888. }
  16889. }
  16890. else
  16891. {
  16892. isSuccess = ConfigurationStatus_Rejected;
  16893. }
  16894. }
  16895. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16896. return isSuccess;
  16897. }
  16898. int TransactionMessageAttemptsGet(void)
  16899. {
  16900. return TransactionMessageAttemptsValue;
  16901. }
  16902. int FirstHeartBeatResponse(void)
  16903. {
  16904. return FirstHeartBeat;
  16905. }
  16906. int TransactionMessageRetryIntervalGet(void)
  16907. {
  16908. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16909. }
  16910. int ReadHttpStatus(int sock)
  16911. {
  16912. //char c;
  16913. char buff[1024]="",*ptr=buff+1;
  16914. int bytes_received, status;
  16915. DEBUG_INFO("Begin Response ..\n");
  16916. while((bytes_received = recv(sock, ptr, 1, 0))){
  16917. if(bytes_received==-1){
  16918. perror("ReadHttpStatus");
  16919. exit(1);
  16920. }
  16921. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16922. ptr++;
  16923. }
  16924. *ptr=0;
  16925. ptr=buff+1;
  16926. sscanf(ptr,"%*s %d ", &status);
  16927. DEBUG_INFO("%s\n",ptr);
  16928. DEBUG_INFO("status=%d\n",status);
  16929. DEBUG_INFO("End Response ..\n");
  16930. return (bytes_received>0)?status:0;
  16931. }
  16932. //the only filed that it parsed is 'Content-Length'
  16933. int ParseHeader(int sock)
  16934. {
  16935. //char c;
  16936. char buff[1024]="",*ptr=buff+4;
  16937. int bytes_received;
  16938. DEBUG_INFO("Begin HEADER ..\n");
  16939. while((bytes_received = recv(sock, ptr, 1, 0))){
  16940. if(bytes_received==-1){
  16941. perror("Parse Header");
  16942. exit(1);
  16943. }
  16944. if(
  16945. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16946. (ptr[-1]=='\r') && (*ptr=='\n' )
  16947. ) break;
  16948. ptr++;
  16949. }
  16950. *ptr=0;
  16951. ptr=buff+4;
  16952. //printf("%s",ptr);
  16953. if(bytes_received){
  16954. ptr=strstr(ptr,"Content-Length:");
  16955. if(ptr){
  16956. sscanf(ptr,"%*s %d",&bytes_received);
  16957. }else
  16958. bytes_received=-1; //unknown size
  16959. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16960. }
  16961. DEBUG_INFO("End HEADER ..\n");
  16962. return bytes_received ;
  16963. }
  16964. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16965. {
  16966. int result = TRUE;
  16967. char rmFileCmd[100]={0};
  16968. char FilePath[100]={0};
  16969. char ftpbuf[200];
  16970. int systemresult;
  16971. sprintf(FilePath,"/mnt/%s",filename);
  16972. system("ping 8.8.8.8 &");
  16973. if((access(FilePath,F_OK))!=-1)
  16974. {
  16975. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16976. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16977. system(rmFileCmd);
  16978. }
  16979. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16980. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16981. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16982. systemresult = system(ftpbuf);
  16983. if(systemresult != 0)
  16984. {
  16985. DEBUG_INFO("http DownLoad error!\n");
  16986. result = FALSE;
  16987. }
  16988. system("pkill ping");
  16989. return result;
  16990. }
  16991. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16992. {
  16993. int result = TRUE;
  16994. char rmFileCmd[100]={0};
  16995. char FilePath[100]={0};
  16996. char ftpbuf[200];
  16997. int systemresult;
  16998. sprintf(FilePath,"/mnt/%s",filename);
  16999. system("ping 8.8.8.8 &");
  17000. if((access(FilePath,F_OK))!=-1)
  17001. {
  17002. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17003. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17004. system(rmFileCmd);
  17005. }
  17006. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17007. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17008. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17009. systemresult = system(ftpbuf);
  17010. if(systemresult != 0)
  17011. {
  17012. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17013. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17014. systemresult = system(ftpbuf);
  17015. if(systemresult != 0)
  17016. {
  17017. DEBUG_WARN("wget error!\n");
  17018. result = FALSE;
  17019. }
  17020. }
  17021. system("pkill ping");
  17022. return result;
  17023. }
  17024. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17025. {
  17026. char rmFileCmd[100]={0};
  17027. char FilePath[100]={0};
  17028. char buf[512];
  17029. int systemresult = 0;
  17030. //DEBUG_INFO("filename=%s\n",filename);
  17031. //DEBUG_INFO("url=%s\n",url);
  17032. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17033. if((access(FilePath,F_OK))!=-1)
  17034. {
  17035. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17036. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17037. system(rmFileCmd);
  17038. }
  17039. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17040. if(fp == NULL)
  17041. {
  17042. DEBUG_INFO("log is NULL\n");
  17043. return FALSE;
  17044. }
  17045. else
  17046. {
  17047. fprintf(fp, "%s\n", url);
  17048. fprintf(fp, "%s\n", filename);
  17049. fclose(fp);
  17050. }
  17051. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17052. if(phpFP == NULL)
  17053. {
  17054. DEBUG_INFO("PHP upload fail.\n");
  17055. return FALSE;
  17056. }
  17057. else
  17058. {
  17059. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17060. {
  17061. if(strstr(buf, "result") != NULL)
  17062. {
  17063. sscanf(buf, "result: %d", &systemresult);
  17064. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17065. }
  17066. }
  17067. pclose(phpFP);
  17068. }
  17069. if(systemresult != 1)
  17070. {
  17071. DEBUG_INFO("HTTP upload error!\n");
  17072. return FALSE;
  17073. }
  17074. return TRUE;
  17075. }
  17076. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17077. {
  17078. int result = FALSE;
  17079. char ftpbuf[200];
  17080. int systemresult;
  17081. /*
  17082. // Domaind name transfer to IP address
  17083. struct hostent* server;
  17084. char *IPbuffer;
  17085. server = gethostbyname(location);
  17086. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17087. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17088. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17089. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17090. systemresult = system(ftpbuf);
  17091. if(systemresult != 0)
  17092. {
  17093. DEBUG_INFO("ftpput error!\n");
  17094. }
  17095. else
  17096. {
  17097. result = TRUE;
  17098. DEBUG_INFO("ftpput OK!\n");
  17099. }
  17100. return result;
  17101. }
  17102. int GetOcppServerURL()
  17103. {
  17104. int result = FALSE;
  17105. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17106. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17107. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17108. struct yuarel url;
  17109. char urlStr[512];
  17110. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17111. {
  17112. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17113. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17114. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17115. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17116. if(yuarel_parse(&url, urlStr) != -1)
  17117. {
  17118. sprintf(OcppProtocol, "%s", url.scheme);
  17119. sprintf(OcppHost, "%s", url.host);
  17120. if(url.path == NULL)
  17121. OcppTempPath[0] = '\0';
  17122. else
  17123. {
  17124. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17125. {
  17126. sprintf(OcppTempPath, "%s/", url.path);
  17127. }
  17128. else
  17129. {
  17130. sprintf(OcppTempPath, "%s", url.path);
  17131. }
  17132. }
  17133. if(url.port == 0)
  17134. {
  17135. if(strcmp(OcppProtocol, "wss") == 0)
  17136. OcppPort = 443;
  17137. else
  17138. OcppPort = 80;
  17139. }
  17140. else
  17141. OcppPort = url.port;
  17142. result = TRUE;
  17143. }
  17144. }
  17145. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17146. {
  17147. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17148. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17149. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17150. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17151. if(yuarel_parse(&url, urlStr) != -1)
  17152. {
  17153. sprintf(OcppProtocol, "%s", url.scheme);
  17154. sprintf(OcppHost, "%s", url.host);
  17155. if(url.path == NULL)
  17156. OcppTempPath[0] = '\0';
  17157. else
  17158. sprintf(OcppTempPath, "%s", url.path);
  17159. if(url.port == 0)
  17160. {
  17161. if(strcmp(OcppProtocol, "wss") == 0)
  17162. OcppPort = 443;
  17163. else
  17164. OcppPort = 80;
  17165. }
  17166. else
  17167. OcppPort = url.port;
  17168. result = TRUE;
  17169. }
  17170. }
  17171. else
  17172. {
  17173. strcpy(OcppHost,"");
  17174. }
  17175. return result;
  17176. }
  17177. int GetOcppPath()
  17178. {
  17179. int result = FALSE;
  17180. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17181. {
  17182. if(OcppTempPath == NULL)
  17183. {
  17184. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17185. }
  17186. else
  17187. {
  17188. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17189. }
  17190. result = TRUE;
  17191. goto End;
  17192. }
  17193. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17194. {
  17195. if(OcppTempPath == NULL)
  17196. {
  17197. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17198. }
  17199. else
  17200. {
  17201. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17202. }
  17203. result = TRUE;
  17204. goto End;
  17205. }
  17206. else
  17207. {
  17208. strcpy(OcppPath,"");
  17209. }
  17210. End:
  17211. return result;
  17212. }
  17213. int GetOcppPort()
  17214. {
  17215. return OcppPort;
  17216. }
  17217. int GetOcppConnStatus(void)
  17218. {
  17219. return ShmOCPP16Data->OcppConnStatus;
  17220. }
  17221. void SetOcppConnStatus(uint8_t status)
  17222. {
  17223. ShmOCPP16Data->OcppConnStatus = status;
  17224. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17225. }
  17226. int GetHeartBeatWithNOResponse(void)
  17227. {
  17228. return HeartBeatWithNOResponse;
  17229. }
  17230. void SetHeartBeatWithNOResponse(void)
  17231. {
  17232. HeartBeatWithNOResponse = 0;
  17233. }
  17234. void GetStartTransactionIdTag(int gun_index)
  17235. {
  17236. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17237. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17238. }
  17239. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17240. {
  17241. char ch;
  17242. FILE *fptr1;
  17243. int temptransactionId;
  17244. char str[100]={0};
  17245. temptransactionId = 0;
  17246. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17247. {
  17248. DEBUG_INFO("IdTag is empty.\n");
  17249. return temptransactionId;
  17250. }
  17251. /*------ Read the file ----------------*/
  17252. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17253. if (!fptr1)
  17254. {
  17255. DEBUG_INFO("QueueTransactionId file open error.\n");
  17256. //printf(" File not found or unable to open the input file!!\n");
  17257. return temptransactionId;
  17258. }
  17259. ch=fgetc(fptr1);
  17260. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17261. rewind(fptr1);
  17262. if(ch!=EOF)
  17263. {
  17264. // printf("%c",ch);
  17265. while (fgets(str, 100, fptr1) != NULL)
  17266. {
  17267. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17268. if(str[0]=='\0')
  17269. {
  17270. break;
  17271. }
  17272. char *revbuf[8] = {0}; // Variable store string split
  17273. int num = 0;// Quantity after string split
  17274. DEBUG_INFO("Transaction queue data= %s\n", str);
  17275. splitstring(str,",",revbuf,&num); // String split
  17276. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17277. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17278. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17279. DEBUG_INFO("------------------------------\n");
  17280. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17281. {
  17282. if(isStopTransaction)
  17283. {
  17284. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17285. {
  17286. temptransactionId = atoi(revbuf[2]);
  17287. //break;
  17288. }
  17289. }
  17290. else
  17291. {
  17292. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17293. {
  17294. temptransactionId = atoi(revbuf[2]);
  17295. //break;
  17296. }
  17297. }
  17298. }
  17299. }
  17300. }
  17301. else
  17302. DEBUG_INFO("EOF\n");
  17303. fclose(fptr1);
  17304. /*------- End of reading ---------------*/
  17305. return temptransactionId;
  17306. }
  17307. void SetTransactionIdZero(int transactionId)
  17308. {
  17309. char ch;
  17310. FILE *fptr1, *fptr2;
  17311. int temptransactionId = 0;
  17312. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17313. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17314. if (!fptr1)
  17315. {
  17316. //printf(" File not found or unable to open the input file!!\n");
  17317. return ;
  17318. }
  17319. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17320. if (!fptr2)
  17321. {
  17322. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17323. fclose(fptr1);
  17324. return ;
  17325. }
  17326. ch=fgetc(fptr1);
  17327. rewind(fptr1);
  17328. if(ch!=EOF)
  17329. {
  17330. // copy all contents to the temporary file except the specific line
  17331. while (fgets(str, 100, fptr1) != NULL)
  17332. {
  17333. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17334. if(str[0]=='\0')
  17335. {
  17336. break;
  17337. }
  17338. char *revbuf[8] = {0};
  17339. int num = 0;
  17340. strcpy(strtemp, str);
  17341. splitstring(str,",",revbuf,&num);
  17342. if(revbuf[2][0] != '\0')
  17343. {
  17344. temptransactionId = atoi(revbuf[2]);
  17345. if(transactionId != temptransactionId)
  17346. {
  17347. fprintf(fptr2, "%s\n", strtemp);
  17348. }
  17349. }
  17350. }
  17351. }
  17352. fclose(fptr1);
  17353. fclose(fptr2);
  17354. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17355. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17356. /*------ Read the file ----------------*/
  17357. }
  17358. int InternetDisconnect(void)
  17359. {
  17360. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17361. }
  17362. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17363. void storeTempStopTransaction(int gun_index)
  17364. {
  17365. char guid[37]={0};
  17366. int tempIndex = 0;
  17367. char TempStopTransaction[256];
  17368. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17369. DEBUG_INFO("storeTempStopTransaction...\n");
  17370. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17371. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17372. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17373. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17374. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17375. {
  17376. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17377. {
  17378. tempIndex = ((gun_index==2) ? 1: 0);
  17379. }
  17380. else
  17381. {
  17382. tempIndex = gun_index;
  17383. }
  17384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17385. {
  17386. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17387. {
  17388. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17389. }
  17390. }// END OF CHAdeMO_QUANTITY
  17391. }
  17392. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17393. {
  17394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17395. {
  17396. tempIndex = ((gun_index==2) ? 1: 0);
  17397. }
  17398. else
  17399. {
  17400. tempIndex = gun_index;
  17401. }
  17402. for (int index = 0; index < CCS_QUANTITY; index++)
  17403. {
  17404. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17405. {
  17406. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17407. }
  17408. }// END OF CCS_QUANTITY
  17409. }
  17410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17411. {
  17412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17413. {
  17414. tempIndex = ((gun_index==2) ? 1: 0);
  17415. }
  17416. else
  17417. {
  17418. tempIndex = gun_index;
  17419. }
  17420. for (int index = 0; index < GB_QUANTITY; index++)
  17421. {
  17422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17423. {
  17424. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17425. }
  17426. }// END OF GB_QUANTITY
  17427. }
  17428. else if(gunType[gun_index] == GUN_TYPE_DO)
  17429. {
  17430. tempIndex = gun_index;
  17431. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17432. {
  17433. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17434. {
  17435. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17436. }
  17437. }
  17438. }
  17439. else
  17440. {
  17441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17442. {
  17443. tempIndex = 2;
  17444. }
  17445. else
  17446. {
  17447. tempIndex = gun_index;
  17448. }
  17449. for (int index = 0; index < AC_QUANTITY; index++)
  17450. {
  17451. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17452. {
  17453. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17454. }
  17455. }// END OF AC_QUANTITY
  17456. }
  17457. //Stop Transaction Time
  17458. struct timeval tmnow;
  17459. struct tm *tm;
  17460. char buf[28];//, usec_buf[6];
  17461. gettimeofday(&tmnow, NULL);
  17462. time_t t;
  17463. t = time(NULL);
  17464. /*UTC time and date*/
  17465. tm = gmtime(&t);
  17466. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17468. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17470. random_uuid(guid);
  17471. /***********************************transactionData******************************************************/
  17472. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17474. //=================================
  17475. //1. Transaction_Begin
  17476. //=================================
  17477. //============================== Energy.Active.Import.Interval ===========================================
  17478. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17479. {
  17480. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17483. 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*/]);
  17484. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17485. 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))
  17486. {
  17487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17488. }
  17489. else
  17490. {
  17491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17492. }
  17493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17495. }
  17496. //=================================
  17497. //2. Transaction_End
  17498. //=================================
  17499. //2.1====================================== Current.Import L1 ==============================================
  17500. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17501. {
  17502. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17503. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17504. {
  17505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17506. {
  17507. tempIndex = ((gun_index==2) ? 1: 0);
  17508. }
  17509. else
  17510. {
  17511. tempIndex = gun_index;
  17512. }
  17513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17514. {
  17515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17516. {
  17517. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17518. }
  17519. }// End of for CHAdeMO_QUANTITY
  17520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17521. }
  17522. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17523. {
  17524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17525. {
  17526. tempIndex = ((gun_index==2) ? 1: 0);
  17527. }
  17528. else
  17529. {
  17530. tempIndex = gun_index;
  17531. }
  17532. for (int index = 0; index < CCS_QUANTITY; index++)
  17533. {
  17534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17535. {
  17536. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17537. }
  17538. }// End of for CCS_QUANTITY
  17539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17540. }
  17541. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17542. {
  17543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17544. {
  17545. tempIndex = ((gun_index==2) ? 1: 0);
  17546. }
  17547. else
  17548. {
  17549. tempIndex = gun_index;
  17550. }
  17551. for (int index = 0; index < GB_QUANTITY; index++)
  17552. {
  17553. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17554. {
  17555. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17556. }
  17557. }// End of for GB_QUANTITY
  17558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17559. }
  17560. else if(gunType[gun_index] == GUN_TYPE_DO)
  17561. {
  17562. tempIndex = gun_index;
  17563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17564. {
  17565. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17566. {
  17567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17568. }
  17569. }
  17570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17571. }
  17572. else
  17573. {
  17574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17575. {
  17576. tempIndex = 2;
  17577. }
  17578. else
  17579. {
  17580. tempIndex = gun_index;
  17581. }
  17582. for (int index = 0; index < AC_QUANTITY; index++)
  17583. {
  17584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17585. {
  17586. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17587. }
  17588. }// End of for AC_QUANTITY
  17589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17590. }
  17591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17594. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17597. }
  17598. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17599. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17600. {
  17601. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17602. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17603. {
  17604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17605. {
  17606. tempIndex = ((gun_index==2) ? 1: 0);
  17607. }
  17608. else
  17609. {
  17610. tempIndex = gun_index;
  17611. }
  17612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17613. {
  17614. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17615. {
  17616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17617. }
  17618. }// END OF CHAdeMO_QUANTITY
  17619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17620. }
  17621. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17622. {
  17623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17624. {
  17625. tempIndex = ((gun_index==2) ? 1: 0);
  17626. }
  17627. else
  17628. {
  17629. tempIndex = gun_index;
  17630. }
  17631. for (int index = 0; index < CCS_QUANTITY; index++)
  17632. {
  17633. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17634. {
  17635. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17636. }
  17637. }// END OF CCS_QUANTITY
  17638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17639. }
  17640. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17641. {
  17642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17643. {
  17644. tempIndex = ((gun_index==2) ? 1: 0);
  17645. }
  17646. else
  17647. {
  17648. tempIndex = gun_index;
  17649. }
  17650. for (int index = 0; index < GB_QUANTITY; index++)
  17651. {
  17652. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17653. {
  17654. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17655. }
  17656. }// END OF GB_QUANTITY
  17657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17658. }
  17659. else if(gunType[gun_index] == GUN_TYPE_DO)
  17660. {
  17661. tempIndex = gun_index;
  17662. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17663. {
  17664. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17665. {
  17666. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17667. }
  17668. }
  17669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17670. }
  17671. else
  17672. {
  17673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17674. {
  17675. tempIndex = 2;
  17676. }
  17677. else
  17678. {
  17679. tempIndex = gun_index;
  17680. }
  17681. for (int index = 0; index < AC_QUANTITY; index++)
  17682. {
  17683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17684. {
  17685. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17686. }
  17687. }// END OF AC_QUANTITY
  17688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17689. }
  17690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17693. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17696. }
  17697. //2.3====================================== Power.Active.Import =========================================
  17698. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17699. {
  17700. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17701. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17702. {
  17703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17704. {
  17705. tempIndex = ((gun_index==2) ? 1: 0);
  17706. }
  17707. else
  17708. {
  17709. tempIndex = gun_index;
  17710. }
  17711. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17712. {
  17713. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17714. {
  17715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17716. }
  17717. } // End for CHAdeMO_QUANTITY
  17718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17719. }
  17720. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17721. {
  17722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17723. {
  17724. tempIndex = ((gun_index==2) ? 1: 0);
  17725. }
  17726. else
  17727. {
  17728. tempIndex = gun_index;
  17729. }
  17730. for (int index = 0; index < CCS_QUANTITY; index++)
  17731. {
  17732. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17733. {
  17734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17735. }
  17736. } // END for CCS_QUANTITY
  17737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17738. }
  17739. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17740. {
  17741. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17742. {
  17743. tempIndex = ((gun_index==2) ? 1: 0);
  17744. }
  17745. else
  17746. {
  17747. tempIndex = gun_index;
  17748. }
  17749. for (int index = 0; index < GB_QUANTITY; index++)
  17750. {
  17751. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17752. {
  17753. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17754. }
  17755. }// END for GB_QUANTITY
  17756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17757. }
  17758. else if(gunType[gun_index] == GUN_TYPE_DO)
  17759. {
  17760. tempIndex = gun_index;
  17761. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17762. {
  17763. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17764. {
  17765. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17766. }
  17767. }
  17768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17769. }
  17770. else
  17771. {
  17772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17773. {
  17774. tempIndex = 2;
  17775. }
  17776. else
  17777. {
  17778. tempIndex = gun_index;
  17779. }
  17780. for (int index = 0; index < AC_QUANTITY; index++)
  17781. {
  17782. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17783. {
  17784. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17785. }
  17786. } // END for AC_QUANTITY
  17787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17788. }
  17789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17792. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17795. }
  17796. //2.4====================================== Voltage L1 ====================================================
  17797. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17798. {
  17799. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17800. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17801. {
  17802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17803. {
  17804. tempIndex = ((gun_index==2) ? 1: 0);
  17805. }
  17806. else
  17807. {
  17808. tempIndex = gun_index;
  17809. }
  17810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17811. {
  17812. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17813. {
  17814. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17815. }
  17816. } // END OF FOR CHAdeMO_QUANTITY
  17817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17818. }
  17819. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17820. {
  17821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17822. {
  17823. tempIndex = ((gun_index==2) ? 1: 0);
  17824. }
  17825. else
  17826. {
  17827. tempIndex = gun_index;
  17828. }
  17829. for (int index = 0; index < CCS_QUANTITY; index++)
  17830. {
  17831. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17832. {
  17833. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17834. }
  17835. } // END OF FOR CCS_QUANTITY
  17836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17837. }
  17838. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17839. {
  17840. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17841. {
  17842. tempIndex = ((gun_index==2) ? 1: 0);
  17843. }
  17844. else
  17845. {
  17846. tempIndex = gun_index;
  17847. }
  17848. for (int index = 0; index < GB_QUANTITY; index++)
  17849. {
  17850. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17851. {
  17852. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17853. }
  17854. } // END OF FOR GB_QUANTITY
  17855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17856. }
  17857. else if(gunType[gun_index] == GUN_TYPE_DO)
  17858. {
  17859. tempIndex = gun_index;
  17860. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17861. {
  17862. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17863. {
  17864. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17865. }
  17866. }
  17867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17868. }
  17869. else
  17870. {
  17871. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17872. {
  17873. tempIndex = 2;
  17874. }
  17875. else
  17876. {
  17877. tempIndex = gun_index;
  17878. }
  17879. for (int index = 0; index < AC_QUANTITY; index++)
  17880. {
  17881. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17882. {
  17883. 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
  17884. }
  17885. } // END OF FOR AC_QUANTITY
  17886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17887. }
  17888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17891. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17894. }
  17895. //2.5============================================== End SoC =========================================================
  17896. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17897. {
  17898. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17899. 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))
  17900. {
  17901. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17902. {
  17903. tempIndex = ((gun_index==2) ? 1: 0);
  17904. }
  17905. else
  17906. {
  17907. tempIndex = gun_index;
  17908. }
  17909. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17910. {
  17911. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17912. {
  17913. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17914. {
  17915. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17916. }
  17917. }
  17918. }
  17919. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17920. {
  17921. for (int index = 0; index < CCS_QUANTITY; index++)
  17922. {
  17923. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17924. {
  17925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17926. }
  17927. }
  17928. }
  17929. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17930. {
  17931. for (int index = 0; index < GB_QUANTITY; index++)
  17932. {
  17933. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17934. {
  17935. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17936. }
  17937. }
  17938. }
  17939. else if(gunType[gun_index] == GUN_TYPE_DO)
  17940. {
  17941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17942. {
  17943. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17944. {
  17945. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17946. }
  17947. }
  17948. }
  17949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17955. } // END FOR DC CASE
  17956. }
  17957. //2.6====================================== Current.Import L2 ==============================================
  17958. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17959. {
  17960. // AC 3 phase L2 current
  17961. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17962. {
  17963. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17964. {
  17965. tempIndex = 2;
  17966. }
  17967. else
  17968. {
  17969. tempIndex = gun_index;
  17970. }
  17971. for (int index = 0; index < AC_QUANTITY; index++)
  17972. {
  17973. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17974. {
  17975. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17976. }
  17977. }// End of for AC_QUANTITY
  17978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17979. }
  17980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17985. }
  17986. //2.7====================================== Current.Import L3 ==============================================
  17987. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17988. {
  17989. // AC 3 phase L3 current
  17990. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17991. {
  17992. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17993. {
  17994. tempIndex = 2;
  17995. }
  17996. else
  17997. {
  17998. tempIndex = gun_index;
  17999. }
  18000. for (int index = 0; index < AC_QUANTITY; index++)
  18001. {
  18002. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18003. {
  18004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18005. }
  18006. }// End of for AC_QUANTITY
  18007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18008. }
  18009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18014. }
  18015. //2.9====================================== Voltage L2 ====================================================
  18016. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18017. {
  18018. // AC 3 phase L2 volatge
  18019. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18020. {
  18021. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18022. {
  18023. tempIndex = 2;
  18024. }
  18025. else
  18026. {
  18027. tempIndex = gun_index;
  18028. }
  18029. for (int index = 0; index < AC_QUANTITY; index++)
  18030. {
  18031. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18032. {
  18033. 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
  18034. }
  18035. } // END OF FOR AC_QUANTITY
  18036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18037. }
  18038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18043. }
  18044. //2.10====================================== Voltage L3 ====================================================
  18045. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18046. {
  18047. // AC 3 phase L3 volatge
  18048. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18049. {
  18050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18051. {
  18052. tempIndex = 2;
  18053. }
  18054. else
  18055. {
  18056. tempIndex = gun_index;
  18057. }
  18058. for (int index = 0; index < AC_QUANTITY; index++)
  18059. {
  18060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18061. {
  18062. 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
  18063. }
  18064. } // END OF FOR AC_QUANTITY
  18065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18066. }
  18067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18072. }
  18073. //====================== Start SoC ================================
  18074. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18075. {
  18076. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18077. 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))
  18078. {
  18079. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18080. {
  18081. tempIndex = ((gun_index==2) ? 1: 0);
  18082. }
  18083. else
  18084. {
  18085. tempIndex = gun_index;
  18086. }
  18087. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18088. {
  18089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18090. {
  18091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18092. {
  18093. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18094. }
  18095. }
  18096. }
  18097. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18098. {
  18099. for (int index = 0; index < CCS_QUANTITY; index++)
  18100. {
  18101. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18102. {
  18103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18104. }
  18105. }
  18106. }
  18107. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18108. {
  18109. for (int index = 0; index < GB_QUANTITY; index++)
  18110. {
  18111. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18112. {
  18113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18114. }
  18115. }
  18116. }
  18117. else if(gunType[gun_index] == GUN_TYPE_DO)
  18118. {
  18119. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18120. {
  18121. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18122. {
  18123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18124. }
  18125. }
  18126. }
  18127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18133. } // END FOR DC CASE
  18134. }
  18135. //======================================== Message create ==============================================
  18136. json_object *StopTransaction = json_object_new_object();
  18137. json_object *transactionDatas = json_object_new_array();
  18138. json_object *sampledValues = json_object_new_array();
  18139. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18140. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18141. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18142. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18143. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18144. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18145. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18146. {
  18147. json_object *transactionData = json_object_new_object();
  18148. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18149. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18150. {
  18151. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18152. {
  18153. json_object *sampledValue = json_object_new_object();
  18154. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18155. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18156. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18157. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18158. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18159. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18160. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18161. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18162. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18163. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18164. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18165. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18166. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18167. json_object_array_add(sampledValues, sampledValue);
  18168. }
  18169. }
  18170. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18171. json_object_array_add(transactionDatas, transactionData);
  18172. }
  18173. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18174. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18175. ,MESSAGE_TYPE_CALL
  18176. ,guid
  18177. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18178. json_object_put(StopTransaction);
  18179. // Check File "TempStopTransaction" Exist
  18180. if((access(TempStopTransaction,F_OK))!=-1)
  18181. {
  18182. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18183. fclose(fopen(TempStopTransaction, "w"));
  18184. }
  18185. else
  18186. {
  18187. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18188. FILE *log = fopen(TempStopTransaction, "w+");
  18189. if(log == NULL)
  18190. {
  18191. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18192. return ;
  18193. }
  18194. else
  18195. {
  18196. fclose(log);
  18197. }
  18198. }
  18199. //Add TempStopTransaction | Update TempStopTransaction
  18200. // open file for writing
  18201. FILE *outfile;
  18202. outfile = fopen (TempStopTransaction, "a");
  18203. //DEBUG_INFO("data = %s\n", queuedata);
  18204. fputs(queuedata, outfile);
  18205. fputs("\n", outfile);
  18206. fclose (outfile);
  18207. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18208. OCPP_updatePeriodEnergy(gun_index);
  18209. }
  18210. void checkTempStopTransaction(int gun_index)
  18211. {
  18212. FILE *fptr1;
  18213. char ch;
  18214. char str[QUEUE_MESSAGE_LENGTH]={0};
  18215. char guid[37]={0};
  18216. char tempdata[65]={0};
  18217. char connectorStr[2]={0};
  18218. char TempStopTransaction[256];
  18219. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18220. fptr1 = fopen(TempStopTransaction, "r");
  18221. //TempStopTransaction格式: 槍號,StopTransaction封包
  18222. if (!fptr1)
  18223. {
  18224. //printf(" File not found or unable to open the input file!!\n");
  18225. return ;
  18226. }
  18227. ch=fgetc(fptr1);
  18228. //printf(" Now the content of the file %s is : \n",fname);
  18229. rewind(fptr1);
  18230. if(ch!=EOF)
  18231. {
  18232. // copy all contents to the temporary file except the specific line
  18233. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18234. {
  18235. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18236. if(str[0]=='\0')
  18237. {
  18238. break;
  18239. }
  18240. //TempStopTransaction格式: 槍號,StopTransaction封包
  18241. strncpy(connectorStr, str, 1);
  18242. if(atoi(connectorStr) != (gun_index+1))
  18243. {
  18244. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18245. fclose(fptr1);
  18246. return ;
  18247. }
  18248. //random_uuid(guid);
  18249. strncpy(guid, str+6, 36); //copy guid
  18250. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18251. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18252. {
  18253. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18254. }
  18255. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18256. OCPP_insert_transaction_msg(NO, str);
  18257. memset(str,0,ARRAY_SIZE(str));
  18258. }
  18259. }
  18260. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18261. fclose(fptr1);
  18262. remove(TempStopTransaction); // remove the original file
  18263. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18264. }
  18265. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18266. {
  18267. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18268. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18269. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18270. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18271. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18272. }
  18273. int GetWebSocketPingInterval(void)
  18274. {
  18275. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18276. }
  18277. int GetServerSign(void)
  18278. {
  18279. return server_sign;
  18280. }
  18281. uint8_t GetOcppSecurityProfile()
  18282. {
  18283. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18284. }
  18285. void GetOcppChargerBoxId(uint8_t *data)
  18286. {
  18287. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18288. }
  18289. void GetOcppSecurityPassword(uint8_t *data)
  18290. {
  18291. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18292. }
  18293. void SetOcppVersion(uint8_t *version)
  18294. {
  18295. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18296. DEBUG_INFO("ocpp version: %s\n", version);
  18297. if(strstr((char*)version, "ocpp1.6") != NULL)
  18298. {
  18299. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18300. }
  18301. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18302. {
  18303. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18304. system("pkill OcppBackend");
  18305. }
  18306. }
  18307. void SetServerSign(int value)
  18308. {
  18309. server_sign = value;
  18310. }
  18311. int GetBootNotificationInterval(void)
  18312. {
  18313. return BootNotificationInterval;
  18314. }
  18315. int GetInternetConn(void)
  18316. {
  18317. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18318. }
  18319. int GetBackendConnectionTimeout(void)
  18320. {
  18321. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18322. }
  18323. int isConnectorInitMode(int gun_index)
  18324. {
  18325. int tempIndex = 0;
  18326. int result = TRUE;
  18327. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18328. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18329. {
  18330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18331. {
  18332. tempIndex = ((gun_index==2) ? 1: 0);
  18333. }
  18334. else
  18335. {
  18336. tempIndex = gun_index;
  18337. }
  18338. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18339. {
  18340. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18341. {
  18342. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18343. } //end of the same index
  18344. }//end of for CHAdeMO_QUANTITY
  18345. }
  18346. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18347. {
  18348. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18349. {
  18350. tempIndex = ((gun_index==2) ? 1: 0);
  18351. }
  18352. else
  18353. {
  18354. tempIndex = gun_index;
  18355. }
  18356. for (int index = 0; index < CCS_QUANTITY; index++)
  18357. {
  18358. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18359. {
  18360. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18361. } //end of the same index
  18362. } // end of for CCS_QUANTITY
  18363. }
  18364. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18365. {
  18366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18367. {
  18368. tempIndex = ((gun_index==2) ? 1: 0);
  18369. }
  18370. else
  18371. {
  18372. tempIndex = gun_index;
  18373. }
  18374. for (int index = 0; index < GB_QUANTITY; index++)
  18375. {
  18376. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18377. {
  18378. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18379. } //end of the same index
  18380. } // end of for GB_QUANTITY
  18381. }
  18382. else if(gunType[gun_index] == GUN_TYPE_DO)
  18383. {
  18384. tempIndex = gun_index;
  18385. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18386. {
  18387. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18388. {
  18389. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18390. } //end of the same index
  18391. }
  18392. }
  18393. else
  18394. {
  18395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18396. {
  18397. tempIndex = 2;
  18398. }
  18399. else
  18400. {
  18401. tempIndex = gun_index;
  18402. }
  18403. for (int index = 0; index < AC_QUANTITY; index++)
  18404. {
  18405. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18406. {
  18407. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18408. }//end of the same index
  18409. }//end of for AC_QUANTITY
  18410. }
  18411. return result;
  18412. }
  18413. void refreshProcDogTimer()
  18414. {
  18415. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18416. }
  18417. void InitialSystemValue(void)
  18418. {
  18419. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18420. locallistVersion=0;
  18421. BootNotificationInterval = 0;
  18422. authorizeRetryTimes = 0;
  18423. GunStatusInterval = 10;
  18424. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18425. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18426. //Hear Beat
  18427. HeartBeatWithNOResponse = 0;
  18428. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18429. FirstHeartBeat = 0;
  18430. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18431. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18432. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18433. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18434. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18435. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18436. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18437. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18438. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18439. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18440. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18441. //Status && ConnectorPlugIn Setting
  18442. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18443. {
  18444. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18445. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18446. }
  18447. for (int index = 0; index < CCS_QUANTITY; index++)
  18448. {
  18449. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18450. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18451. }
  18452. for (int index = 0; index < GB_QUANTITY; index++)
  18453. {
  18454. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18455. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18456. }
  18457. for (int index = 0; index < AC_QUANTITY; index++)
  18458. {
  18459. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18460. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18461. }
  18462. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18463. {
  18464. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18465. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18466. }
  18467. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18468. {
  18469. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18470. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18471. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18472. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18473. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18474. }
  18475. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18476. refreshStartTimer(&clientTime.Heartbeat);
  18477. sleep(1);
  18478. }
  18479. void LWS_Send(char *str)
  18480. {
  18481. //=====================================================
  18482. // Check InternetConn 0: disconnected, 1: connected
  18483. //====================================================
  18484. if(GetOcppConnStatus() == 0)
  18485. {
  18486. DEBUG_INFO("offline now !!!\n");
  18487. return;
  18488. }
  18489. // Only disable isWebsocketSendable operation initiated by charger
  18490. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18491. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18492. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18493. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18494. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18495. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18496. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18497. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18498. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18499. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18500. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18501. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18502. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18503. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18504. {
  18505. isWebsocketSendable = 0;
  18506. }
  18507. pthread_mutex_lock(&lock_send);
  18508. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18509. sprintf((char *)SendBuffer, "%s", str);
  18510. SendBufLen = strlen(str);
  18511. pthread_mutex_unlock(&lock_send);
  18512. lws_callback_on_writable(wsi_client);
  18513. //lws_service(context, 0);
  18514. //sleep(1);
  18515. }
  18516. void LWS_SendNow(char *str)
  18517. {
  18518. //=====================================================
  18519. // Check InternetConn 0: disconnected, 1: connected
  18520. //====================================================
  18521. if(GetOcppConnStatus() == 0)
  18522. {
  18523. DEBUG_INFO("offline now !!!\n");
  18524. return;
  18525. }
  18526. // Only disable isWebsocketSendable operation initiated by charger
  18527. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18528. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18529. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18530. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18531. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18532. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18533. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18534. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18535. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18536. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18537. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18538. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18539. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18540. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18541. {
  18542. isWebsocketSendable = 0;
  18543. }
  18544. pthread_mutex_lock(&lock_send);
  18545. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18546. sprintf((char *)SendBuffer, "%s", str);
  18547. SendBufLen = strlen(str);
  18548. pthread_mutex_unlock(&lock_send);
  18549. lws_callback_on_writable(wsi_client);
  18550. lws_service(context, 0);
  18551. //sleep(1);
  18552. }