MessageHandler.c 847 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct InterLock
  92. {
  93. unsigned char isGetDiagnosticGoing:1;
  94. unsigned char isUpdateFirmwareGoing:1;
  95. }interLock;
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // TTIA routine
  356. //=========================================
  357. int sendTTIAInfo(uint8_t gun_index)
  358. {
  359. static int sn = 0;
  360. int result = FAIL;
  361. struct hostent *server;
  362. int udp_socket_fd;
  363. struct sockaddr_in dest_addr = {0};
  364. uint8_t tx_buf[80] = {0};
  365. uint8_t logBuf[256]= {0};
  366. uint8_t tx_len, tempIndex, socStart, socEnd;
  367. uint16_t PresentChargedEnergy;
  368. struct tm tmStart, tmEnd;
  369. DEBUG_INFO("sendTTIAInfo...\n");
  370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  371. {
  372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  373. {
  374. tempIndex = ((gun_index==2) ? 1: 0);
  375. }
  376. else
  377. {
  378. tempIndex = gun_index;
  379. }
  380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  381. {
  382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  383. {
  384. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  385. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  386. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  387. }
  388. }
  389. }
  390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  391. {
  392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  393. {
  394. tempIndex = ((gun_index==2) ? 1: 0);
  395. }
  396. else
  397. {
  398. tempIndex = gun_index;
  399. }
  400. for (int index = 0; index < CCS_QUANTITY; index++)
  401. {
  402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  403. {
  404. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  405. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  406. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  407. }
  408. }
  409. }
  410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < GB_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_DO)
  431. {
  432. tempIndex = gun_index;
  433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  434. {
  435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  436. {
  437. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  438. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  439. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  440. }
  441. }
  442. }
  443. else
  444. {
  445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  446. {
  447. tempIndex = 2;
  448. }
  449. else
  450. {
  451. tempIndex = gun_index;
  452. }
  453. for (int index = 0; index < AC_QUANTITY; index++)
  454. {
  455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  456. {
  457. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  458. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  459. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  460. }
  461. }// END
  462. }
  463. // Message assembly
  464. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  465. tx_buf[4] = 0x02; // Protocol Version
  466. tx_buf[5] = 0xb0; // Message ID
  467. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  468. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  469. tx_buf[8] = 0x00; // CarID low byte
  470. tx_buf[9] = 0x00; // CarID high byte
  471. tx_buf[10] = 0x00; // ID Storage
  472. tx_buf[11] = 0x00; // Driver lowest byte
  473. tx_buf[12] = 0x00; // Driver 2nd byte
  474. tx_buf[13] = 0x00; // Driver 3rd byte
  475. tx_buf[14] = 0x00; // Driver highest byte
  476. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  477. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  478. tx_buf[17] = 0x00; // Reserve
  479. tx_buf[18] = 60 & 0xff; // Payload length low byte
  480. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  481. // EVSE provider
  482. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  483. // EVSE provider
  484. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  485. // EVSE id
  486. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  487. // Connector id
  488. tx_buf[37] = gun_index;
  489. // EVSE station
  490. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  491. // Vehicle SN
  492. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  493. // Mileage
  494. tx_buf[61] = 0x00; // lowest byte
  495. tx_buf[62] = 0x00; // 2nd byte
  496. tx_buf[63] = 0x00; // highest byte
  497. // Start date time 6 bytes
  498. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  499. {
  500. struct tm *tmTarget;
  501. struct timeb tbTarget;
  502. tmStart.tm_year -= 1900;
  503. tmStart.tm_mon -= 1;
  504. tmStart.tm_gmtoff = 0;
  505. tbTarget.time = mktime(&tmStart);
  506. tbTarget.timezone = 0;
  507. tbTarget.time += (8*3600);
  508. tmTarget = gmtime(&tbTarget.time);
  509. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  510. tx_buf[65] = (tmTarget->tm_mon+1);
  511. tx_buf[66] = tmTarget->tm_mday;
  512. tx_buf[67] = tmTarget->tm_hour;
  513. tx_buf[68] = tmTarget->tm_min;
  514. tx_buf[69] = tmTarget->tm_sec;
  515. }
  516. // Stop date time 6 bytes
  517. 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))
  518. {
  519. struct tm *tmTarget;
  520. struct timeb tbTarget;
  521. tmEnd.tm_year -= 1900;
  522. tmEnd.tm_mon -= 1;
  523. tmEnd.tm_gmtoff = 0;
  524. tbTarget.time = mktime(&tmEnd);
  525. tbTarget.timezone = 0;
  526. tbTarget.time += (8*3600);
  527. tmTarget = gmtime(&tbTarget.time);
  528. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  529. tx_buf[71] = (tmTarget->tm_mon+1);
  530. tx_buf[72] = tmTarget->tm_mday;
  531. tx_buf[73] = tmTarget->tm_hour;
  532. tx_buf[74] = tmTarget->tm_min;
  533. tx_buf[75] = tmTarget->tm_sec;
  534. }
  535. // Session energy 2 bytes
  536. tx_buf[76] = PresentChargedEnergy & 0xff;
  537. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  538. // Start SOC 1 byte
  539. tx_buf[78] = socStart;
  540. // Stop SOC 1 byte
  541. tx_buf[79] = socEnd;
  542. // Open socket
  543. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  544. if(udp_socket_fd == -1)
  545. {
  546. DEBUG_ERROR("UDP socket create failed!\n");
  547. }
  548. else
  549. {
  550. // Get server DNS entry
  551. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  552. if (server == NULL)
  553. {
  554. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  555. }
  556. else
  557. {
  558. // Build the server's Internet address
  559. bzero((char *) &dest_addr, sizeof(dest_addr));
  560. dest_addr.sin_family = AF_INET;
  561. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  562. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  563. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  564. {
  565. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  566. {
  567. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  568. }
  569. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  570. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  571. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  572. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  573. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  574. DEBUG_TTIA_INFO("---------- Header ----------\n");
  575. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  576. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  577. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  578. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  579. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  580. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  581. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  582. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  583. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  584. DEBUG_TTIA_INFO("Len: 0x3C\n");
  585. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  586. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  587. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  588. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  589. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  590. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  591. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  592. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  593. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  594. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  595. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  596. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  597. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  598. DEBUG_TTIA_INFO("=========================================\n");
  599. sn++;
  600. result = PASS;
  601. }
  602. else
  603. {
  604. DEBUG_ERROR("UDP sent out fail.\n");
  605. }
  606. }
  607. }
  608. return result;
  609. }
  610. //=========================================
  611. // Save configuration
  612. //=========================================
  613. int runShellCmd(const char*cmd)
  614. {
  615. int result = FAIL;
  616. char buf[256];
  617. FILE *fp;
  618. fp = popen(cmd, "r");
  619. if(fp != NULL)
  620. {
  621. while(fgets(buf, sizeof(buf), fp) != NULL)
  622. {
  623. DEBUG_INFO("%s\n", buf);
  624. }
  625. result = PASS;
  626. }
  627. pclose(fp);
  628. return result;
  629. }
  630. int StoreUsrConfigData(struct SysConfigData *UsrData)
  631. {
  632. int result = PASS;
  633. int fd,wrd;
  634. unsigned int i,Chk;
  635. unsigned char *ptr, *BufTmp;
  636. int MtdBlockSize = 0x300000;
  637. Chk=0;
  638. ptr=(unsigned char *)UsrData;
  639. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  640. {
  641. memset(BufTmp,0,MtdBlockSize);
  642. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  643. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  644. Chk+=*(BufTmp+i);
  645. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  646. // Output configuration to file.
  647. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  648. if (fd < 0)
  649. {
  650. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  651. free(BufTmp);
  652. return 0;
  653. }
  654. wrd=write(fd, BufTmp, MtdBlockSize);
  655. close(fd);
  656. if(wrd<MtdBlockSize)
  657. {
  658. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  659. free(BufTmp);
  660. return 0;
  661. }
  662. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  663. DEBUG_INFO("Erase /dev/mtd10.\n");
  664. runShellCmd("flash_erase /dev/mtd10 0 0");
  665. DEBUG_INFO("Write /dev/mtd10.\n");
  666. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  667. DEBUG_INFO("Erase /dev/mtd11.\n");
  668. runShellCmd("flash_erase /dev/mtd11 0 0");
  669. DEBUG_INFO("Write /dev/mtd11.\n");
  670. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  671. system("rm -f /mnt/EvseConfig.bin");
  672. DEBUG_INFO("EvseConfig write to flash OK\n");
  673. }
  674. else
  675. {
  676. DEBUG_ERROR("alloc BlockSize NG\r\n");
  677. result = FAIL;
  678. }
  679. if(BufTmp!=NULL)
  680. free(BufTmp);
  681. return result;
  682. }
  683. //=========================================
  684. // Sqlite3 related function
  685. //=========================================
  686. static int selectSqlCount = 0;
  687. static int callback(void *data, int argc, char **argv, char **azColName){
  688. int i;
  689. //printf("%s: ", (const char*)data);
  690. selectSqlCount = argc;
  691. for(i = 0; i<argc; i++){
  692. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  693. }
  694. //printf("\n");
  695. return 0;
  696. }
  697. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  698. //int i;
  699. //printf("%s:\n", (const char*)data);
  700. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  701. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  702. return 0;
  703. }
  704. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  705. //printf("%s:\n", (const char*)data);
  706. //idTag
  707. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  708. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  709. //parentIdTag
  710. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  711. //expir_date
  712. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  713. //status
  714. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  715. //version
  716. if(columenCount > 5)
  717. idTagQuery.listVersionInt = atoi(columnValue[5]);
  718. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  719. return 0;
  720. }
  721. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  722. {
  723. // localversion = argv[5] ? atoi(argv[5]) : 0;
  724. // printf("localversion=%d\n", localversion);
  725. return 0;
  726. }
  727. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  728. {
  729. for (int i = 0; i < n_columns; i++)
  730. {
  731. DEBUG_INFO("%s\t", col_values[i]);
  732. }
  733. DEBUG_INFO("\n");
  734. return 0;
  735. }
  736. int OCPP_cleanLocalCache()
  737. {
  738. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  739. char *errMsg = 0;
  740. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  741. if (SQLITE_OK != rc)
  742. {
  743. DEBUG_INFO("SQL error: %s\n",errMsg);
  744. return FALSE;
  745. }
  746. return TRUE;
  747. }
  748. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  749. {
  750. int isSuccess = TRUE;
  751. int ret = 0;
  752. //const char* data = "Callback function called";
  753. char sql[300];
  754. char zErrMsg[200];
  755. memset(sql, 0, 300);
  756. memset(zErrMsg, 0, 200);
  757. 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);
  758. //* Execute SQL statement */
  759. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  760. if( ret != SQLITE_OK )
  761. {
  762. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  763. isSuccess = FALSE;
  764. }
  765. return isSuccess;
  766. }
  767. void OCPP_getIdTagFromLocalCache(char idTag[])
  768. {
  769. int rc = 0;
  770. char sql[100];
  771. char zErrMsg[100];
  772. memset(sql, 0, 100);
  773. memset(zErrMsg, 0, 100);
  774. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  775. memset(&idTagQuery, 0, sizeof(idTagQuery));
  776. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  777. /* Execute SQL statement */
  778. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  779. if( rc != SQLITE_OK )
  780. {
  781. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  782. }
  783. }
  784. void OCPP_getListVerion()
  785. {
  786. int rc = 0;
  787. // const char* data = "Callback function called";
  788. char sql[100];
  789. char zErrMsg[100];
  790. memset(sql, 0, 100);
  791. memset(zErrMsg, 0, 100);
  792. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  793. /* Execute SQL statement */
  794. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  795. if( rc != SQLITE_OK )
  796. {
  797. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  798. }
  799. }
  800. void OCPP_get_TableAuthlocalAllData(void)
  801. {
  802. int rc = 0;
  803. char sql[100];
  804. char zErrMsg[100];
  805. memset(sql, 0, 100);
  806. memset(zErrMsg, 0, 100);
  807. sprintf(sql,"select * from ocpp_auth_local ");
  808. /* Execute SQL statement */
  809. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  810. if( rc != SQLITE_OK )
  811. {
  812. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  813. }
  814. //return ver;
  815. }
  816. int OCPP_cleanLocalList()
  817. {
  818. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  819. char *errMsg = 0;
  820. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  821. if (SQLITE_OK != rc)
  822. {
  823. DEBUG_INFO("%s\n",errMsg);
  824. return FALSE;
  825. }
  826. return TRUE;
  827. }
  828. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  829. {
  830. int isSuccess = FALSE;
  831. int ret = 0;
  832. //const char* data = "Callback function called";
  833. char sql[300];
  834. char zErrMsg[200];
  835. memset(sql, 0, 300);
  836. memset(zErrMsg, 0, 200);
  837. 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);
  838. //* Execute SQL statement */
  839. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  840. if( ret != SQLITE_OK )
  841. {
  842. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  843. return isSuccess;
  844. }
  845. memset(sql, 0, 300);
  846. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  847. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  848. if( ret != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. return isSuccess;
  852. }
  853. isSuccess = TRUE;
  854. return isSuccess;
  855. }
  856. void OCPP_getIdTagFromLocalList(char idTag[])
  857. {
  858. int rc = 0;
  859. // const char* data = "Callback function called";
  860. char sql[100];
  861. char zErrMsg[100];
  862. memset(sql, 0, 100);
  863. memset(zErrMsg, 0, 100);
  864. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  865. memset(&idTagQuery, 0, sizeof(idTagQuery));
  866. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  867. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  868. /* Execute SQL statement */
  869. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  870. if( rc != SQLITE_OK )
  871. {
  872. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  873. }
  874. //return ver;
  875. }
  876. void OCPP_deleteIdTagFromLocalList(char idTag[])
  877. {
  878. //int ver = 0;
  879. //int isSuccess = FALSE;
  880. int rc = 0;
  881. char sql[100];
  882. char zErrMsg[100];
  883. memset(sql, 0, 100);
  884. memset(zErrMsg, 0, 100);
  885. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  886. //* Execute SQL statement */
  887. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  888. if( rc != SQLITE_OK )
  889. {
  890. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  891. }
  892. }
  893. int getCurrentYear()
  894. {
  895. int result = 0;
  896. time_t CurrentTime;
  897. struct tm *tm;
  898. CurrentTime = time(NULL);
  899. tm=localtime(&CurrentTime);
  900. result = (tm->tm_year + 1900);
  901. return result;
  902. }
  903. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  904. {
  905. int result = PASS;
  906. char* errMsg = NULL;
  907. char sqlStr[8192];
  908. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  909. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  910. {
  911. result = FAIL;
  912. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  913. }
  914. 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));
  915. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  916. {
  917. result = FAIL;
  918. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  919. }
  920. return result;
  921. }
  922. //==========================================
  923. // Check time passed since today
  924. //==========================================
  925. long long DiffTimebWithNow(struct timeb ST)
  926. {
  927. //return milli-second
  928. struct timeb ET;
  929. long long StartTime,StopTime;
  930. ftime(&ET);
  931. StartTime=(long long)ST.time;
  932. StopTime=(long long)ET.time;
  933. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  934. }
  935. int getTimePassSinceToday(uint8_t gun_index)
  936. {
  937. int result = -1;
  938. static time_t lastTime[4];
  939. time_t t;
  940. struct tm *tmStartToday;
  941. struct timeb tbStartToday;
  942. t=time(NULL);
  943. if(difftime(t, lastTime[gun_index])>0)
  944. {
  945. tmStartToday=localtime(&t);
  946. tmStartToday->tm_hour = 0;
  947. tmStartToday->tm_min = 0;
  948. tmStartToday->tm_sec = 0;
  949. tbStartToday.time = mktime(tmStartToday);
  950. tbStartToday.millitm = 0;
  951. result = DiffTimebWithNow(tbStartToday)/1000;
  952. lastTime[gun_index] = t;
  953. }
  954. return result;
  955. }
  956. void getNowDatetime(uint8_t *data)
  957. {
  958. time_t t = time(NULL);
  959. struct tm tm = *localtime(&t);
  960. 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);
  961. }
  962. int syncDateTimeRTC(uint8_t *data)
  963. {
  964. struct ParsingResult
  965. {
  966. int result;
  967. int scanedElement;
  968. int year;
  969. int month;
  970. int mday;
  971. int hour;
  972. int min;
  973. int sec;
  974. int tz_hour;
  975. int tz_min;
  976. float minSec;
  977. }result;
  978. struct tm tmOrg;
  979. struct tm *tmTarget;
  980. struct timeb tbTarget;
  981. char buf[128];
  982. memset(&result, 0x00, sizeof(struct ParsingResult));
  983. result.result = PASS;
  984. if(strstr((char*)data, ".") != NULL)
  985. {
  986. // Original data with mini second
  987. if(strstr((char*)data, "Z") != NULL)
  988. {
  989. // Original data with Z
  990. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  991. &result.year,
  992. &result.month,
  993. &result.mday,
  994. &result.hour,
  995. &result.min,
  996. &result.sec,
  997. &result.minSec);
  998. }
  999. else
  1000. {
  1001. // Original data without Z
  1002. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1003. &result.year,
  1004. &result.month,
  1005. &result.mday,
  1006. &result.hour,
  1007. &result.min,
  1008. &result.sec,
  1009. &result.minSec,
  1010. &result.tz_hour,
  1011. &result.tz_min);
  1012. }
  1013. }
  1014. else
  1015. {
  1016. // Original data without mini second
  1017. if(strstr((char*)data, "Z") != NULL)
  1018. {
  1019. // Original data with Z
  1020. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1021. &result.year,
  1022. &result.month,
  1023. &result.mday,
  1024. &result.hour,
  1025. &result.min,
  1026. &result.sec);
  1027. }
  1028. else
  1029. {
  1030. // Original data without Z
  1031. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1032. &result.year,
  1033. &result.month,
  1034. &result.mday,
  1035. &result.hour,
  1036. &result.min,
  1037. &result.sec,
  1038. &result.tz_hour,
  1039. &result.tz_min);
  1040. }
  1041. }
  1042. tmOrg.tm_year = result.year - 1900;
  1043. tmOrg.tm_mon = result.month - 1;
  1044. tmOrg.tm_mday = result.mday;
  1045. tmOrg.tm_hour = result.hour;
  1046. tmOrg.tm_min = result.min;
  1047. tmOrg.tm_sec = result.sec;
  1048. tmOrg.tm_gmtoff = 0;
  1049. tbTarget.time = mktime(&tmOrg);
  1050. tbTarget.timezone = 0;
  1051. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1052. tmTarget = gmtime(&tbTarget.time);
  1053. 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);
  1054. //DEBUG_INFO(" org date time: %s\n", data);
  1055. //DEBUG_INFO("parse date time: %s\n", buf);
  1056. system(buf);
  1057. system("/sbin/hwclock -w --systohc");
  1058. if(result.scanedElement < 6)
  1059. result.result = FAIL;
  1060. return result.result;
  1061. }
  1062. //==========================================
  1063. // GetCompositeSchedule logic related function
  1064. //==========================================
  1065. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1066. {
  1067. //return milli-second
  1068. unsigned int StartTime,StopTime;
  1069. StartTime=(unsigned int)ST.time;
  1070. StopTime=(unsigned int)ET.time;
  1071. return (StopTime-StartTime);
  1072. }
  1073. int DiffTimebWithNowSec(struct timeb ST)
  1074. {
  1075. //return milli-second
  1076. struct timeb ET;
  1077. unsigned int StartTime,StopTime;
  1078. ftime(&ET);
  1079. StartTime=(unsigned int)ST.time;
  1080. StopTime=(unsigned int)ET.time;
  1081. return (StopTime-StartTime);
  1082. }
  1083. int getStartStop(uint8_t *start, uint8_t *stop)
  1084. {
  1085. int result = -1;
  1086. struct tm tmStart;
  1087. struct timeb tbStart;
  1088. struct tm tmStop;
  1089. struct timeb tbStop;
  1090. 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) &&
  1091. (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))
  1092. {
  1093. //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);
  1094. //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);
  1095. tmStart.tm_year -= 1900;
  1096. tmStart.tm_mon -= 1;
  1097. tbStart.time = mktime(&tmStart);
  1098. tbStart.millitm = 0;
  1099. tmStop.tm_year -= 1900;
  1100. tmStop.tm_mon -= 1;
  1101. tbStop.time = mktime(&tmStop);
  1102. tbStop.millitm = 0;
  1103. result = DiffTimebSec(tbStart, tbStop);
  1104. //DEBUG_INFO("getStartStop(): %d\n", result);
  1105. }
  1106. else
  1107. {
  1108. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1109. }
  1110. return result;
  1111. }
  1112. int isOvertNow(uint8_t *start)
  1113. {
  1114. int result = NO;
  1115. struct ParsingResult
  1116. {
  1117. int result;
  1118. int scanedElement;
  1119. int year;
  1120. int month;
  1121. int mday;
  1122. int hour;
  1123. int min;
  1124. int sec;
  1125. int tz_hour;
  1126. int tz_min;
  1127. float minSec;
  1128. }parsingResult;
  1129. struct tm tmStart;
  1130. struct timeb tbStart;
  1131. if(strstr((char*)start, ".") != NULL)
  1132. {
  1133. // Original data with mini second
  1134. if(strstr((char*)start, "Z") != NULL)
  1135. {
  1136. // Original data with Z
  1137. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1138. &parsingResult.year,
  1139. &parsingResult.month,
  1140. &parsingResult.mday,
  1141. &parsingResult.hour,
  1142. &parsingResult.min,
  1143. &parsingResult.sec,
  1144. &parsingResult.minSec);
  1145. }
  1146. else
  1147. {
  1148. // Original data without Z
  1149. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1150. &parsingResult.year,
  1151. &parsingResult.month,
  1152. &parsingResult.mday,
  1153. &parsingResult.hour,
  1154. &parsingResult.min,
  1155. &parsingResult.sec,
  1156. &parsingResult.minSec,
  1157. &parsingResult.tz_hour,
  1158. &parsingResult.tz_min);
  1159. }
  1160. }
  1161. else
  1162. {
  1163. // Original data without mini second
  1164. if(strstr((char*)start, "Z") != NULL)
  1165. {
  1166. // Original data with Z
  1167. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1168. &parsingResult.year,
  1169. &parsingResult.month,
  1170. &parsingResult.mday,
  1171. &parsingResult.hour,
  1172. &parsingResult.min,
  1173. &parsingResult.sec);
  1174. }
  1175. else
  1176. {
  1177. // Original data without Z
  1178. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1179. &parsingResult.year,
  1180. &parsingResult.month,
  1181. &parsingResult.mday,
  1182. &parsingResult.hour,
  1183. &parsingResult.min,
  1184. &parsingResult.sec,
  1185. &parsingResult.tz_hour,
  1186. &parsingResult.tz_min);
  1187. }
  1188. }
  1189. if(parsingResult.scanedElement >= 6)
  1190. {
  1191. tmStart.tm_year = parsingResult.year - 1900;
  1192. tmStart.tm_mon = parsingResult.month - 1;
  1193. tmStart.tm_mday = parsingResult.mday;
  1194. tmStart.tm_hour = parsingResult.hour;
  1195. tmStart.tm_min = parsingResult.min;
  1196. tmStart.tm_sec = parsingResult.sec;
  1197. tmStart.tm_gmtoff = 0;
  1198. tbStart.time = mktime(&tmStart);
  1199. tbStart.timezone = 0;
  1200. tbStart.millitm = 0;
  1201. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1202. if(DiffTimebWithNowSec(tbStart) <= 0)
  1203. result = NO;
  1204. else
  1205. result = YES;
  1206. }
  1207. else
  1208. {
  1209. DEBUG_WARN("Start date parsing error.\n");
  1210. }
  1211. return result;
  1212. }
  1213. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1214. {
  1215. int result = -1;
  1216. struct tm tmStart;
  1217. struct timeb tbStart;
  1218. struct tm tmStop;
  1219. struct timeb tbStop;
  1220. 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) &&
  1221. (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))
  1222. {
  1223. tmStart.tm_year -= 1900;
  1224. tmStart.tm_mon -= 1;
  1225. tbStart.time = mktime(&tmStart);
  1226. tbStart.millitm = 0;
  1227. tmStop.tm_year -= 1900;
  1228. tmStop.tm_mon -= 1;
  1229. tbStop.time = mktime(&tmStop);
  1230. tbStop.millitm = 0;
  1231. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1232. }
  1233. return result;
  1234. }
  1235. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1236. {
  1237. FILE *fp;
  1238. char profileFileName[128];
  1239. char *line = NULL;
  1240. size_t len = 0;
  1241. time_t CurrentTime;
  1242. struct tm *tmComposite;
  1243. struct StructChargingProfile maxProfile;
  1244. uint8_t limitMax=0;
  1245. int compositePeriodIdx = 0;
  1246. CurrentTime = time(NULL);
  1247. tmComposite=localtime(&CurrentTime);
  1248. 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);
  1249. if(isUnitA)
  1250. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1251. else
  1252. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1253. compositeProfile->ChargingSchedule.Duration = durationReq;
  1254. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1255. {
  1256. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1257. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1258. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1259. }
  1260. compositeProfile->ChargingProfileId = 0;
  1261. compositeProfile->StackLevel = 99 ;
  1262. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1263. maxProfile.ChargingProfileId = -1;
  1264. maxProfile.ChargingSchedule.Duration = -1;
  1265. system("rm -f /tmp/*.json");
  1266. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1267. // Search max profile
  1268. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1269. if((access(profileFileName, F_OK))!=-1)
  1270. {
  1271. fp = fopen(profileFileName, "r");
  1272. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1273. {
  1274. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1275. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1277. }
  1278. maxProfile.ChargingProfileId = -1;
  1279. maxProfile.StackLevel = -1;
  1280. while(getline(&line, &len, fp) != -1)
  1281. {
  1282. json_object *obj = NULL;
  1283. obj = json_tokener_parse(line);
  1284. if(is_error(obj))
  1285. {
  1286. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1287. }
  1288. else
  1289. {
  1290. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1291. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1292. )
  1293. {
  1294. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1295. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1296. )
  1297. {
  1298. struct tm tmFrom, tmTo;
  1299. struct timeb tbFrom, tbTo;
  1300. 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) &&
  1301. (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))
  1302. {
  1303. tmFrom.tm_year -= 1900;
  1304. tmFrom.tm_mon -= 1;
  1305. tbFrom.time = mktime(&tmFrom);
  1306. tmTo.tm_year -= 1900;
  1307. tmTo.tm_mon -= 1;
  1308. tbTo.time = mktime(&tmTo);
  1309. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1310. {
  1311. if(maxProfile.ChargingProfileId == -1)
  1312. DEBUG_INFO("MaxProfile found.\n");
  1313. else
  1314. DEBUG_INFO("MaxProfile updated.\n");
  1315. // Required item
  1316. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1317. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1318. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1319. if(isUnitA)
  1320. {
  1321. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1322. 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++)
  1323. {
  1324. 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"));
  1325. 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?
  1326. 3:
  1327. 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")));
  1328. 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")));
  1329. }
  1330. }
  1331. else
  1332. {
  1333. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1334. 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++)
  1335. {
  1336. 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"));
  1337. 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?
  1338. 3:
  1339. 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")));
  1340. 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));
  1341. }
  1342. }
  1343. // Optional item
  1344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1345. {
  1346. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1347. }
  1348. else
  1349. {
  1350. sprintf((char*)maxProfile.ValidFrom, " ");
  1351. }
  1352. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1353. {
  1354. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1355. }
  1356. else
  1357. {
  1358. sprintf((char*)maxProfile.ValidTo, " ");
  1359. }
  1360. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1361. {
  1362. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1363. }
  1364. else
  1365. {
  1366. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1367. }
  1368. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1369. {
  1370. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1371. }
  1372. else
  1373. {
  1374. maxProfile.TransactionId = -1;
  1375. }
  1376. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1377. {
  1378. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1379. }
  1380. else
  1381. {
  1382. maxProfile.ChargingSchedule.Duration = 86400;
  1383. }
  1384. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1385. {
  1386. 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")));
  1387. }
  1388. else
  1389. {
  1390. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1391. }
  1392. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1393. {
  1394. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1395. }
  1396. else
  1397. {
  1398. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1399. }
  1400. }
  1401. }
  1402. }
  1403. else
  1404. {
  1405. if(maxProfile.ChargingProfileId == -1)
  1406. DEBUG_INFO("MaxProfile found.\n");
  1407. else
  1408. DEBUG_INFO("MaxProfile updated.\n");
  1409. // Required item
  1410. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1411. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1412. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1413. if(isUnitA)
  1414. {
  1415. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1416. 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++)
  1417. {
  1418. 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"));
  1419. 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?
  1420. 3:
  1421. 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")));
  1422. 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")));
  1423. }
  1424. }
  1425. else
  1426. {
  1427. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1428. 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++)
  1429. {
  1430. 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"));
  1431. 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?
  1432. 3:
  1433. 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")));
  1434. 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));
  1435. }
  1436. }
  1437. // Optional item
  1438. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1439. {
  1440. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1441. }
  1442. else
  1443. {
  1444. sprintf((char*)maxProfile.ValidFrom, " ");
  1445. }
  1446. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1447. {
  1448. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1449. }
  1450. else
  1451. {
  1452. sprintf((char*)maxProfile.ValidTo, " ");
  1453. }
  1454. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1455. {
  1456. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1457. }
  1458. else
  1459. {
  1460. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1461. }
  1462. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1463. {
  1464. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1465. }
  1466. else
  1467. {
  1468. maxProfile.TransactionId = -1;
  1469. }
  1470. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1471. {
  1472. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1473. }
  1474. else
  1475. {
  1476. maxProfile.ChargingSchedule.Duration = 86400;
  1477. }
  1478. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1479. {
  1480. 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")));
  1481. }
  1482. else
  1483. {
  1484. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1485. }
  1486. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1487. {
  1488. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1489. }
  1490. else
  1491. {
  1492. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1493. }
  1494. }
  1495. }
  1496. }
  1497. json_object_put(obj);
  1498. }
  1499. fclose(fp);
  1500. /*
  1501. if(maxProfile.ChargingProfileId !=-1)
  1502. {
  1503. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1504. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1505. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1506. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1507. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1508. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1509. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1510. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1511. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1512. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1513. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1514. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1515. {
  1516. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1517. {
  1518. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1519. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1520. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1521. }
  1522. }
  1523. }
  1524. else
  1525. DEBUG_INFO("MaxProfile not found.\n");
  1526. DEBUG_INFO("------------------------------------\n");*/
  1527. }
  1528. if(maxProfile.ChargingProfileId != -1)
  1529. {
  1530. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1531. {
  1532. if(maxProfile.ChargingSchedule.Duration != -1)
  1533. {
  1534. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1535. 0:
  1536. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1537. }
  1538. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1539. {
  1540. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1541. {
  1542. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1543. 0:
  1544. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1545. if(idxPeriod > 0)
  1546. {
  1547. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1548. {
  1549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1550. }
  1551. }
  1552. }
  1553. }
  1554. }
  1555. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1556. {
  1557. if(maxProfile.ChargingSchedule.Duration != -1)
  1558. {
  1559. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1560. }
  1561. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1562. {
  1563. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1564. {
  1565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1566. if(idxPeriod > 0)
  1567. {
  1568. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1569. {
  1570. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. else
  1577. {
  1578. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1579. {
  1580. if(maxProfile.ChargingSchedule.Duration != -1)
  1581. {
  1582. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1583. 0:
  1584. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1585. }
  1586. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1587. {
  1588. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1589. {
  1590. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1591. 0:
  1592. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1593. if(idxPeriod > 0)
  1594. {
  1595. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1596. {
  1597. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1598. }
  1599. }
  1600. }
  1601. }
  1602. }
  1603. else
  1604. {
  1605. if(maxProfile.ChargingSchedule.Duration != -1)
  1606. {
  1607. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1608. 0:
  1609. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1610. }
  1611. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1612. {
  1613. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1614. {
  1615. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1616. 0:
  1617. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1618. if(idxPeriod > 0)
  1619. {
  1620. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1621. {
  1622. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. /*
  1630. DEBUG_INFO("MaxProfile after align.\n");
  1631. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1632. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1633. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1634. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1635. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1636. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1637. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1638. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1639. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1640. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1641. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1645. {
  1646. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1647. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1648. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1649. }
  1650. }
  1651. DEBUG_INFO("------------------------------------\n");*/
  1652. }
  1653. // Find each profile period quantity
  1654. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1655. {
  1656. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1657. limitMax = idx+1;
  1658. }
  1659. if(maxProfile.ChargingProfileId != -1)
  1660. {
  1661. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1662. {
  1663. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1664. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1665. (maxProfile.ChargingSchedule.Duration > 0))
  1666. {
  1667. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1668. {
  1669. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1670. compositePeriodIdx++;
  1671. }
  1672. else
  1673. {
  1674. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1675. }
  1676. }
  1677. }
  1678. }
  1679. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1680. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1681. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1682. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1683. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1684. {
  1685. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1686. {
  1687. compositeProfile->ChargingProfileId = 1;
  1688. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1689. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1690. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1691. }
  1692. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1693. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1694. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1695. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1696. }
  1697. if(line)
  1698. free(line);
  1699. }
  1700. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1701. {
  1702. FILE *fp;
  1703. char profileFileName[128];
  1704. char *line = NULL;
  1705. size_t len = 0;
  1706. time_t CurrentTime;
  1707. struct tm *tmComposite;
  1708. struct StructChargingProfile maxProfile;
  1709. struct StructChargingProfile defaultTxProfile;
  1710. struct StructChargingProfile txProfile;
  1711. struct StructChargingSchedulePeriod tmpPeriod;
  1712. uint8_t limitMax=0;
  1713. uint8_t limitDef=0;
  1714. uint8_t limitTx=0;
  1715. int compositePeriodIdx = 0;
  1716. CurrentTime = time(NULL);
  1717. tmComposite=localtime(&CurrentTime);
  1718. 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);
  1719. if(isUnitA)
  1720. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1721. else
  1722. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1723. compositeProfile->ChargingSchedule.Duration = durationReq;
  1724. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1725. {
  1726. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1727. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1728. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1729. }
  1730. compositeProfile->ChargingProfileId = 0;
  1731. compositeProfile->StackLevel = 99 ;
  1732. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1733. maxProfile.ChargingProfileId = -1;
  1734. defaultTxProfile.ChargingProfileId = -1;
  1735. txProfile.ChargingProfileId = -1;
  1736. maxProfile.ChargingSchedule.Duration = -1;
  1737. defaultTxProfile.ChargingSchedule.Duration = -1;
  1738. txProfile.ChargingSchedule.Duration = -1;
  1739. system("rm -f /tmp/*.json");
  1740. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1741. /*
  1742. * Search valid charging profile
  1743. */
  1744. //DEBUG_INFO("====================================\n");
  1745. // Search tx profile
  1746. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1747. if((access(profileFileName, F_OK))!=-1)
  1748. {
  1749. fp = fopen(profileFileName, "r");
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1755. }
  1756. txProfile.ChargingProfileId = -1;
  1757. txProfile.StackLevel = -1;
  1758. while(getline(&line, &len, fp) != -1)
  1759. {
  1760. json_object *obj = NULL;
  1761. obj = json_tokener_parse(line);
  1762. if(is_error(obj))
  1763. {
  1764. DEBUG_ERROR("Parse txProfile from file error.\n");
  1765. }
  1766. else
  1767. {
  1768. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1769. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1770. )
  1771. {
  1772. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1773. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1774. )
  1775. {
  1776. struct tm tmFrom, tmTo;
  1777. struct timeb tbFrom, tbTo;
  1778. 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) &&
  1779. (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))
  1780. {
  1781. tmFrom.tm_year -= 1900;
  1782. tmFrom.tm_mon -= 1;
  1783. tbFrom.time = mktime(&tmFrom);
  1784. tmTo.tm_year -= 1900;
  1785. tmTo.tm_mon -= 1;
  1786. tbTo.time = mktime(&tmTo);
  1787. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1788. {
  1789. if(txProfile.ChargingProfileId == -1)
  1790. DEBUG_INFO("TxProfile found.\n");
  1791. else
  1792. DEBUG_INFO("TxProfile updated.\n");
  1793. // Required item
  1794. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1795. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1796. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1797. if(isUnitA)
  1798. {
  1799. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1800. 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++)
  1801. {
  1802. 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"));
  1803. 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?
  1804. 3:
  1805. 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")));
  1806. 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")));
  1807. }
  1808. }
  1809. else
  1810. {
  1811. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1812. 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++)
  1813. {
  1814. 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"));
  1815. 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?
  1816. 3:
  1817. 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")));
  1818. 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));
  1819. }
  1820. }
  1821. // Optional item
  1822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1823. {
  1824. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1825. }
  1826. else
  1827. {
  1828. sprintf((char*)txProfile.ValidFrom, " ");
  1829. }
  1830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1831. {
  1832. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1833. }
  1834. else
  1835. {
  1836. sprintf((char*)txProfile.ValidTo, " ");
  1837. }
  1838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1839. {
  1840. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1841. }
  1842. else
  1843. {
  1844. sprintf((char*)txProfile.RecurrencyKind, " ");
  1845. }
  1846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1847. {
  1848. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1849. }
  1850. else
  1851. {
  1852. txProfile.TransactionId = -1;
  1853. }
  1854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1855. {
  1856. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1857. }
  1858. else
  1859. {
  1860. txProfile.ChargingSchedule.Duration = 86400;
  1861. }
  1862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1863. {
  1864. 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")));
  1865. }
  1866. else
  1867. {
  1868. 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));
  1869. }
  1870. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1871. {
  1872. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1873. }
  1874. else
  1875. {
  1876. txProfile.ChargingSchedule.MinChargingRate = -1;
  1877. }
  1878. }
  1879. }
  1880. }
  1881. else
  1882. {
  1883. if(txProfile.ChargingProfileId == -1)
  1884. DEBUG_INFO("TxProfile found.\n");
  1885. else
  1886. DEBUG_INFO("TxProfile updated.\n");
  1887. // Required item
  1888. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1889. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1890. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1891. if(isUnitA)
  1892. {
  1893. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1894. 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++)
  1895. {
  1896. 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"));
  1897. 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?
  1898. 3:
  1899. 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")));
  1900. 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")));
  1901. }
  1902. }
  1903. else
  1904. {
  1905. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1906. 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++)
  1907. {
  1908. 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"));
  1909. 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?
  1910. 3:
  1911. 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")));
  1912. 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));
  1913. }
  1914. }
  1915. // Optional item
  1916. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1917. {
  1918. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1919. }
  1920. else
  1921. {
  1922. sprintf((char*)txProfile.ValidFrom, " ");
  1923. }
  1924. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1925. {
  1926. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1927. }
  1928. else
  1929. {
  1930. sprintf((char*)txProfile.ValidTo, " ");
  1931. }
  1932. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1933. {
  1934. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1935. }
  1936. else
  1937. {
  1938. sprintf((char*)txProfile.RecurrencyKind, " ");
  1939. }
  1940. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1941. {
  1942. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1943. }
  1944. else
  1945. {
  1946. txProfile.TransactionId = -1;
  1947. }
  1948. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1949. {
  1950. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1951. }
  1952. else
  1953. {
  1954. txProfile.ChargingSchedule.Duration = 86400;
  1955. }
  1956. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1957. {
  1958. 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")));
  1959. }
  1960. else
  1961. {
  1962. 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));
  1963. }
  1964. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1965. {
  1966. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1967. }
  1968. else
  1969. {
  1970. txProfile.ChargingSchedule.MinChargingRate = -1;
  1971. }
  1972. }
  1973. }
  1974. }
  1975. json_object_put(obj);
  1976. }
  1977. fclose(fp);
  1978. /*
  1979. if(txProfile.ChargingProfileId != -1)
  1980. {
  1981. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1982. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1983. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1984. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1985. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1986. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1987. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1988. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1989. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1990. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1991. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1992. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1993. {
  1994. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1995. {
  1996. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1997. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1998. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1999. }
  2000. }
  2001. }
  2002. else
  2003. DEBUG_INFO("TxProfile not found.\n");*/
  2004. }
  2005. // Search default tx profile
  2006. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2007. if((access(profileFileName, F_OK))==-1)
  2008. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2009. if((access(profileFileName, F_OK))!=-1)
  2010. {
  2011. fp = fopen(profileFileName, "r");
  2012. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2013. {
  2014. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2015. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2016. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2017. }
  2018. defaultTxProfile.ChargingProfileId = -1;
  2019. defaultTxProfile.StackLevel = -1;
  2020. while(getline(&line, &len, fp) != -1)
  2021. {
  2022. json_object *obj = NULL;
  2023. obj = json_tokener_parse(line);
  2024. if(is_error(obj))
  2025. {
  2026. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2027. }
  2028. else
  2029. {
  2030. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2031. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2032. )
  2033. {
  2034. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2035. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2036. )
  2037. {
  2038. struct tm tmFrom, tmTo;
  2039. struct timeb tbFrom, tbTo;
  2040. 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) &&
  2041. (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))
  2042. {
  2043. tmFrom.tm_year -= 1900;
  2044. tmFrom.tm_mon -= 1;
  2045. tbFrom.time = mktime(&tmFrom);
  2046. tmTo.tm_year -= 1900;
  2047. tmTo.tm_mon -= 1;
  2048. tbTo.time = mktime(&tmTo);
  2049. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2050. {
  2051. if(defaultTxProfile.ChargingProfileId == -1)
  2052. DEBUG_INFO("TxDefaultProfile found.\n");
  2053. else
  2054. DEBUG_INFO("TxDefaultProfile updated.\n");
  2055. // Required item
  2056. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2057. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2058. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2059. if(isUnitA)
  2060. {
  2061. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2062. 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++)
  2063. {
  2064. 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"));
  2065. 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?
  2066. 3:
  2067. 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")));
  2068. 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")));
  2069. }
  2070. }
  2071. else
  2072. {
  2073. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2074. 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++)
  2075. {
  2076. 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"));
  2077. 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?
  2078. 3:
  2079. 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")));
  2080. 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));
  2081. }
  2082. }
  2083. // Optional item
  2084. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2085. {
  2086. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2087. }
  2088. else
  2089. {
  2090. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2091. }
  2092. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2093. {
  2094. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2095. }
  2096. else
  2097. {
  2098. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2099. }
  2100. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2101. {
  2102. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2103. }
  2104. else
  2105. {
  2106. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2107. }
  2108. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2109. {
  2110. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2111. }
  2112. else
  2113. {
  2114. defaultTxProfile.TransactionId = -1;
  2115. }
  2116. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2117. {
  2118. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2119. }
  2120. else
  2121. {
  2122. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2123. }
  2124. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2125. {
  2126. 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")));
  2127. }
  2128. else
  2129. {
  2130. 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));
  2131. }
  2132. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2133. {
  2134. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2135. }
  2136. else
  2137. {
  2138. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2139. }
  2140. }
  2141. }
  2142. }
  2143. else
  2144. {
  2145. if(defaultTxProfile.ChargingProfileId == -1)
  2146. DEBUG_INFO("TxDefaultProfile found.\n");
  2147. else
  2148. DEBUG_INFO("TxDefaultProfile updated.\n");
  2149. // Required item
  2150. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2151. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2152. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2153. if(isUnitA)
  2154. {
  2155. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2156. 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++)
  2157. {
  2158. 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"));
  2159. 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?
  2160. 3:
  2161. 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")));
  2162. 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")));
  2163. }
  2164. }
  2165. else
  2166. {
  2167. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2168. 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++)
  2169. {
  2170. 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"));
  2171. 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?
  2172. 3:
  2173. 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")));
  2174. 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));
  2175. }
  2176. }
  2177. // Optional item
  2178. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2179. {
  2180. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2181. }
  2182. else
  2183. {
  2184. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2185. }
  2186. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2187. {
  2188. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2189. }
  2190. else
  2191. {
  2192. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2193. }
  2194. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2195. {
  2196. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2197. }
  2198. else
  2199. {
  2200. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2201. }
  2202. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2203. {
  2204. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2205. }
  2206. else
  2207. {
  2208. defaultTxProfile.TransactionId = -1;
  2209. }
  2210. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2211. {
  2212. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2213. }
  2214. else
  2215. {
  2216. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2217. }
  2218. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2219. {
  2220. 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")));
  2221. }
  2222. else
  2223. {
  2224. 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));
  2225. }
  2226. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2227. {
  2228. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2229. }
  2230. else
  2231. {
  2232. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2233. }
  2234. }
  2235. }
  2236. }
  2237. json_object_put(obj);
  2238. }
  2239. fclose(fp);
  2240. /*
  2241. if(defaultTxProfile.ChargingProfileId != -1)
  2242. {
  2243. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2244. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2245. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2246. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2247. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2248. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2249. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2250. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2251. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2252. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2253. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2254. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2255. {
  2256. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2257. {
  2258. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2259. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2260. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2261. }
  2262. }
  2263. }
  2264. else
  2265. DEBUG_INFO("TxDefaultProfile not found.\n");
  2266. DEBUG_INFO("------------------------------------\n");*/
  2267. }
  2268. // Search max profile
  2269. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2270. if((access(profileFileName, F_OK))!=-1)
  2271. {
  2272. fp = fopen(profileFileName, "r");
  2273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2274. {
  2275. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2277. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2278. }
  2279. maxProfile.ChargingProfileId = -1;
  2280. maxProfile.StackLevel = -1;
  2281. while(getline(&line, &len, fp) != -1)
  2282. {
  2283. json_object *obj = NULL;
  2284. obj = json_tokener_parse(line);
  2285. if(is_error(obj))
  2286. {
  2287. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2288. }
  2289. else
  2290. {
  2291. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2292. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2293. )
  2294. {
  2295. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2296. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2297. )
  2298. {
  2299. struct tm tmFrom, tmTo;
  2300. struct timeb tbFrom, tbTo;
  2301. 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) &&
  2302. (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))
  2303. {
  2304. tmFrom.tm_year -= 1900;
  2305. tmFrom.tm_mon -= 1;
  2306. tbFrom.time = mktime(&tmFrom);
  2307. tmTo.tm_year -= 1900;
  2308. tmTo.tm_mon -= 1;
  2309. tbTo.time = mktime(&tmTo);
  2310. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2311. {
  2312. if(maxProfile.ChargingProfileId == -1)
  2313. DEBUG_INFO("MaxProfile found.\n");
  2314. else
  2315. DEBUG_INFO("MaxProfile updated.\n");
  2316. // Required item
  2317. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2318. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2319. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2320. if(isUnitA)
  2321. {
  2322. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2323. 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++)
  2324. {
  2325. 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"));
  2326. 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?
  2327. 3:
  2328. 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")));
  2329. 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")));
  2330. }
  2331. }
  2332. else
  2333. {
  2334. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2335. 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++)
  2336. {
  2337. 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"));
  2338. 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?
  2339. 3:
  2340. 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")));
  2341. 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));
  2342. }
  2343. }
  2344. // Optional item
  2345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2346. {
  2347. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2348. }
  2349. else
  2350. {
  2351. sprintf((char*)maxProfile.ValidFrom, " ");
  2352. }
  2353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2354. {
  2355. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)maxProfile.ValidTo, " ");
  2360. }
  2361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2362. {
  2363. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2364. }
  2365. else
  2366. {
  2367. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2368. }
  2369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2370. {
  2371. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2372. }
  2373. else
  2374. {
  2375. maxProfile.TransactionId = -1;
  2376. }
  2377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2378. {
  2379. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2380. }
  2381. else
  2382. {
  2383. maxProfile.ChargingSchedule.Duration = 86400;
  2384. }
  2385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2386. {
  2387. 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")));
  2388. }
  2389. else
  2390. {
  2391. 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));
  2392. }
  2393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2394. {
  2395. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2396. }
  2397. else
  2398. {
  2399. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2400. }
  2401. }
  2402. }
  2403. }
  2404. else
  2405. {
  2406. if(maxProfile.ChargingProfileId == -1)
  2407. DEBUG_INFO("MaxProfile found.\n");
  2408. else
  2409. DEBUG_INFO("MaxProfile updated.\n");
  2410. // Required item
  2411. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2412. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2413. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2414. if(isUnitA)
  2415. {
  2416. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2417. 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++)
  2418. {
  2419. 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"));
  2420. 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?
  2421. 3:
  2422. 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")));
  2423. 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")));
  2424. }
  2425. }
  2426. else
  2427. {
  2428. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2429. 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++)
  2430. {
  2431. 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"));
  2432. 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?
  2433. 3:
  2434. 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")));
  2435. 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));
  2436. }
  2437. }
  2438. // Optional item
  2439. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2440. {
  2441. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2442. }
  2443. else
  2444. {
  2445. sprintf((char*)maxProfile.ValidFrom, " ");
  2446. }
  2447. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2448. {
  2449. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2450. }
  2451. else
  2452. {
  2453. sprintf((char*)maxProfile.ValidTo, " ");
  2454. }
  2455. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2456. {
  2457. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2458. }
  2459. else
  2460. {
  2461. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2462. }
  2463. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2464. {
  2465. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2466. }
  2467. else
  2468. {
  2469. maxProfile.TransactionId = -1;
  2470. }
  2471. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2472. {
  2473. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2474. }
  2475. else
  2476. {
  2477. maxProfile.ChargingSchedule.Duration = 86400;
  2478. }
  2479. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2480. {
  2481. 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")));
  2482. }
  2483. else
  2484. {
  2485. 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));
  2486. }
  2487. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2488. {
  2489. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2490. }
  2491. else
  2492. {
  2493. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2494. }
  2495. }
  2496. }
  2497. }
  2498. json_object_put(obj);
  2499. }
  2500. fclose(fp);
  2501. /*
  2502. if(maxProfile.ChargingProfileId !=-1)
  2503. {
  2504. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2505. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2506. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2507. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2508. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2509. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2510. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2511. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2512. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2513. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2514. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2516. {
  2517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2518. {
  2519. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2520. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2521. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2522. }
  2523. }
  2524. }
  2525. else
  2526. DEBUG_INFO("MaxProfile not found.\n");
  2527. DEBUG_INFO("------------------------------------\n");*/
  2528. }
  2529. /*
  2530. * Align found profile start schedule & periods
  2531. */
  2532. //DEBUG_INFO("====================================\n");
  2533. /*
  2534. // For local test usage, force modify found profile start schedule info
  2535. 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);
  2536. 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);
  2537. 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);
  2538. */
  2539. if(txProfile.ChargingProfileId != -1)
  2540. {
  2541. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2542. {
  2543. if(txProfile.ChargingSchedule.Duration != -1)
  2544. {
  2545. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2546. 0:
  2547. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2548. }
  2549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2550. {
  2551. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2552. {
  2553. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2554. 0:
  2555. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2556. if(idxPeriod > 0)
  2557. {
  2558. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2559. {
  2560. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2561. }
  2562. }
  2563. }
  2564. }
  2565. }
  2566. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2567. {
  2568. if(txProfile.ChargingSchedule.Duration != -1)
  2569. {
  2570. 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?
  2571. 0:
  2572. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2573. }
  2574. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2575. {
  2576. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2577. {
  2578. 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?
  2579. 0:
  2580. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2581. if(idxPeriod > 0)
  2582. {
  2583. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2584. {
  2585. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2586. }
  2587. }
  2588. }
  2589. }
  2590. }
  2591. else
  2592. {
  2593. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2594. {
  2595. if(txProfile.ChargingSchedule.Duration != -1)
  2596. {
  2597. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2598. 0:
  2599. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2600. }
  2601. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2602. {
  2603. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2604. {
  2605. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2606. 0:
  2607. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2608. if(idxPeriod > 0)
  2609. {
  2610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2611. {
  2612. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. else
  2619. {
  2620. if(txProfile.ChargingSchedule.Duration != -1)
  2621. {
  2622. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2623. 0:
  2624. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2625. }
  2626. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2627. {
  2628. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2629. {
  2630. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2631. 0:
  2632. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2633. if(idxPeriod > 0)
  2634. {
  2635. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2636. {
  2637. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2638. }
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. /*
  2645. DEBUG_INFO("txProfile after align.\n");
  2646. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2647. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2648. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2649. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2650. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2651. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2652. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2653. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2654. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2655. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2656. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2657. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2658. {
  2659. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2660. {
  2661. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2662. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2663. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2664. }
  2665. }*/
  2666. }
  2667. if(defaultTxProfile.ChargingProfileId != -1)
  2668. {
  2669. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2670. {
  2671. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2672. {
  2673. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2674. 0:
  2675. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2676. }
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2680. {
  2681. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2682. 0:
  2683. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2684. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2685. {
  2686. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2687. }
  2688. if(idxPeriod > 0)
  2689. {
  2690. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2691. {
  2692. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2693. }
  2694. }
  2695. }
  2696. }
  2697. }
  2698. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2699. {
  2700. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2701. {
  2702. 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?
  2703. 0:
  2704. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2705. }
  2706. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2707. {
  2708. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2709. {
  2710. 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?
  2711. 0:
  2712. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2713. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2714. {
  2715. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2716. }
  2717. if(idxPeriod > 0)
  2718. {
  2719. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2720. {
  2721. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2722. }
  2723. }
  2724. }
  2725. }
  2726. }
  2727. else
  2728. {
  2729. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2730. {
  2731. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2732. {
  2733. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2734. 0:
  2735. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2736. }
  2737. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2738. {
  2739. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2740. {
  2741. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2742. 0:
  2743. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2744. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2745. {
  2746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2747. }
  2748. if(idxPeriod > 0)
  2749. {
  2750. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2751. {
  2752. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2753. }
  2754. }
  2755. }
  2756. }
  2757. }
  2758. else
  2759. {
  2760. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2761. {
  2762. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2763. 0:
  2764. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2765. }
  2766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2767. {
  2768. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2769. {
  2770. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2771. 0:
  2772. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2773. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2774. {
  2775. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2776. }
  2777. if(idxPeriod > 0)
  2778. {
  2779. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2780. {
  2781. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2782. }
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. /*
  2789. DEBUG_INFO("defaultTxProfile after align.\n");
  2790. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2791. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2792. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2793. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2794. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2795. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2796. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2797. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2798. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2799. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2800. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2801. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2802. {
  2803. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2804. {
  2805. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2806. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2807. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2808. }
  2809. }
  2810. DEBUG_INFO("------------------------------------\n");*/
  2811. }
  2812. if(maxProfile.ChargingProfileId != -1)
  2813. {
  2814. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2815. {
  2816. if(maxProfile.ChargingSchedule.Duration != -1)
  2817. {
  2818. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2819. 0:
  2820. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2821. }
  2822. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2823. {
  2824. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2825. {
  2826. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2827. 0:
  2828. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2829. if(idxPeriod > 0)
  2830. {
  2831. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2832. {
  2833. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2834. }
  2835. }
  2836. }
  2837. }
  2838. }
  2839. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2840. {
  2841. if(maxProfile.ChargingSchedule.Duration != -1)
  2842. {
  2843. 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?
  2844. 0:
  2845. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2846. }
  2847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2848. {
  2849. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2850. {
  2851. 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?
  2852. 0:
  2853. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2854. if(idxPeriod > 0)
  2855. {
  2856. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2857. {
  2858. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2859. }
  2860. }
  2861. }
  2862. }
  2863. }
  2864. else
  2865. {
  2866. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2867. {
  2868. if(maxProfile.ChargingSchedule.Duration != -1)
  2869. {
  2870. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2871. 0:
  2872. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2873. }
  2874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2875. {
  2876. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2877. {
  2878. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2879. 0:
  2880. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2881. if(idxPeriod > 0)
  2882. {
  2883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2884. {
  2885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2886. }
  2887. }
  2888. }
  2889. }
  2890. }
  2891. else
  2892. {
  2893. if(maxProfile.ChargingSchedule.Duration != -1)
  2894. {
  2895. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2896. 0:
  2897. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2898. }
  2899. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2900. {
  2901. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2902. {
  2903. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2904. 0:
  2905. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2906. if(idxPeriod > 0)
  2907. {
  2908. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2909. {
  2910. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. /*
  2918. DEBUG_INFO("MaxProfile after align.\n");
  2919. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2920. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2921. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2922. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2923. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2924. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2925. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2926. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2927. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2928. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2929. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2930. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2931. {
  2932. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2933. {
  2934. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2935. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2936. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2937. }
  2938. }
  2939. DEBUG_INFO("------------------------------------\n");*/
  2940. }
  2941. /*
  2942. * Merge to conposite schedule
  2943. */
  2944. //DEBUG_INFO("====================================\n");
  2945. // Find each profile period quantity
  2946. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2947. {
  2948. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2949. limitMax = idx+1;
  2950. }
  2951. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2952. {
  2953. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2954. limitDef = idx+1;
  2955. }
  2956. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2957. {
  2958. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2959. limitTx = idx+1;
  2960. }
  2961. // TxProfile found, composite schedule based on it
  2962. if(txProfile.ChargingProfileId != -1)
  2963. {
  2964. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2965. {
  2966. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2967. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2968. (txProfile.ChargingSchedule.Duration > 0))
  2969. {
  2970. if(maxProfile.ChargingProfileId != -1)
  2971. {
  2972. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2973. {
  2974. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2975. {
  2976. if((maxProfile.ChargingSchedule.Duration > 0))
  2977. {
  2978. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2979. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2980. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2981. }
  2982. else
  2983. {
  2984. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2985. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2986. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2987. }
  2988. }
  2989. if(idxMaxPeriod == (limitMax-1))
  2990. {
  2991. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2992. {
  2993. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2994. {
  2995. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2996. compositePeriodIdx++;
  2997. }
  2998. else
  2999. {
  3000. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3001. }
  3002. }
  3003. }
  3004. }
  3005. }
  3006. else
  3007. {
  3008. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3009. {
  3010. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3011. compositePeriodIdx++;
  3012. }
  3013. else
  3014. {
  3015. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3016. }
  3017. }
  3018. }
  3019. if(idxTxPeriod == (limitTx-1))
  3020. {
  3021. if(defaultTxProfile.ChargingProfileId != -1)
  3022. {
  3023. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3024. {
  3025. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3026. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3027. (defaultTxProfile.ChargingSchedule.Duration>0))
  3028. {
  3029. if(maxProfile.ChargingProfileId != -1)
  3030. {
  3031. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3032. {
  3033. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3034. {
  3035. if((maxProfile.ChargingSchedule.Duration > 0))
  3036. {
  3037. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3038. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3039. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3040. }
  3041. else
  3042. {
  3043. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3044. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3045. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3046. }
  3047. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3048. {
  3049. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3050. {
  3051. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3052. compositePeriodIdx++;
  3053. }
  3054. else
  3055. {
  3056. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3057. }
  3058. }
  3059. // Delete duplicate period
  3060. if(compositePeriodIdx > 1)
  3061. {
  3062. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3063. {
  3064. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3065. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3066. compositePeriodIdx -= 1;
  3067. }
  3068. }
  3069. }
  3070. else
  3071. break;
  3072. }
  3073. }
  3074. else
  3075. {
  3076. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3077. {
  3078. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3079. compositePeriodIdx++;
  3080. }
  3081. else
  3082. {
  3083. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3084. }
  3085. }
  3086. }
  3087. }
  3088. }
  3089. }
  3090. }
  3091. }
  3092. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3093. else if(defaultTxProfile.ChargingProfileId != -1)
  3094. {
  3095. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3096. {
  3097. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3098. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3099. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3100. {
  3101. if(maxProfile.ChargingProfileId != -1)
  3102. {
  3103. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3104. {
  3105. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3106. {
  3107. if((maxProfile.ChargingSchedule.Duration > 0))
  3108. {
  3109. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3110. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3111. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3112. }
  3113. else
  3114. {
  3115. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3116. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3117. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3118. }
  3119. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3120. {
  3121. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3122. {
  3123. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3124. compositePeriodIdx++;
  3125. }
  3126. else
  3127. {
  3128. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3129. }
  3130. }
  3131. // Delete duplicate period
  3132. if(compositePeriodIdx > 1)
  3133. {
  3134. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3135. {
  3136. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3137. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3138. compositePeriodIdx -= 1;
  3139. }
  3140. }
  3141. }
  3142. else
  3143. break;
  3144. }
  3145. }
  3146. else
  3147. {
  3148. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3149. {
  3150. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3151. compositePeriodIdx++;
  3152. }
  3153. else
  3154. {
  3155. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3156. }
  3157. }
  3158. }
  3159. }
  3160. }
  3161. // Fill other period by MaxProfile
  3162. if(maxProfile.ChargingProfileId != -1)
  3163. {
  3164. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3165. {
  3166. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3167. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3168. (maxProfile.ChargingSchedule.Duration > 0))
  3169. {
  3170. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3171. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3172. {
  3173. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3174. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3175. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3176. }
  3177. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3178. {
  3179. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3180. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3181. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3182. }
  3183. if(tmpPeriod.Limit != -1)
  3184. {
  3185. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3186. {
  3187. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3188. {
  3189. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3190. compositePeriodIdx++;
  3191. }
  3192. else
  3193. {
  3194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3195. }
  3196. }
  3197. // Delete duplicate period
  3198. if(compositePeriodIdx > 1)
  3199. {
  3200. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3201. {
  3202. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3203. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3204. compositePeriodIdx -= 1;
  3205. }
  3206. }
  3207. }
  3208. }
  3209. }
  3210. }
  3211. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3212. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3213. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3214. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3216. {
  3217. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3218. {
  3219. compositeProfile->ChargingProfileId = 1;
  3220. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3221. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3222. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3223. }
  3224. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3225. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3226. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3227. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3228. }
  3229. if(line)
  3230. free(line);
  3231. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3232. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3233. }
  3234. //==========================================
  3235. // Init all share memory
  3236. //==========================================
  3237. int InitShareMemory()
  3238. {
  3239. int result = PASS;
  3240. int MeterSMId;
  3241. //creat ShmSysConfigAndInfo
  3242. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3243. {
  3244. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3245. result = FAIL;
  3246. }
  3247. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3248. {
  3249. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3250. result = FAIL;
  3251. }
  3252. else
  3253. {}
  3254. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3255. {
  3256. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3257. result = FAIL;
  3258. }
  3259. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3260. {
  3261. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3262. result = FAIL;
  3263. }
  3264. else
  3265. {}
  3266. //creat ShmPsuData
  3267. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3268. {
  3269. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3270. result = FAIL;
  3271. }
  3272. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3273. {
  3274. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3275. result = FAIL;
  3276. }
  3277. else
  3278. {}
  3279. //creat ShmOCPP16Data
  3280. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3281. {
  3282. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3283. result = FAIL;
  3284. }
  3285. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3286. {
  3287. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3288. result = FAIL;
  3289. }
  3290. else
  3291. {}
  3292. /****************************** For Initial Settings************************************************/
  3293. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3294. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3295. // allocate Configuration memory address
  3296. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3297. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3298. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3299. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3300. //offline MeterValue Interval
  3301. TempMeterValueInterval = 0;
  3302. return result;
  3303. }
  3304. int ProcessShareMemory()
  3305. {
  3306. if(InitShareMemory() == FAIL)
  3307. {
  3308. DEBUG_ERROR("InitShareMemory NG\n");
  3309. if(ShmStatusCodeData!=NULL)
  3310. {
  3311. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3312. }
  3313. sleep(5);
  3314. return FAIL;
  3315. }
  3316. return PASS;
  3317. }
  3318. void CheckSystemValue(void)
  3319. {
  3320. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3321. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3322. char filenmae[100]={0};
  3323. char str[100]={0};
  3324. int tempIndex = 0;
  3325. //===============================
  3326. // send Heartbeat
  3327. //===============================
  3328. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3329. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3330. {
  3331. clientTime.Heartbeat=time((time_t*)NULL);
  3332. if(server_sign == TRUE)
  3333. {
  3334. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3335. }
  3336. else
  3337. {
  3338. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3339. }
  3340. }
  3341. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3342. {
  3343. //parameter for test
  3344. sendHeartbeatRequest(0);
  3345. //==============================================
  3346. // Reset Waiting Time
  3347. //==============================================
  3348. HeartBeatWithNOResponse += 1;
  3349. }
  3350. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3351. {
  3352. //==========================================
  3353. // csu trigger DataTransferReq
  3354. //==========================================
  3355. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3356. {
  3357. sendDataTransferRequest(gun_index);
  3358. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3359. }
  3360. //===============================
  3361. // CSU Trigger Authorize Request
  3362. //===============================
  3363. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3364. {
  3365. sendAuthorizeRequest(0);
  3366. authorizeRetryTimes = authorizeRetryTimes + 1;
  3367. if(authorizeRetryTimes < 3)
  3368. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3369. }
  3370. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3371. {
  3372. authorizeRetryTimes = 0;
  3373. SetOcppConnStatus(FALSE);
  3374. server_sign = FALSE;
  3375. }
  3376. 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))
  3377. {
  3378. sendAuthorizeRequest(0);
  3379. }
  3380. //==============================================
  3381. // Charger start transaction
  3382. //==============================================
  3383. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3384. {
  3385. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3386. sendStartTransactionRequest(gun_index);
  3387. clientTime.StartTransaction = time((time_t*)NULL);
  3388. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3389. storeTempStopTransaction(gun_index);
  3390. }
  3391. //==============================================
  3392. // Charger stop transaction
  3393. //==============================================
  3394. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3395. {
  3396. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3397. sendStopTransactionRequest(gun_index);
  3398. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3399. clientTime.StopTransaction = time((time_t*)NULL);
  3400. }
  3401. //==============================================
  3402. // Charger status report
  3403. //==============================================
  3404. //--- Check Mode Change ---//
  3405. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3406. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3407. {
  3408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3409. {
  3410. tempIndex = ((gun_index==2) ? 1: 0);
  3411. }
  3412. else
  3413. {
  3414. tempIndex = gun_index;
  3415. }
  3416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3417. {
  3418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3419. {
  3420. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3421. {
  3422. // Sent unplug message for California pricing logic
  3423. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3424. {
  3425. uint8_t ts[20];
  3426. getNowDatetime(ts);
  3427. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3428. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3429. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3430. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3431. }
  3432. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3433. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3434. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3435. }
  3436. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3437. {
  3438. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3439. if((access(filenmae,F_OK))!=-1)
  3440. {
  3441. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3442. sprintf(str,"rm -f %s",filenmae);
  3443. system(str);
  3444. }
  3445. }
  3446. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3447. #if 1 // for TempStopTransaction
  3448. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3449. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3450. {
  3451. checkTempStopTransaction(gun_index);
  3452. }
  3453. #endif
  3454. }
  3455. }
  3456. }
  3457. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3458. {
  3459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3460. {
  3461. tempIndex = ((gun_index==2) ? 1: 0);
  3462. }
  3463. else
  3464. {
  3465. tempIndex = gun_index;
  3466. }
  3467. for (int index = 0; index < CCS_QUANTITY; index++)
  3468. {
  3469. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3470. {
  3471. 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]*/ )
  3472. {
  3473. // Sent unplug message for California pricing logic
  3474. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3475. {
  3476. uint8_t ts[20];
  3477. getNowDatetime(ts);
  3478. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3479. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3480. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3481. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3482. }
  3483. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3484. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3485. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3486. }
  3487. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3488. {
  3489. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3490. if((access(filenmae,F_OK))!=-1)
  3491. {
  3492. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3493. sprintf(str,"rm -f %s",filenmae);
  3494. system(str);
  3495. }
  3496. }
  3497. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3498. #if 1 // for TempStopTransaction
  3499. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3500. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3501. {
  3502. checkTempStopTransaction(gun_index);
  3503. }
  3504. #endif
  3505. }
  3506. }
  3507. }
  3508. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3509. {
  3510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3511. {
  3512. tempIndex = ((gun_index==2) ? 1: 0);
  3513. }
  3514. else
  3515. {
  3516. tempIndex = gun_index;
  3517. }
  3518. for (int index = 0; index < GB_QUANTITY; index++)
  3519. {
  3520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3521. {
  3522. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3523. {
  3524. // Sent unplug message for California pricing logic
  3525. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3526. {
  3527. uint8_t ts[20];
  3528. getNowDatetime(ts);
  3529. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3530. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3531. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3532. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3533. }
  3534. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3535. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3536. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3537. }
  3538. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3539. {
  3540. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3541. if((access(filenmae,F_OK))!=-1)
  3542. {
  3543. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3544. sprintf(str,"rm -f %s",filenmae);
  3545. system(str);
  3546. }
  3547. }
  3548. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3549. #if 1 // for TempStopTransaction
  3550. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3551. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3552. {
  3553. checkTempStopTransaction(gun_index);
  3554. }
  3555. #endif
  3556. }
  3557. }
  3558. }
  3559. else if(gunType[gun_index] == GUN_TYPE_DO)
  3560. {
  3561. tempIndex = gun_index;
  3562. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3563. {
  3564. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3565. {
  3566. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3567. {
  3568. // Sent unplug message for California pricing logic
  3569. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3570. {
  3571. uint8_t ts[20];
  3572. getNowDatetime(ts);
  3573. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3574. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3575. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3576. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3577. }
  3578. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3579. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3580. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3581. }
  3582. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  3583. {
  3584. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3585. if((access(filenmae,F_OK))!=-1)
  3586. {
  3587. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3588. sprintf(str,"rm -f %s",filenmae);
  3589. system(str);
  3590. }
  3591. }
  3592. 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);
  3593. #if 1 // for TempStopTransaction
  3594. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3595. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3596. {
  3597. checkTempStopTransaction(gun_index);
  3598. }
  3599. #endif
  3600. }
  3601. }
  3602. }
  3603. else
  3604. {
  3605. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3606. {
  3607. tempIndex = 2;
  3608. }
  3609. else
  3610. {
  3611. tempIndex = gun_index;
  3612. }
  3613. for (int index = 0; index < AC_QUANTITY; index++)
  3614. {
  3615. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3616. {
  3617. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3618. {
  3619. // Sent unplug message for California pricing logic
  3620. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3621. {
  3622. uint8_t ts[20];
  3623. getNowDatetime(ts);
  3624. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3625. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3626. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3627. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3628. }
  3629. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3630. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3631. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3632. }
  3633. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3634. {
  3635. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3636. if((access(filenmae,F_OK))!=-1)
  3637. {
  3638. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3639. sprintf(str,"rm -f %s",filenmae);
  3640. system(str);
  3641. }
  3642. }
  3643. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3644. #if 1 // for TempStopTransaction
  3645. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3646. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3647. {
  3648. checkTempStopTransaction(gun_index);
  3649. }
  3650. #endif
  3651. }
  3652. }// END
  3653. }
  3654. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3655. (
  3656. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3657. )
  3658. )
  3659. {
  3660. if(SystemInitial > 0)
  3661. SystemInitial -= 1;
  3662. sendStatusNotificationRequest(gun_index);
  3663. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3664. }
  3665. //==============================================
  3666. // CSU Trigger Smart Charging Profilw
  3667. //==============================================
  3668. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3669. {
  3670. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3671. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3672. }
  3673. //==============================================
  3674. // Meter report
  3675. //==============================================
  3676. // Trigger MeterValue
  3677. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3678. {
  3679. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3680. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3681. }
  3682. // ClockAlign MeterValue
  3683. 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))
  3684. {
  3685. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3686. {
  3687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3688. {
  3689. tempIndex = ((gun_index==2) ? 1: 0);
  3690. }
  3691. else
  3692. {
  3693. tempIndex = gun_index;
  3694. }
  3695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3696. {
  3697. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3698. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3699. {
  3700. reqClockAlignMeter[gun_index] = 1;
  3701. }
  3702. }// End for CHAdeMO
  3703. }
  3704. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3705. {
  3706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3707. {
  3708. tempIndex = ((gun_index==2) ? 1: 0);
  3709. }
  3710. else
  3711. {
  3712. tempIndex = gun_index;
  3713. }
  3714. for (int index = 0; index < CCS_QUANTITY; index++)
  3715. {
  3716. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3717. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3718. {
  3719. reqClockAlignMeter[gun_index] = 1;
  3720. }
  3721. } // End for CCS
  3722. }
  3723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3724. {
  3725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3726. {
  3727. tempIndex = ((gun_index==2) ? 1: 0);
  3728. }
  3729. else
  3730. {
  3731. tempIndex = gun_index;
  3732. }
  3733. for (int index = 0; index < GB_QUANTITY; index++)
  3734. {
  3735. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3736. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3737. {
  3738. reqClockAlignMeter[gun_index] = 1;
  3739. }
  3740. }// End for GB
  3741. }
  3742. else if(gunType[gun_index] == GUN_TYPE_DO)
  3743. {
  3744. tempIndex = gun_index;
  3745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3746. {
  3747. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3748. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3749. {
  3750. reqClockAlignMeter[gun_index] = 1;
  3751. }
  3752. }
  3753. }
  3754. else
  3755. {
  3756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3757. {
  3758. tempIndex = 2;
  3759. }
  3760. else
  3761. {
  3762. tempIndex = gun_index;
  3763. }
  3764. for (int index = 0; index < AC_QUANTITY; index++)
  3765. {
  3766. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3767. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3768. {
  3769. reqClockAlignMeter[gun_index] = 1;
  3770. }
  3771. }//End for AC
  3772. }
  3773. if(reqClockAlignMeter[gun_index] == 1)
  3774. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3775. }
  3776. // Sample period MeterValue
  3777. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3778. {
  3779. //check Transaction active
  3780. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3781. {
  3782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3783. {
  3784. tempIndex = ((gun_index==2) ? 1: 0);
  3785. }
  3786. else
  3787. {
  3788. tempIndex = gun_index;
  3789. }
  3790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3791. {
  3792. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3793. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3794. {
  3795. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3796. {
  3797. reqSampleMeter[gun_index] = 1;
  3798. }
  3799. }
  3800. }// End for CHAdeMO
  3801. }
  3802. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3803. {
  3804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3805. {
  3806. tempIndex = ((gun_index==2) ? 1: 0);
  3807. }
  3808. else
  3809. {
  3810. tempIndex = gun_index;
  3811. }
  3812. for (int index = 0; index < CCS_QUANTITY; index++)
  3813. {
  3814. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3815. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3816. {
  3817. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3818. {
  3819. reqSampleMeter[gun_index] = 1;
  3820. }
  3821. }
  3822. } // End for CCS
  3823. }
  3824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3825. {
  3826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3827. {
  3828. tempIndex = ((gun_index==2) ? 1: 0);
  3829. }
  3830. else
  3831. {
  3832. tempIndex = gun_index;
  3833. }
  3834. for (int index = 0; index < GB_QUANTITY; index++)
  3835. {
  3836. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3837. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3838. {
  3839. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3840. {
  3841. reqSampleMeter[gun_index] = 1;
  3842. }
  3843. }
  3844. }// End for GB
  3845. }
  3846. else if(gunType[gun_index] == GUN_TYPE_DO)
  3847. {
  3848. tempIndex = gun_index;
  3849. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3850. {
  3851. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3852. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3853. {
  3854. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3855. {
  3856. reqSampleMeter[gun_index] = 1;
  3857. }
  3858. }
  3859. }
  3860. }
  3861. else
  3862. {
  3863. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3864. {
  3865. tempIndex = 2;
  3866. }
  3867. else
  3868. {
  3869. tempIndex = gun_index;
  3870. }
  3871. for (int index = 0; index < AC_QUANTITY; index++)
  3872. {
  3873. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3874. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3875. {
  3876. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3877. {
  3878. reqSampleMeter[gun_index] = 1;
  3879. }
  3880. }
  3881. }//End for AC
  3882. }
  3883. if(reqSampleMeter[gun_index] == 1)
  3884. {
  3885. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3886. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3887. storeTempStopTransaction(gun_index);
  3888. }
  3889. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3890. }
  3891. //==============================================
  3892. // Check Connector reserved
  3893. //==============================================
  3894. //===============================
  3895. // Check if Reserve is expired
  3896. //===============================
  3897. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3898. {
  3899. double diff_t;
  3900. struct tm tp;
  3901. // current time
  3902. time_t t = time(NULL);
  3903. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3904. tp.tm_isdst = -1;
  3905. time_t utc = mktime(&tp);
  3906. diff_t = difftime(utc, t);
  3907. if(diff_t <= 0)
  3908. {
  3909. DEBUG_INFO("reserve expired.\n");
  3910. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3911. }
  3912. }//END OF Check if Reserve is expired
  3913. //==========================================
  3914. // csu trigger FirmwareStatusNotificationReq
  3915. //==========================================
  3916. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3917. {
  3918. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3919. }
  3920. //==========================================
  3921. // csu trigger DiagnosticsStatusNotificationReq
  3922. //==========================================
  3923. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3924. {
  3925. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3926. }
  3927. //==========================================
  3928. // csu trigger CancelReservationConf
  3929. //==========================================
  3930. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3931. {
  3932. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3933. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3934. }
  3935. //==========================================
  3936. // csu trigger ChangeAvailabilityConf
  3937. //==========================================
  3938. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3939. {
  3940. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3941. }
  3942. //==========================================
  3943. // csu trigger UnlockConnectorConf
  3944. //==========================================
  3945. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3946. {
  3947. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3948. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3949. }
  3950. //==========================================
  3951. // csu trigger ReserveNowConf
  3952. //==========================================
  3953. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3954. {
  3955. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3956. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3957. }
  3958. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3959. {
  3960. sendSignCertificateRequest();
  3961. }
  3962. }
  3963. }
  3964. //==========================================
  3965. // send request routine
  3966. //==========================================
  3967. int sendAuthorizeRequest(int gun_index)
  3968. {
  3969. mtrace();
  3970. int result = FAIL;
  3971. char message[100]={0};
  3972. char guid[37];
  3973. char tempdata[65]={0};
  3974. DEBUG_INFO("sendAuthorizeRequest...\n");
  3975. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3976. //Local Authorize
  3977. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3978. {
  3979. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3980. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3981. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3982. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3983. result = PASS;
  3984. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3985. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3986. authorizeRetryTimes = 0;
  3987. return result;
  3988. }
  3989. 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))||
  3990. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3991. {
  3992. // Query from cache
  3993. DEBUG_INFO("Authorize from cache.\n");
  3994. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3995. // Query from list
  3996. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3997. {
  3998. DEBUG_INFO("Authorize from list.\n");
  3999. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4000. }
  4001. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4002. {
  4003. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4004. {
  4005. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4006. }
  4007. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4008. {
  4009. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4010. }
  4011. if(!GetOcppConnStatus())
  4012. {
  4013. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4014. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4015. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4016. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4017. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4018. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4019. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4020. authorizeRetryTimes = 0;
  4021. return result;
  4022. }
  4023. }
  4024. else
  4025. {
  4026. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4027. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4028. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4029. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4030. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4031. else
  4032. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4033. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4034. result = PASS;
  4035. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4036. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4037. authorizeRetryTimes = 0;
  4038. return result;
  4039. }
  4040. }
  4041. //initialize struct Authorize
  4042. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4043. //get data from shared memory
  4044. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4045. random_uuid(guid);
  4046. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4047. LWS_Send(message);
  4048. sprintf(tempdata, "Authorize,%d", gun_index);
  4049. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4050. {
  4051. result = PASS;
  4052. DEBUG_INFO("Authorize mapItem pass\n");
  4053. }
  4054. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4055. return result;
  4056. }
  4057. int sendBootNotificationRequest(void)
  4058. {
  4059. mtrace();
  4060. int result = FAIL;
  4061. char message[500]={0}, payload[700]={0};
  4062. char guid[37]={0};
  4063. char tempdata[65]={0};
  4064. // Fill BootNotification fields
  4065. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4066. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4067. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4068. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4069. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4070. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4071. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4072. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4073. ShmOCPP16Data->ChargeBoxId
  4074. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4075. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4076. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4077. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4078. ,ShmOCPP16Data->BootNotification.CpIccid
  4079. ,ShmOCPP16Data->BootNotification.CpImsi);
  4080. random_uuid(guid);
  4081. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4082. LWS_Send(message);
  4083. sprintf(tempdata, "BootNotification,0");
  4084. 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*/)
  4085. {
  4086. result = PASS;
  4087. }
  4088. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4089. strcpy(queuedata,message);
  4090. return result;
  4091. }
  4092. int sendDataTransferRequest(int gun_index)
  4093. {
  4094. mtrace();
  4095. char message[1000]={0};
  4096. char guid[37]={0};
  4097. char tempdata[65]={0};
  4098. int result = FAIL;
  4099. random_uuid(guid);
  4100. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4101. MESSAGE_TYPE_CALL,
  4102. guid,
  4103. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4104. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4105. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4106. LWS_Send(message);
  4107. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4108. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4109. {
  4110. result = PASS;
  4111. DEBUG_INFO("DataTransfer mapItem pass\n");
  4112. }
  4113. return result;
  4114. }
  4115. int sendDiagnosticsStatusNotificationRequest(char *status)
  4116. {
  4117. mtrace();
  4118. int result = FAIL;
  4119. char message[110]={0};
  4120. char guid[37]={0};
  4121. char tempdata[65]={0};
  4122. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4123. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4124. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4125. random_uuid(guid);
  4126. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4127. LWS_SendNow(message);
  4128. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4129. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4130. {
  4131. result = PASS;
  4132. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4133. }
  4134. //#ifdef SystemLogMessage
  4135. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4136. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4137. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4138. //#endif
  4139. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4140. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4141. //record status
  4142. if(strcmp(status,"Idle")==0)
  4143. {
  4144. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4145. }
  4146. else if(strcmp(status,"Uploaded")==0)
  4147. {
  4148. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4149. }
  4150. else if(strcmp(status,"UploadFailed")==0)
  4151. {
  4152. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4153. }
  4154. else if(strcmp(status,"Uploading")==0)
  4155. {
  4156. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4157. }
  4158. return result;
  4159. }
  4160. int sendFirmwareStatusNotificationRequest(char *status)
  4161. {
  4162. mtrace();
  4163. int result = FAIL;
  4164. char message[110]={0};
  4165. char guid[37]={0};
  4166. char tempdata[65]={0};
  4167. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4168. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4169. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4170. random_uuid(guid);
  4171. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4172. LWS_SendNow(message);
  4173. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4174. 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*/)
  4175. {
  4176. result = PASS;
  4177. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4178. }
  4179. //#ifdef SystemLogMessage
  4180. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4181. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4182. //#endif
  4183. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4184. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4185. //record status
  4186. if(strcmp(status,"Downloaded")==0)
  4187. {
  4188. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4189. }
  4190. else if(strcmp(status,"DownloadFailed")==0)
  4191. {
  4192. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4193. }
  4194. else if(strcmp(status,"Downloading")==0)
  4195. {
  4196. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4197. }
  4198. else if(strcmp(status,"Idle")==0)
  4199. {
  4200. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4201. }
  4202. else if(strcmp(status,"InstallationFailed")==0)
  4203. {
  4204. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4205. }
  4206. else if(strcmp(status,"Installing")==0)
  4207. {
  4208. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4209. }
  4210. else if(strcmp(status,"Installed")==0)
  4211. {
  4212. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4213. }
  4214. return result;
  4215. }
  4216. int sendHeartbeatRequest(int gun_index)
  4217. {
  4218. mtrace();
  4219. int result = FAIL;
  4220. char message[80]={0};
  4221. char guid[37]={0};
  4222. char tempdata[65]={0};
  4223. random_uuid(guid);
  4224. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4225. , MESSAGE_TYPE_CALL
  4226. , guid );
  4227. LWS_Send(message);
  4228. sprintf(tempdata, "Heartbeat,%d", 0);
  4229. 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*/)
  4230. {
  4231. result = PASS;
  4232. }
  4233. return result;
  4234. }
  4235. int sendStartTransactionRequest(int gun_index)
  4236. {
  4237. mtrace();
  4238. int result = FAIL;
  4239. char message[250]={0};
  4240. char guid[37]={0};
  4241. struct timeval tmnow;
  4242. struct tm *tm;
  4243. char buf[28];//, usec_buf[6];
  4244. char tempdata[65]={0};
  4245. int tempIndex = 0;
  4246. DEBUG_INFO("sendStartTransactionRequest...\n");
  4247. gettimeofday(&tmnow, NULL);
  4248. time_t t;
  4249. t = time(NULL);
  4250. /*UTC time and date*/
  4251. tm = gmtime(&t);
  4252. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4253. #if 0 // remove temporally
  4254. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4255. strcat(buf,".");
  4256. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4257. strcat(buf,usec_buf);
  4258. #endif
  4259. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4260. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4261. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4262. // clear StartTransaction Response
  4263. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4264. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4265. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4266. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4267. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4268. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4269. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4270. {
  4271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4272. {
  4273. tempIndex = ((gun_index==2) ? 1: 0);
  4274. }
  4275. else
  4276. {
  4277. tempIndex = gun_index;
  4278. }
  4279. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4280. {
  4281. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4282. {
  4283. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4284. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4285. }
  4286. }
  4287. }
  4288. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4289. {
  4290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4291. {
  4292. tempIndex = ((gun_index==2) ? 1: 0);
  4293. }
  4294. else
  4295. {
  4296. tempIndex = gun_index;
  4297. }
  4298. for (int index = 0; index < CCS_QUANTITY; index++)
  4299. {
  4300. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4301. {
  4302. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4303. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4304. }
  4305. }
  4306. }
  4307. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4308. {
  4309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4310. {
  4311. tempIndex = ((gun_index==2) ? 1: 0);
  4312. }
  4313. else
  4314. {
  4315. tempIndex = gun_index;
  4316. }
  4317. for (int index = 0; index < GB_QUANTITY; index++)
  4318. {
  4319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4320. {
  4321. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4322. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4323. }
  4324. }
  4325. }
  4326. else if(gunType[gun_index] == GUN_TYPE_DO)
  4327. {
  4328. tempIndex = gun_index;
  4329. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4330. {
  4331. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4332. {
  4333. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4334. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4335. }
  4336. }
  4337. }
  4338. else
  4339. {
  4340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4341. {
  4342. tempIndex = 2;
  4343. }
  4344. else
  4345. {
  4346. tempIndex = gun_index;
  4347. }
  4348. for (int index = 0; index < AC_QUANTITY; index++)
  4349. {
  4350. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4351. {
  4352. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4353. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4354. }
  4355. }
  4356. }
  4357. random_uuid(guid);
  4358. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4359. {
  4360. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4361. , gun_index +1
  4362. , MESSAGE_TYPE_CALL
  4363. , guid
  4364. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4365. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4366. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4367. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4368. }
  4369. else
  4370. {
  4371. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4372. , gun_index +1
  4373. , MESSAGE_TYPE_CALL
  4374. , guid
  4375. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4376. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4377. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4378. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4379. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4380. }
  4381. #if 1
  4382. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4383. 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*/)
  4384. {
  4385. result = PASS;
  4386. }
  4387. #endif
  4388. strcpy(queuedata, message);
  4389. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4390. OCPP_insert_transaction_msg(YES, queuedata);
  4391. return result;
  4392. }
  4393. int sendStatusNotificationRequest(int gun_index)
  4394. {
  4395. mtrace();
  4396. int result = FAIL;
  4397. char message[600]={0};
  4398. char guid[37];
  4399. int currentStatus = 0;
  4400. struct timeval tmnow;
  4401. struct tm *tm;
  4402. char buf[28];//, usec_buf[6];
  4403. char tempdata[65]={0};
  4404. int tempIndex = 0;
  4405. uint8_t isStateChanged = TRUE;
  4406. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4407. gettimeofday(&tmnow, NULL);
  4408. time_t t;
  4409. t = time(NULL);
  4410. /*UTC time and date*/
  4411. tm = gmtime(&t);
  4412. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4413. #if 0 // remove temporally
  4414. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4415. strcat(buf,".");
  4416. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4417. strcat(buf,usec_buf);
  4418. #endif
  4419. //printf("%s",buf);
  4420. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4421. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4422. // it's option
  4423. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4424. /*
  4425. enum _SYSTEM_STATUS
  4426. {
  4427. S_BOOTING = 0,
  4428. S_IDLE, = 1
  4429. S_AUTHORIZING, =2
  4430. S_REASSIGN_CHECK, =3
  4431. S_REASSIGN, =4
  4432. S_PRECHARGE, =5
  4433. S_PREPARING_FOR_EV, =6
  4434. S_PREPARING_FOR_EVSE, =7
  4435. S_CHARGING, =8
  4436. S_TERMINATING, =9
  4437. S_COMPLETE, =10
  4438. S_ALARM, =11
  4439. S_FAULT =12
  4440. }
  4441. */
  4442. //check Transaction active
  4443. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4444. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4445. {
  4446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4447. {
  4448. tempIndex = ((gun_index==2) ? 1: 0);
  4449. }
  4450. else
  4451. {
  4452. tempIndex = gun_index;
  4453. }
  4454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4455. {
  4456. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4457. {
  4458. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4459. {
  4460. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4461. {
  4462. currentStatus = Preparing; //OCPP Status: Preparing
  4463. }
  4464. else
  4465. {
  4466. currentStatus = Available; //OCPP Status: Available
  4467. }
  4468. }
  4469. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4470. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4471. ) //S_PRECHARGE
  4472. {
  4473. currentStatus = Preparing; //OCPP Status: Preparing
  4474. }
  4475. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4476. {
  4477. currentStatus = Charging; //OCPP Status: Charging
  4478. }
  4479. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4480. {
  4481. currentStatus = Finishing; //OCPP Status: Finishing
  4482. }
  4483. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4484. {
  4485. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4486. }
  4487. 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
  4488. {
  4489. currentStatus = Unavailable; //OCPP Status: Unavailable
  4490. }
  4491. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4492. {
  4493. currentStatus = Faulted; //OCPP Status: Faulted
  4494. }
  4495. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4496. {
  4497. currentStatus = Reserved; //OCPP Status: Reserved
  4498. }
  4499. } //end of the same index
  4500. }//end of for CHAdeMO_QUANTITY
  4501. }
  4502. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4503. {
  4504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4505. {
  4506. tempIndex = ((gun_index==2) ? 1: 0);
  4507. }
  4508. else
  4509. {
  4510. tempIndex = gun_index;
  4511. }
  4512. for (int index = 0; index < CCS_QUANTITY; index++)
  4513. {
  4514. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4515. {
  4516. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4517. {
  4518. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4519. {
  4520. currentStatus = Preparing; //OCPP Status: Preparing
  4521. }
  4522. else
  4523. {
  4524. currentStatus = Available; //OCPP Status: Available
  4525. }
  4526. }
  4527. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4528. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4529. ) //S_PRECHARGE
  4530. {
  4531. currentStatus = Preparing; //OCPP Status: Preparing
  4532. }
  4533. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4534. {
  4535. currentStatus = Charging; //OCPP Status: Charging
  4536. }
  4537. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4538. {
  4539. currentStatus = Finishing; //OCPP Status: Finishing
  4540. }
  4541. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4542. {
  4543. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4544. }
  4545. 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
  4546. {
  4547. currentStatus = Unavailable; //OCPP Status : Unavailable
  4548. }
  4549. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4550. {
  4551. currentStatus = Faulted; //OCPP Status: Faulted
  4552. }
  4553. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4554. {
  4555. currentStatus = Reserved; //OCPP Status: Reserved
  4556. }
  4557. } //end of the same index
  4558. } // end of for CCS_QUANTITY
  4559. }
  4560. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4561. {
  4562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4563. {
  4564. tempIndex = ((gun_index==2) ? 1: 0);
  4565. }
  4566. else
  4567. {
  4568. tempIndex = gun_index;
  4569. }
  4570. for (int index = 0; index < GB_QUANTITY; index++)
  4571. {
  4572. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4573. {
  4574. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4575. {
  4576. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4577. {
  4578. currentStatus = Preparing; //OCPP Status: Preparing
  4579. }
  4580. else
  4581. {
  4582. currentStatus = Available; //OCPP Status: Available
  4583. }
  4584. }
  4585. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4586. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4587. ) //S_PRECHARGE
  4588. {
  4589. currentStatus = Preparing; //OCPP Status: Preparing
  4590. }
  4591. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4592. {
  4593. currentStatus = Charging; //OCPP Status: Charging
  4594. }
  4595. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4596. {
  4597. currentStatus = Finishing; //OCPP Status: Finishing
  4598. }
  4599. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4600. {
  4601. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4602. }
  4603. 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
  4604. {
  4605. currentStatus = Unavailable; //OCPP Status: Unavailable
  4606. }
  4607. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4608. {
  4609. currentStatus = Faulted; //OCPP Status: Faulted
  4610. }
  4611. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4612. {
  4613. currentStatus = Reserved; //OCPP Status: Reserved
  4614. }
  4615. } //end of the same index
  4616. } // end of for GB_QUANTITY
  4617. }
  4618. else if(gunType[gun_index] == GUN_TYPE_DO)
  4619. {
  4620. tempIndex = gun_index;
  4621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4622. {
  4623. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4624. {
  4625. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4626. {
  4627. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4628. {
  4629. currentStatus = Preparing; //OCPP Status: Preparing
  4630. }
  4631. else
  4632. {
  4633. currentStatus = Available; //OCPP Status: Available
  4634. }
  4635. }
  4636. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4637. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4638. ) //S_PRECHARGE
  4639. {
  4640. currentStatus = Preparing; //OCPP Status: Preparing
  4641. }
  4642. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4643. {
  4644. currentStatus = Charging; //OCPP Status: Charging
  4645. }
  4646. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4647. {
  4648. currentStatus = Finishing; //OCPP Status: Finishing
  4649. }
  4650. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4651. {
  4652. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4653. }
  4654. 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
  4655. {
  4656. currentStatus = Unavailable; //OCPP Status: Unavailable
  4657. }
  4658. 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
  4659. {
  4660. currentStatus = Faulted; //OCPP Status: Faulted
  4661. }
  4662. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4663. {
  4664. currentStatus = Reserved; //OCPP Status: Reserved
  4665. }
  4666. } //end of the same index
  4667. }
  4668. }
  4669. else
  4670. {
  4671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4672. {
  4673. tempIndex = 2;
  4674. }
  4675. else
  4676. {
  4677. tempIndex = gun_index;
  4678. }
  4679. for (int index = 0; index < AC_QUANTITY; index++)
  4680. {
  4681. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4682. {
  4683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4684. {
  4685. 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))
  4686. {
  4687. currentStatus = Preparing; //OCPP Status: Preparing
  4688. }
  4689. else
  4690. {
  4691. currentStatus = Available; //OCPP Status: Available
  4692. }
  4693. }
  4694. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4695. {
  4696. currentStatus = Preparing; //OCPP Status: Preparing
  4697. }
  4698. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4699. {
  4700. currentStatus = Charging; //OCPP Status: Charging
  4701. }
  4702. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4703. {
  4704. currentStatus = Finishing; //OCPP Status: Finishing
  4705. }
  4706. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4707. {
  4708. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4709. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4710. else
  4711. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4712. }
  4713. 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
  4714. {
  4715. currentStatus = Unavailable; //OCPP Status: Unavailable
  4716. }
  4717. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4718. {
  4719. currentStatus = Faulted; //OCPP Status: Faulted
  4720. }
  4721. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4722. {
  4723. currentStatus = Reserved; //OCPP Status: Reserved
  4724. }
  4725. }//end of the same index
  4726. }//end of for AC_QUANTITY
  4727. }
  4728. //it's option
  4729. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4730. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4731. {
  4732. isStateChanged = FALSE;
  4733. }
  4734. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4735. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4736. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4737. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4738. random_uuid(guid);
  4739. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4740. , MESSAGE_TYPE_CALL
  4741. , guid
  4742. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4743. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4744. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4745. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4746. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4747. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4748. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4749. if((server_sign == TRUE) && isStateChanged)
  4750. {
  4751. LWS_Send(message);
  4752. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4753. 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*/)
  4754. {
  4755. //DEBUG_ERROR("statusNotification mapitem pass");
  4756. result = PASS;
  4757. }
  4758. }
  4759. else
  4760. {
  4761. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4762. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4763. result = PASS;
  4764. }
  4765. return result;
  4766. }
  4767. int sendStopTransactionRequest(int gun_index)
  4768. {
  4769. mtrace();
  4770. int result = FAIL;
  4771. //char message[1500]={0};
  4772. char guid[37]={0};
  4773. char tempdata[65]={0};
  4774. int tempIndex = 0;
  4775. char TempStopTransaction[256];
  4776. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4777. //int idx_sample=0;
  4778. DEBUG_INFO("sendStopTransactionRequest \n");
  4779. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4780. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4781. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4782. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4784. {
  4785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4786. {
  4787. tempIndex = ((gun_index==2) ? 1: 0);
  4788. }
  4789. else
  4790. {
  4791. tempIndex = gun_index;
  4792. }
  4793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4794. {
  4795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4796. {
  4797. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4798. }
  4799. }// END OF CHAdeMO_QUANTITY
  4800. }
  4801. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4802. {
  4803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4804. {
  4805. tempIndex = ((gun_index==2) ? 1: 0);
  4806. }
  4807. else
  4808. {
  4809. tempIndex = gun_index;
  4810. }
  4811. for (int index = 0; index < CCS_QUANTITY; index++)
  4812. {
  4813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4814. {
  4815. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4816. }
  4817. }// END OF CCS_QUANTITY
  4818. }
  4819. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4820. {
  4821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4822. {
  4823. tempIndex = ((gun_index==2) ? 1: 0);
  4824. }
  4825. else
  4826. {
  4827. tempIndex = gun_index;
  4828. }
  4829. for (int index = 0; index < GB_QUANTITY; index++)
  4830. {
  4831. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4832. {
  4833. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4834. }
  4835. }// END OF GB_QUANTITY
  4836. }
  4837. else if(gunType[gun_index] == GUN_TYPE_DO)
  4838. {
  4839. tempIndex = gun_index;
  4840. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4841. {
  4842. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4843. {
  4844. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4845. }
  4846. }// END OF GB_QUANTITY
  4847. }
  4848. else
  4849. {
  4850. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4851. {
  4852. tempIndex = 2;
  4853. }
  4854. else
  4855. {
  4856. tempIndex = gun_index;
  4857. }
  4858. for (int index = 0; index < AC_QUANTITY; index++)
  4859. {
  4860. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4861. {
  4862. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4863. }
  4864. }// END OF AC_QUANTITY
  4865. }
  4866. //====================================== Stop Transaction Time =====================================================
  4867. struct timeval tmnow;
  4868. struct tm *tm;
  4869. char buf[28];//, usec_buf[6];
  4870. gettimeofday(&tmnow, NULL);
  4871. time_t t;
  4872. t = time(NULL);
  4873. /*UTC time and date*/
  4874. tm = gmtime(&t);
  4875. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4877. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4878. random_uuid(guid);
  4879. /***********************************transactionData******************************************************/
  4880. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4882. //=================================
  4883. // Transaction_Begin
  4884. //=================================
  4885. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4886. {
  4887. //============================================ Energy.Active.Import.Interval ================================
  4888. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4891. 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*/]);
  4892. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4893. 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))
  4894. {
  4895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4896. }
  4897. else
  4898. {
  4899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4900. }
  4901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4903. }
  4904. //=================================
  4905. // Transaction_End
  4906. //=================================
  4907. // ================================= Current.Import L1 ===============================================
  4908. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4909. {
  4910. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4911. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4912. {
  4913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4914. {
  4915. tempIndex = ((gun_index==2) ? 1: 0);
  4916. }
  4917. else
  4918. {
  4919. tempIndex = gun_index;
  4920. }
  4921. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4922. {
  4923. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4924. {
  4925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4926. }
  4927. }// End of for CHAdeMO_QUANTITY
  4928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4929. }
  4930. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4931. {
  4932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4933. {
  4934. tempIndex = ((gun_index==2) ? 1: 0);
  4935. }
  4936. else
  4937. {
  4938. tempIndex = gun_index;
  4939. }
  4940. for (int index = 0; index < CCS_QUANTITY; index++)
  4941. {
  4942. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4943. {
  4944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4945. }
  4946. }// End of for CCS_QUANTITY
  4947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4948. }
  4949. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4950. {
  4951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4952. {
  4953. tempIndex = ((gun_index==2) ? 1: 0);
  4954. }
  4955. else
  4956. {
  4957. tempIndex = gun_index;
  4958. }
  4959. for (int index = 0; index < GB_QUANTITY; index++)
  4960. {
  4961. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4962. {
  4963. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4964. }
  4965. }// End of for GB_QUANTITY
  4966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4967. }
  4968. else if(gunType[gun_index] == GUN_TYPE_DO)
  4969. {
  4970. tempIndex = gun_index;
  4971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4972. {
  4973. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4974. {
  4975. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4976. }
  4977. }
  4978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4979. }
  4980. else
  4981. {
  4982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4983. {
  4984. tempIndex = 2;
  4985. }
  4986. else
  4987. {
  4988. tempIndex = gun_index;
  4989. }
  4990. for (int index = 0; index < AC_QUANTITY; index++)
  4991. {
  4992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4993. {
  4994. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4995. }
  4996. }// End of for AC_QUANTITY
  4997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4998. }
  4999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5004. }
  5005. // ================================= Energy.Active.Import.Interval ==============================================
  5006. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5007. {
  5008. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5009. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5010. {
  5011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5012. {
  5013. tempIndex = ((gun_index==2) ? 1: 0);
  5014. }
  5015. else
  5016. {
  5017. tempIndex = gun_index;
  5018. }
  5019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5020. {
  5021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5022. {
  5023. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5024. }
  5025. }// END OF CHAdeMO_QUANTITY
  5026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5027. }
  5028. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5029. {
  5030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5031. {
  5032. tempIndex = ((gun_index==2) ? 1: 0);
  5033. }
  5034. else
  5035. {
  5036. tempIndex = gun_index;
  5037. }
  5038. for (int index = 0; index < CCS_QUANTITY; index++)
  5039. {
  5040. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5041. {
  5042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5043. }
  5044. }// END OF CCS_QUANTITY
  5045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5046. }
  5047. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5048. {
  5049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5050. {
  5051. tempIndex = ((gun_index==2) ? 1: 0);
  5052. }
  5053. else
  5054. {
  5055. tempIndex = gun_index;
  5056. }
  5057. for (int index = 0; index < GB_QUANTITY; index++)
  5058. {
  5059. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5060. {
  5061. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5062. }
  5063. }// END OF GB_QUANTITY
  5064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5065. }
  5066. else if(gunType[gun_index] == GUN_TYPE_DO)
  5067. {
  5068. tempIndex = gun_index;
  5069. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5070. {
  5071. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5072. {
  5073. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5074. }
  5075. }
  5076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5077. }
  5078. else
  5079. {
  5080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5081. {
  5082. tempIndex = 2;
  5083. }
  5084. else
  5085. {
  5086. tempIndex = gun_index;
  5087. }
  5088. for (int index = 0; index < AC_QUANTITY; index++)
  5089. {
  5090. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5091. {
  5092. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5093. }
  5094. }// END OF AC_QUANTITY
  5095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5096. }
  5097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5102. }
  5103. //=================================== Power.Active.Import ==================================================
  5104. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5105. {
  5106. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5107. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5108. {
  5109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5110. {
  5111. tempIndex = ((gun_index==2) ? 1: 0);
  5112. }
  5113. else
  5114. {
  5115. tempIndex = gun_index;
  5116. }
  5117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5118. {
  5119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5120. {
  5121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5122. }
  5123. } // End for CHAdeMO_QUANTITY
  5124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5125. }
  5126. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5127. {
  5128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5129. {
  5130. tempIndex = ((gun_index==2) ? 1: 0);
  5131. }
  5132. else
  5133. {
  5134. tempIndex = gun_index;
  5135. }
  5136. for (int index = 0; index < CCS_QUANTITY; index++)
  5137. {
  5138. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5139. {
  5140. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5141. }
  5142. } // END for CCS_QUANTITY
  5143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5144. }
  5145. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5146. {
  5147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5148. {
  5149. tempIndex = ((gun_index==2) ? 1: 0);
  5150. }
  5151. else
  5152. {
  5153. tempIndex = gun_index;
  5154. }
  5155. for (int index = 0; index < GB_QUANTITY; index++)
  5156. {
  5157. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5158. {
  5159. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5160. }
  5161. }// END for GB_QUANTITY
  5162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5163. }
  5164. else if(gunType[gun_index] == GUN_TYPE_DO)
  5165. {
  5166. tempIndex = gun_index;
  5167. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5168. {
  5169. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5170. {
  5171. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5172. }
  5173. }
  5174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5175. }
  5176. else
  5177. {
  5178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5179. {
  5180. tempIndex = 2;
  5181. }
  5182. else
  5183. {
  5184. tempIndex = gun_index;
  5185. }
  5186. for (int index = 0; index < AC_QUANTITY; index++)
  5187. {
  5188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5189. {
  5190. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5191. }
  5192. } // END for AC_QUANTITY
  5193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5194. }
  5195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5200. }
  5201. //============================ Voltage L1 ====================================
  5202. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5203. {
  5204. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5205. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5206. {
  5207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5208. {
  5209. tempIndex = ((gun_index==2) ? 1: 0);
  5210. }
  5211. else
  5212. {
  5213. tempIndex = gun_index;
  5214. }
  5215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5216. {
  5217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5218. {
  5219. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5220. }
  5221. } // END OF FOR CHAdeMO_QUANTITY
  5222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5223. }
  5224. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5225. {
  5226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5227. {
  5228. tempIndex = ((gun_index==2) ? 1: 0);
  5229. }
  5230. else
  5231. {
  5232. tempIndex = gun_index;
  5233. }
  5234. for (int index = 0; index < CCS_QUANTITY; index++)
  5235. {
  5236. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5237. {
  5238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5239. }
  5240. } // END OF FOR CCS_QUANTITY
  5241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5242. }
  5243. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5244. {
  5245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5246. {
  5247. tempIndex = ((gun_index==2) ? 1: 0);
  5248. }
  5249. else
  5250. {
  5251. tempIndex = gun_index;
  5252. }
  5253. for (int index = 0; index < GB_QUANTITY; index++)
  5254. {
  5255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5256. {
  5257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5258. }
  5259. } // END OF FOR GB_QUANTITY
  5260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5261. }
  5262. else if(gunType[gun_index] == GUN_TYPE_DO)
  5263. {
  5264. tempIndex = gun_index;
  5265. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5266. {
  5267. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5268. {
  5269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5270. }
  5271. }
  5272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5273. }
  5274. else
  5275. {
  5276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5277. {
  5278. tempIndex = 2;
  5279. }
  5280. else
  5281. {
  5282. tempIndex = gun_index;
  5283. }
  5284. for (int index = 0; index < AC_QUANTITY; index++)
  5285. {
  5286. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5287. {
  5288. 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
  5289. }
  5290. } // END OF FOR AC_QUANTITY
  5291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5292. }
  5293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5298. }
  5299. //====================== End SoC ================================
  5300. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5301. {
  5302. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5303. 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))
  5304. {
  5305. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5306. {
  5307. tempIndex = ((gun_index==2) ? 1: 0);
  5308. }
  5309. else
  5310. {
  5311. tempIndex = gun_index;
  5312. }
  5313. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5314. {
  5315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5316. {
  5317. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5318. {
  5319. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5320. }
  5321. }
  5322. }
  5323. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5324. {
  5325. for (int index = 0; index < CCS_QUANTITY; index++)
  5326. {
  5327. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5328. {
  5329. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5330. }
  5331. }
  5332. }
  5333. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5334. {
  5335. for (int index = 0; index < GB_QUANTITY; index++)
  5336. {
  5337. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5338. {
  5339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5340. }
  5341. }
  5342. }
  5343. else if(gunType[gun_index] == GUN_TYPE_DO)
  5344. {
  5345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5346. {
  5347. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5348. {
  5349. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5350. }
  5351. }
  5352. }
  5353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5359. } // END FOR DC CASE
  5360. }
  5361. // ================================= Current.Import L2 ===============================================
  5362. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5363. {
  5364. // AC 3 phse L2 current
  5365. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5366. {
  5367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5368. {
  5369. tempIndex = 2;
  5370. }
  5371. else
  5372. {
  5373. tempIndex = gun_index;
  5374. }
  5375. for (int index = 0; index < AC_QUANTITY; index++)
  5376. {
  5377. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5378. {
  5379. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5380. }
  5381. }// End of for AC_QUANTITY
  5382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5383. }
  5384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5389. }
  5390. // ================================= Current.Import L3 ===============================================
  5391. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5392. {
  5393. // AC 3 phse L3 current
  5394. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5395. {
  5396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5397. {
  5398. tempIndex = 2;
  5399. }
  5400. else
  5401. {
  5402. tempIndex = gun_index;
  5403. }
  5404. for (int index = 0; index < AC_QUANTITY; index++)
  5405. {
  5406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5407. {
  5408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5409. }
  5410. }// End of for AC_QUANTITY
  5411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5412. }
  5413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5418. }
  5419. //============================ Voltage L2 ====================================
  5420. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5421. {
  5422. // AC 3 phse L2 voltage
  5423. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5424. {
  5425. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5426. {
  5427. tempIndex = 2;
  5428. }
  5429. else
  5430. {
  5431. tempIndex = gun_index;
  5432. }
  5433. for (int index = 0; index < AC_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5436. {
  5437. 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
  5438. }
  5439. } // END OF FOR AC_QUANTITY
  5440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5441. }
  5442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5447. }
  5448. //============================ Voltage L3 ====================================
  5449. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5450. {
  5451. // AC 3 phse L3 voltage
  5452. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5453. {
  5454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5455. {
  5456. tempIndex = 2;
  5457. }
  5458. else
  5459. {
  5460. tempIndex = gun_index;
  5461. }
  5462. for (int index = 0; index < AC_QUANTITY; index++)
  5463. {
  5464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5465. {
  5466. 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
  5467. }
  5468. } // END OF FOR AC_QUANTITY
  5469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5470. }
  5471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5476. }
  5477. //====================== Start SoC ================================
  5478. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5479. {
  5480. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5481. 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))
  5482. {
  5483. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5484. {
  5485. tempIndex = ((gun_index==2) ? 1: 0);
  5486. }
  5487. else
  5488. {
  5489. tempIndex = gun_index;
  5490. }
  5491. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5492. {
  5493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5494. {
  5495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5496. {
  5497. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5498. }
  5499. }
  5500. }
  5501. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5502. {
  5503. for (int index = 0; index < CCS_QUANTITY; index++)
  5504. {
  5505. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5506. {
  5507. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5508. }
  5509. }
  5510. }
  5511. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5512. {
  5513. for (int index = 0; index < GB_QUANTITY; index++)
  5514. {
  5515. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5516. {
  5517. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5518. }
  5519. }
  5520. }
  5521. else if(gunType[gun_index] == GUN_TYPE_DO)
  5522. {
  5523. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5524. {
  5525. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5526. {
  5527. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5528. }
  5529. }
  5530. }
  5531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5537. } // END FOR DC CASE
  5538. }
  5539. //================================================ Message create ====================================================
  5540. json_object *StopTransaction = json_object_new_object();
  5541. json_object *transactionDatas = json_object_new_array();
  5542. json_object *sampledValues = json_object_new_array();
  5543. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5544. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5545. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5546. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5547. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5548. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5549. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5550. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5551. {
  5552. json_object *transactionData = json_object_new_object();
  5553. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5554. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5555. {
  5556. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5557. {
  5558. json_object *sampledValue = json_object_new_object();
  5559. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5560. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5561. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5562. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5563. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5564. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5565. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5566. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5567. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5568. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5569. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5570. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5571. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5572. json_object_array_add(sampledValues, sampledValue);
  5573. }
  5574. }
  5575. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5576. json_object_array_add(transactionDatas, transactionData);
  5577. }
  5578. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5579. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5580. ,MESSAGE_TYPE_CALL
  5581. ,guid
  5582. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5583. json_object_put(StopTransaction);
  5584. #if 1 // for TempStopTransaction
  5585. //Delete TempStopTransaction
  5586. if((access(TempStopTransaction,F_OK))!=-1)
  5587. {
  5588. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5589. }
  5590. #endif
  5591. #if 1
  5592. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5593. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5594. {
  5595. result = PASS;
  5596. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5597. }
  5598. #endif
  5599. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5600. OCPP_insert_transaction_msg(NO, queuedata);
  5601. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5602. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5603. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5604. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5605. {
  5606. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5607. }
  5608. //for test
  5609. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5610. return result;
  5611. }
  5612. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5613. {
  5614. mtrace();
  5615. int result = FAIL;
  5616. char guid[37]={0};
  5617. char tempdata[65]={0};
  5618. int tempIndex = 0;
  5619. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5620. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5621. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5622. //set value
  5623. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5624. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5625. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5626. -1);
  5627. random_uuid(guid);
  5628. //UTC Date time
  5629. struct timeval tmnow;
  5630. struct tm *tm;
  5631. char buf[28];//, usec_buf[6];
  5632. gettimeofday(&tmnow, NULL);
  5633. time_t t;
  5634. t = time(NULL);
  5635. /*UTC time and date*/
  5636. tm = gmtime(&t);
  5637. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5639. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5640. //********************************(1)Current.Import L1************************************************/
  5641. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5642. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5643. (dataType == ReadingContext_Trigger))
  5644. {
  5645. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5646. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5647. {
  5648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5649. {
  5650. tempIndex = ((gun_index==2) ? 1: 0);
  5651. }
  5652. else
  5653. {
  5654. tempIndex = gun_index;
  5655. }
  5656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5657. {
  5658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5659. {
  5660. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5661. }
  5662. }
  5663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5664. }
  5665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5666. {
  5667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5668. {
  5669. tempIndex = ((gun_index==2) ? 1: 0);
  5670. }
  5671. else
  5672. {
  5673. tempIndex = gun_index;
  5674. }
  5675. for (int index = 0; index < CCS_QUANTITY; index++)
  5676. {
  5677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5678. {
  5679. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5680. }
  5681. }
  5682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5683. }
  5684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5685. {
  5686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5687. {
  5688. tempIndex = ((gun_index==2) ? 1: 0);
  5689. }
  5690. else
  5691. {
  5692. tempIndex = gun_index;
  5693. }
  5694. for (int index = 0; index < GB_QUANTITY; index++)
  5695. {
  5696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5697. {
  5698. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5699. }
  5700. }
  5701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5702. }
  5703. else if(gunType[gun_index] == GUN_TYPE_DO)
  5704. {
  5705. tempIndex = gun_index;
  5706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5707. {
  5708. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5709. {
  5710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5711. }
  5712. }
  5713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5714. }
  5715. else
  5716. {
  5717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5718. {
  5719. tempIndex = 2;
  5720. }
  5721. else
  5722. {
  5723. tempIndex = gun_index;
  5724. }
  5725. for (int index = 0; index < AC_QUANTITY; index++)
  5726. {
  5727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5728. {
  5729. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5730. }
  5731. }
  5732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5733. }
  5734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5739. }
  5740. //********************************(2)Energy.Active.Import.Register ************************************************/
  5741. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5742. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5743. (dataType == ReadingContext_Trigger))
  5744. {
  5745. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5746. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5747. {
  5748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5749. {
  5750. tempIndex = ((gun_index==2) ? 1: 0);
  5751. }
  5752. else
  5753. {
  5754. tempIndex = gun_index;
  5755. }
  5756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5757. {
  5758. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5759. {
  5760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5761. }
  5762. }
  5763. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5764. }
  5765. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5766. {
  5767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5768. {
  5769. tempIndex = ((gun_index==2) ? 1: 0);
  5770. }
  5771. else
  5772. {
  5773. tempIndex = gun_index;
  5774. }
  5775. for (int index = 0; index < CCS_QUANTITY; index++)
  5776. {
  5777. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5778. {
  5779. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5780. }
  5781. }
  5782. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5783. }
  5784. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5785. {
  5786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5787. {
  5788. tempIndex = ((gun_index==2) ? 1: 0);
  5789. }
  5790. else
  5791. {
  5792. tempIndex = gun_index;
  5793. }
  5794. for (int index = 0; index < GB_QUANTITY; index++)
  5795. {
  5796. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5797. {
  5798. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5799. }
  5800. }
  5801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5802. }
  5803. else if(gunType[gun_index] == GUN_TYPE_DO)
  5804. {
  5805. tempIndex = gun_index;
  5806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5807. {
  5808. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5809. {
  5810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5811. }
  5812. }
  5813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5814. }
  5815. else
  5816. {
  5817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5818. {
  5819. tempIndex = 2;
  5820. }
  5821. else
  5822. {
  5823. tempIndex = gun_index;
  5824. }
  5825. for (int index = 0; index < AC_QUANTITY; index++)
  5826. {
  5827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5828. {
  5829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5830. }
  5831. }
  5832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5833. }
  5834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5839. }
  5840. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5843. (dataType == ReadingContext_Trigger))
  5844. {
  5845. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5847. {
  5848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5849. {
  5850. tempIndex = ((gun_index==2) ? 1: 0);
  5851. }
  5852. else
  5853. {
  5854. tempIndex = gun_index;
  5855. }
  5856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5857. {
  5858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5859. {
  5860. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5861. }
  5862. } // END OF FOR CHAdeMO_QUANTITY
  5863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5864. }
  5865. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5866. {
  5867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5868. {
  5869. tempIndex = ((gun_index==2) ? 1: 0);
  5870. }
  5871. else
  5872. {
  5873. tempIndex = gun_index;
  5874. }
  5875. for (int index = 0; index < CCS_QUANTITY; index++)
  5876. {
  5877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5878. {
  5879. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5880. }
  5881. } // END OF CCS_QUANTITY
  5882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5883. }
  5884. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  5895. {
  5896. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5897. {
  5898. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5899. }
  5900. } // END OF GB_QUANTITY
  5901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5902. }
  5903. else if(gunType[gun_index] == GUN_TYPE_DO)
  5904. {
  5905. tempIndex = gun_index;
  5906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5907. {
  5908. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5909. {
  5910. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5911. }
  5912. }
  5913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5914. }
  5915. else
  5916. {
  5917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5918. {
  5919. tempIndex = 2;
  5920. }
  5921. else
  5922. {
  5923. tempIndex = gun_index;
  5924. }
  5925. for (int index = 0; index < AC_QUANTITY; index++)
  5926. {
  5927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5928. {
  5929. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5930. }
  5931. }
  5932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5933. }
  5934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5939. }
  5940. //********************************(4)Power.Active.Import************************************************/
  5941. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5942. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5943. (dataType == ReadingContext_Trigger))
  5944. {
  5945. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5947. {
  5948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5949. {
  5950. tempIndex = ((gun_index==2) ? 1: 0);
  5951. }
  5952. else
  5953. {
  5954. tempIndex = gun_index;
  5955. }
  5956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5957. {
  5958. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5959. {
  5960. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5961. }
  5962. } // END OF FOR
  5963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5964. }
  5965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5966. {
  5967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5968. {
  5969. tempIndex = ((gun_index==2) ? 1: 0);
  5970. }
  5971. else
  5972. {
  5973. tempIndex = gun_index;
  5974. }
  5975. for (int index = 0; index < CCS_QUANTITY; index++)
  5976. {
  5977. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5978. {
  5979. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5980. }
  5981. }
  5982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5983. }
  5984. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5985. {
  5986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5987. {
  5988. tempIndex = ((gun_index==2) ? 1: 0);
  5989. }
  5990. else
  5991. {
  5992. tempIndex = gun_index;
  5993. }
  5994. for (int index = 0; index < GB_QUANTITY; index++)
  5995. {
  5996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5997. {
  5998. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5999. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6000. }
  6001. }
  6002. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6003. }
  6004. else if(gunType[gun_index] == GUN_TYPE_DO)
  6005. {
  6006. tempIndex = gun_index;
  6007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6008. {
  6009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6010. {
  6011. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6012. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6013. }
  6014. }
  6015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6016. }
  6017. else
  6018. {
  6019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6020. {
  6021. tempIndex = 2;
  6022. }
  6023. else
  6024. {
  6025. tempIndex = gun_index;
  6026. }
  6027. for (int index = 0; index < AC_QUANTITY; index++)
  6028. {
  6029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6030. {
  6031. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6032. }
  6033. }
  6034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6035. }
  6036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6041. }
  6042. //***********************************************(5)VOLTAGE L1******************************************************/
  6043. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6044. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6045. (dataType == ReadingContext_Trigger))
  6046. {
  6047. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6049. {
  6050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6051. {
  6052. tempIndex = ((gun_index==2) ? 1: 0);
  6053. }
  6054. else
  6055. {
  6056. tempIndex = gun_index;
  6057. }
  6058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6059. {
  6060. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6061. {
  6062. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6063. }
  6064. }
  6065. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6066. }
  6067. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6068. {
  6069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6070. {
  6071. tempIndex = ((gun_index==2) ? 1: 0);
  6072. }
  6073. else
  6074. {
  6075. tempIndex = gun_index;
  6076. }
  6077. for (int index = 0; index < CCS_QUANTITY; index++)
  6078. {
  6079. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6080. {
  6081. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6082. }
  6083. }
  6084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6085. }
  6086. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6087. {
  6088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6089. {
  6090. tempIndex = ((gun_index==2) ? 1: 0);
  6091. }
  6092. else
  6093. {
  6094. tempIndex = gun_index;
  6095. }
  6096. for (int index = 0; index < GB_QUANTITY; index++)
  6097. {
  6098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6099. {
  6100. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6101. }
  6102. }
  6103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6104. }
  6105. else if(gunType[gun_index] == GUN_TYPE_DO)
  6106. {
  6107. tempIndex = gun_index;
  6108. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6111. {
  6112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6113. }
  6114. }
  6115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6116. }
  6117. else
  6118. {
  6119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6120. {
  6121. tempIndex = 2;
  6122. }
  6123. else
  6124. {
  6125. tempIndex = gun_index;
  6126. }
  6127. for (int index = 0; index < AC_QUANTITY; index++)
  6128. {
  6129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6130. {
  6131. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6132. }
  6133. }
  6134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6135. }
  6136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6141. }
  6142. //***********************************************(6)SOC******************************************************/
  6143. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6144. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6145. (dataType == ReadingContext_Trigger))
  6146. {
  6147. 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))
  6148. {
  6149. //idx_sample=5;
  6150. //sampledValue = NULL;
  6151. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6152. {
  6153. tempIndex = ((gun_index==2) ? 1: 0);
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6160. {
  6161. //tempIndex = ((gun_index==2) ? 1: 0);
  6162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6163. {
  6164. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6165. {
  6166. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6167. }
  6168. }
  6169. }
  6170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6171. {
  6172. //tempIndex = ((gun_index==2) ? 1: 0);
  6173. for (int index = 0; index < CCS_QUANTITY; index++)
  6174. {
  6175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6176. {
  6177. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6178. }
  6179. }
  6180. }
  6181. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6182. {
  6183. //tempIndex = ((gun_index==2) ? 1: 0);
  6184. for (int index = 0; index < GB_QUANTITY; index++)
  6185. {
  6186. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6187. {
  6188. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6189. }
  6190. }
  6191. }
  6192. else if(gunType[gun_index] == GUN_TYPE_DO)
  6193. {
  6194. //tempIndex = ((gun_index==2) ? 1: 0);
  6195. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6196. {
  6197. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6198. {
  6199. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6200. }
  6201. }
  6202. }
  6203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6207. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6209. }
  6210. }
  6211. //********************************(7)Current.Import L2************************************************/
  6212. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6213. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6214. (dataType == ReadingContext_Trigger))
  6215. {
  6216. // Only for AC 3 phase
  6217. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6218. {
  6219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6220. {
  6221. tempIndex = 2;
  6222. }
  6223. else
  6224. {
  6225. tempIndex = gun_index;
  6226. }
  6227. for (int index = 0; index < AC_QUANTITY; index++)
  6228. {
  6229. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6230. {
  6231. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6232. }
  6233. }
  6234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6235. }
  6236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6241. }
  6242. //********************************(8)Current.Import L3************************************************/
  6243. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6244. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6245. (dataType == ReadingContext_Trigger))
  6246. {
  6247. // Only for AC 3 phase
  6248. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6249. {
  6250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6251. {
  6252. tempIndex = 2;
  6253. }
  6254. else
  6255. {
  6256. tempIndex = gun_index;
  6257. }
  6258. for (int index = 0; index < AC_QUANTITY; index++)
  6259. {
  6260. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6261. {
  6262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6263. }
  6264. }
  6265. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6266. }
  6267. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6268. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6272. }
  6273. //***********************************************(9)VOLTAGE L2******************************************************/
  6274. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6275. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6276. (dataType == ReadingContext_Trigger))
  6277. {
  6278. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6279. {
  6280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6281. {
  6282. tempIndex = 2;
  6283. }
  6284. else
  6285. {
  6286. tempIndex = gun_index;
  6287. }
  6288. for (int index = 0; index < AC_QUANTITY; index++)
  6289. {
  6290. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6291. {
  6292. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6293. }
  6294. }
  6295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6296. }
  6297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6299. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6302. }
  6303. //***********************************************(10)VOLTAGE L3******************************************************/
  6304. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6305. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6306. (dataType == ReadingContext_Trigger))
  6307. {
  6308. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6309. {
  6310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6311. {
  6312. tempIndex = 2;
  6313. }
  6314. else
  6315. {
  6316. tempIndex = gun_index;
  6317. }
  6318. for (int index = 0; index < AC_QUANTITY; index++)
  6319. {
  6320. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6321. {
  6322. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6323. }
  6324. }
  6325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6326. }
  6327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6332. }
  6333. //***********************************************(11)Current.Offered******************************************************/
  6334. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6335. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6336. (dataType == ReadingContext_Trigger))
  6337. {
  6338. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6339. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6340. {
  6341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6342. {
  6343. tempIndex = ((gun_index==2) ? 1: 0);
  6344. }
  6345. else
  6346. {
  6347. tempIndex = gun_index;
  6348. }
  6349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6350. {
  6351. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6352. {
  6353. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6354. }
  6355. } // END OF FOR CHAdeMO_QUANTITY
  6356. }
  6357. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6358. {
  6359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6360. {
  6361. tempIndex = ((gun_index==2) ? 1: 0);
  6362. }
  6363. else
  6364. {
  6365. tempIndex = gun_index;
  6366. }
  6367. for (int index = 0; index < CCS_QUANTITY; index++)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6370. {
  6371. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6372. }
  6373. } // END OF CCS_QUANTITY
  6374. }
  6375. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6376. {
  6377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6378. {
  6379. tempIndex = ((gun_index==2) ? 1: 0);
  6380. }
  6381. else
  6382. {
  6383. tempIndex = gun_index;
  6384. }
  6385. for (int index = 0; index < GB_QUANTITY; index++)
  6386. {
  6387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6388. {
  6389. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6390. }
  6391. } // END OF GB_QUANTITY
  6392. }
  6393. else if(gunType[gun_index] == GUN_TYPE_DO)
  6394. {
  6395. tempIndex = gun_index;
  6396. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6397. {
  6398. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6399. {
  6400. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6401. }
  6402. }
  6403. }
  6404. else
  6405. {
  6406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6407. {
  6408. tempIndex = 2;
  6409. }
  6410. else
  6411. {
  6412. tempIndex = gun_index;
  6413. }
  6414. for (int index = 0; index < AC_QUANTITY; index++)
  6415. {
  6416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6417. {
  6418. uint16_t currentOffer;
  6419. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6420. {
  6421. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6422. }
  6423. else
  6424. {
  6425. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6426. }
  6427. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6428. }
  6429. }
  6430. }
  6431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6436. }
  6437. //***********************************************(12)Power.Offered******************************************************/
  6438. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6439. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6440. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6441. {
  6442. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6443. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6444. {
  6445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6446. {
  6447. tempIndex = ((gun_index==2) ? 1: 0);
  6448. }
  6449. else
  6450. {
  6451. tempIndex = gun_index;
  6452. }
  6453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6454. {
  6455. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6456. {
  6457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6458. }
  6459. } // END OF FOR CHAdeMO_QUANTITY
  6460. }
  6461. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6462. {
  6463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6464. {
  6465. tempIndex = ((gun_index==2) ? 1: 0);
  6466. }
  6467. else
  6468. {
  6469. tempIndex = gun_index;
  6470. }
  6471. for (int index = 0; index < CCS_QUANTITY; index++)
  6472. {
  6473. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6474. {
  6475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6476. }
  6477. } // END OF CCS_QUANTITY
  6478. }
  6479. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6480. {
  6481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6482. {
  6483. tempIndex = ((gun_index==2) ? 1: 0);
  6484. }
  6485. else
  6486. {
  6487. tempIndex = gun_index;
  6488. }
  6489. for (int index = 0; index < GB_QUANTITY; index++)
  6490. {
  6491. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6492. {
  6493. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6494. }
  6495. } // END OF GB_QUANTITY
  6496. }
  6497. else if(gunType[gun_index] == GUN_TYPE_DO)
  6498. {
  6499. tempIndex = gun_index;
  6500. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6503. {
  6504. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6505. }
  6506. }
  6507. }
  6508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6513. }
  6514. // Message create ====================================================================================================
  6515. if(TRUE)
  6516. {
  6517. json_object *MeterValueReq = json_object_new_object();
  6518. json_object *MeterValues = json_object_new_array();
  6519. json_object *sampledValues = json_object_new_array();
  6520. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6521. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6522. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6523. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6524. {
  6525. json_object *MeterValue = json_object_new_object();
  6526. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6527. {
  6528. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6529. {
  6530. json_object *sampledValue = json_object_new_object();
  6531. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6532. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6533. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6534. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6535. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6536. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6537. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6538. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6539. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6540. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6541. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6542. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6543. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6544. json_object_array_add(sampledValues, sampledValue);
  6545. }
  6546. }
  6547. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6548. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6549. json_object_array_add(MeterValues, MeterValue);
  6550. }
  6551. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6552. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6553. ,gun_index + 1
  6554. ,MESSAGE_TYPE_CALL
  6555. ,guid
  6556. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6557. json_object_put(MeterValueReq);
  6558. }
  6559. // Put request guid to hash map
  6560. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6561. 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*/)
  6562. {
  6563. result = PASS;
  6564. //DEBUG_INFO("MeterValues mapitem pass\n");
  6565. }
  6566. if((dataType != ReadingContext_Trigger) &&
  6567. (dataType != ReadingContext_Sample_Clock) &&
  6568. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6569. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6570. else
  6571. {
  6572. if(FirstHeartBeat)
  6573. LWS_Send(queuedata +2);
  6574. }
  6575. return result;
  6576. }
  6577. int sendLogStatusNotificationRequest(char *status)
  6578. {
  6579. mtrace();
  6580. int result = PASS;
  6581. char message[4096]={0};
  6582. char guid[37]={0};
  6583. char tempdata[128]={0};
  6584. json_object *LogStatusNotification = json_object_new_object();
  6585. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6586. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6587. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6588. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6589. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6590. random_uuid(guid);
  6591. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6592. json_object_put(LogStatusNotification);
  6593. LWS_Send(message);
  6594. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6595. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6596. {
  6597. result = PASS;
  6598. }
  6599. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6600. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6601. return result;
  6602. }
  6603. int sendSecurityEventNotificationRequest()
  6604. {
  6605. mtrace();
  6606. int result = PASS;
  6607. char message[4096]={0};
  6608. char guid[37]={0};
  6609. char tempdata[128]={0};
  6610. json_object *SecurityEventNotification = json_object_new_object();
  6611. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6612. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6613. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6614. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6615. random_uuid(guid);
  6616. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6617. json_object_put(SecurityEventNotification);
  6618. LWS_Send(message);
  6619. sprintf(tempdata, "SecurityEventNotification,0");
  6620. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6621. {
  6622. result = PASS;
  6623. }
  6624. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6625. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6626. return result;
  6627. }
  6628. int sendSignCertificateRequest()
  6629. {
  6630. mtrace();
  6631. int result = PASS;
  6632. char message[4096]={0};
  6633. char guid[37]={0};
  6634. char tempdata[128]={0};
  6635. json_object *SignCertificate = json_object_new_object();
  6636. DEBUG_INFO("sendSignCertificateRequest...\n");
  6637. // Read csr file content
  6638. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6639. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6640. char *line = NULL;
  6641. size_t len = 0;
  6642. while(getline(&line, &len, fp) != -1)
  6643. {
  6644. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6645. {
  6646. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6647. }
  6648. }
  6649. fclose(fp);
  6650. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6651. random_uuid(guid);
  6652. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6653. json_object_put(SignCertificate);
  6654. LWS_Send(message);
  6655. sprintf(tempdata, "SignCertificate,0");
  6656. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6657. {
  6658. result = PASS;
  6659. }
  6660. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6661. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6662. return result;
  6663. }
  6664. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6665. {
  6666. mtrace();
  6667. int result = PASS;
  6668. char message[110]={0};
  6669. char guid[37]={0};
  6670. char tempdata[65]={0};
  6671. json_object *FirmwareStatusNotification = json_object_new_object();
  6672. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6673. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6674. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6675. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6676. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6677. random_uuid(guid);
  6678. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6679. json_object_put(FirmwareStatusNotification);
  6680. LWS_Send(message);
  6681. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6682. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6683. {
  6684. result = PASS;
  6685. }
  6686. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6687. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6688. return result;
  6689. }
  6690. //==========================================
  6691. // send confirm routine
  6692. //==========================================
  6693. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6694. {
  6695. mtrace();
  6696. int result = FAIL;
  6697. char message[100]={0};
  6698. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6699. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6700. LWS_Send(message);
  6701. result = TRUE;
  6702. return result;
  6703. }
  6704. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6705. {
  6706. mtrace();
  6707. int result = FAIL;
  6708. char message[100]={0};
  6709. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6710. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6711. LWS_Send(message);
  6712. result = TRUE;
  6713. return result;
  6714. }
  6715. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6716. {
  6717. mtrace();
  6718. int result = FAIL;
  6719. char message[100]={0};
  6720. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6722. LWS_Send(message);
  6723. result = TRUE;
  6724. return result;
  6725. }
  6726. int sendClearCacheConfirmation(char *uuid,char *payload)
  6727. {
  6728. mtrace();
  6729. int result = FAIL;
  6730. char message[500]={0};
  6731. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6732. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6733. LWS_Send(message);
  6734. return result;
  6735. }
  6736. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6737. {
  6738. mtrace();
  6739. int result = FAIL;
  6740. char message[500]={0};
  6741. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6742. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6743. LWS_Send(message);
  6744. return result;
  6745. }
  6746. int sendDataTransferConfirmation(char *uuid,char *payload)
  6747. {
  6748. mtrace();
  6749. char statusStr[20]={0};
  6750. char dataStr[10]={0};
  6751. char sstr[20]={0};
  6752. int c = 0;
  6753. char *loc;
  6754. int result = FAIL;
  6755. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6756. /**********************status**************************/
  6757. loc = strstr(payload, "status");
  6758. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6759. c = 0;
  6760. while (loc[3+strlen("status")+c] != '\"')
  6761. {
  6762. sstr[c] = loc[3+strlen("status")+c];
  6763. c++;
  6764. }
  6765. sstr[c] = '\0';
  6766. strcpy(statusStr, sstr);
  6767. /**********************data**************************/
  6768. loc = strstr(payload, "data");
  6769. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6770. c = 0;
  6771. while (loc[3+strlen("data")+c] != '\"')
  6772. {
  6773. sstr[c] = loc[3+strlen("data")+c];
  6774. c++;
  6775. }
  6776. sstr[c] = '\0';
  6777. strcpy(dataStr, sstr);
  6778. return result;
  6779. }
  6780. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6781. {
  6782. mtrace();
  6783. int result = FAIL;
  6784. char message[1000]={0};
  6785. int CompositeScheduleIndex = 0;
  6786. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6787. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6788. if(nPeriod == 0)
  6789. {
  6790. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6791. {
  6792. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6793. ,MESSAGE_TYPE_CALLRESULT
  6794. ,uuid
  6795. ,payload
  6796. ,connectorIdInt);
  6797. }
  6798. else
  6799. {
  6800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6801. ,MESSAGE_TYPE_CALLRESULT
  6802. ,uuid
  6803. ,payload
  6804. ,connectorIdInt
  6805. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6806. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6807. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6808. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6809. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6810. }
  6811. }
  6812. else
  6813. {
  6814. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6815. ,MESSAGE_TYPE_CALLRESULT
  6816. ,uuid
  6817. ,payload
  6818. ,connectorIdInt
  6819. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6820. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6821. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6822. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6823. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6824. {
  6825. if (idx_sample == 0)
  6826. {
  6827. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6828. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6829. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6830. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6831. }
  6832. else
  6833. {
  6834. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6835. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6836. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6837. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6838. }
  6839. }
  6840. sprintf(message + strlen(message), "]}}]");
  6841. }
  6842. LWS_Send(message);
  6843. result = TRUE;
  6844. return result;
  6845. }
  6846. int sendGetConfigurationConfirmation(char *uuid)
  6847. {
  6848. mtrace();
  6849. int result = FAIL;
  6850. int MaxKeySupported = 0;
  6851. int sentConfigurationNumber= 0;
  6852. int sentunConfigurationNumber= 0;
  6853. char message[1024*10]={0};
  6854. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6855. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6856. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6857. ,MESSAGE_TYPE_CALLRESULT
  6858. ,uuid );
  6859. //configuration key
  6860. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6861. {
  6862. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6863. {
  6864. if (sentConfigurationNumber == 0)
  6865. {
  6866. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6867. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6868. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6869. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6870. }
  6871. else
  6872. {
  6873. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6874. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6875. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6876. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6877. }
  6878. sentConfigurationNumber = sentConfigurationNumber + 1;
  6879. }
  6880. }
  6881. sprintf(message + strlen(message), "]");
  6882. if(UnknownKeynum != 0)
  6883. {
  6884. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6885. //unkown key
  6886. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6887. {
  6888. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6889. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6890. if(sentunConfigurationNumber == 0)
  6891. {
  6892. sprintf(message + strlen(message), "\"%s\""
  6893. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6894. }
  6895. else
  6896. {
  6897. sprintf(message + strlen(message), ",\"%s\""
  6898. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6899. }
  6900. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6901. }
  6902. sprintf(message + strlen(message), "]");
  6903. }
  6904. sprintf(message + strlen(message), "}]");
  6905. LWS_Send(message);
  6906. return result;
  6907. }
  6908. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6909. {
  6910. mtrace();
  6911. int result = FAIL;
  6912. char message[400]={0};
  6913. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6914. if(strcmp(payload,"")==0)
  6915. {
  6916. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6917. }
  6918. else
  6919. {
  6920. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6921. }
  6922. LWS_Send(message);
  6923. result = TRUE;
  6924. return result;
  6925. }
  6926. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6927. {
  6928. mtrace();
  6929. int result = FAIL;
  6930. char message[80]={0};
  6931. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6932. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6933. LWS_Send(message);
  6934. result = TRUE;
  6935. return result;
  6936. }
  6937. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6938. {
  6939. mtrace();
  6940. int result = FAIL;
  6941. char message[80]={0};
  6942. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6943. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6944. LWS_Send(message);
  6945. result = TRUE;
  6946. return result;
  6947. }
  6948. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6949. {
  6950. mtrace();
  6951. int result = FAIL;
  6952. char message[80]={0};
  6953. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6954. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6955. LWS_Send(message);
  6956. result = TRUE;
  6957. return result;
  6958. }
  6959. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6960. {
  6961. mtrace();
  6962. int result = FAIL;
  6963. char message[80]={0};
  6964. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6965. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6966. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6967. LWS_Send(message);
  6968. result = TRUE;
  6969. return result;
  6970. }
  6971. int sendResetConfirmation(char *uuid,char *payload)
  6972. {
  6973. mtrace();
  6974. int result = FAIL;
  6975. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6976. char message[80]={0};
  6977. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6978. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6979. LWS_Send(message);
  6980. result = TRUE;
  6981. return result;
  6982. }
  6983. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6984. {
  6985. mtrace();
  6986. int result = FAIL;
  6987. char message[500]={0};
  6988. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6989. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6990. LWS_Send(message);
  6991. result = TRUE;
  6992. return result;
  6993. }
  6994. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6995. {
  6996. mtrace();
  6997. int result = FAIL;
  6998. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6999. char message[80]={0};
  7000. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7001. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7002. LWS_Send(message);
  7003. result = TRUE;
  7004. return result;
  7005. }
  7006. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7007. {
  7008. mtrace();
  7009. int result = FAIL;
  7010. char message[80]={0};
  7011. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7012. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7013. LWS_Send(message);
  7014. result = TRUE;
  7015. return result;
  7016. }
  7017. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7018. {
  7019. mtrace();
  7020. int result = FAIL;
  7021. char message[80]={0};
  7022. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7023. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7024. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7025. LWS_Send(message);
  7026. result = TRUE;
  7027. return result;
  7028. }
  7029. int sendUpdateFirmwareConfirmation(char *uuid)
  7030. {
  7031. mtrace();
  7032. int result = FAIL;
  7033. char message[60]={0};
  7034. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7035. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7036. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7037. LWS_Send(message);
  7038. result = TRUE;
  7039. return result;
  7040. }
  7041. int sendCertificateSignedConfirmation(char *uuid)
  7042. {
  7043. mtrace();
  7044. int result = PASS;
  7045. char message[4096]={0};
  7046. json_object *CertificateSigned = json_object_new_object();
  7047. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7048. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7049. sprintf(message,"[%d,\"%s\",%s]"
  7050. ,MESSAGE_TYPE_CALLRESULT
  7051. ,uuid
  7052. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7053. json_object_put(CertificateSigned);
  7054. LWS_Send(message);
  7055. return result;
  7056. }
  7057. int sendDeleteCertificateConfirmation(char *uuid)
  7058. {
  7059. mtrace();
  7060. int result = PASS;
  7061. char message[4096]={0};
  7062. json_object *DeleteCertificate = json_object_new_object();
  7063. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7064. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7065. sprintf(message,"[%d,\"%s\",%s]"
  7066. ,MESSAGE_TYPE_CALLRESULT
  7067. ,uuid
  7068. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7069. json_object_put(DeleteCertificate);
  7070. LWS_Send(message);
  7071. return result;
  7072. }
  7073. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7074. {
  7075. mtrace();
  7076. int result = PASS;
  7077. char message[4096]={0};
  7078. json_object *ExtendedTriggerMessage = json_object_new_object();
  7079. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7080. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7081. sprintf(message,"[%d,\"%s\",%s]"
  7082. ,MESSAGE_TYPE_CALLRESULT
  7083. ,uuid
  7084. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7085. json_object_put(ExtendedTriggerMessage);
  7086. LWS_Send(message);
  7087. return result;
  7088. }
  7089. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7090. {
  7091. mtrace();
  7092. int result = PASS;
  7093. char message[4096]={0};
  7094. json_object *GetInstalledCertificateIds = json_object_new_object();
  7095. json_object *certificateHashDataDatas = json_object_new_array();
  7096. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7097. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7098. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7099. {
  7100. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7101. {
  7102. json_object *certificateHashData = json_object_new_object();
  7103. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7104. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7105. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7106. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7107. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7108. }
  7109. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7110. }
  7111. else
  7112. {
  7113. json_object_put(certificateHashDataDatas);
  7114. }
  7115. sprintf(message,"[%d,\"%s\",%s]"
  7116. ,MESSAGE_TYPE_CALLRESULT
  7117. ,uuid
  7118. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7119. json_object_put(GetInstalledCertificateIds);
  7120. LWS_Send(message);
  7121. return result;
  7122. }
  7123. int sendGetLogConfirmation(char *uuid)
  7124. {
  7125. mtrace();
  7126. int result = PASS;
  7127. char message[4096]={0};
  7128. json_object *GetLog = json_object_new_object();
  7129. DEBUG_INFO("sendGetLogConfirmation...\n");
  7130. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7131. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7132. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7133. sprintf(message,"[%d,\"%s\",%s]"
  7134. ,MESSAGE_TYPE_CALLRESULT
  7135. ,uuid
  7136. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7137. json_object_put(GetLog);
  7138. LWS_Send(message);
  7139. return result;
  7140. }
  7141. int sendInstallCertificateConfirmation(char *uuid)
  7142. {
  7143. mtrace();
  7144. int result = PASS;
  7145. char message[4096]={0};
  7146. json_object *InstallCertificate = json_object_new_object();
  7147. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7148. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7149. sprintf(message,"[%d,\"%s\",%s]"
  7150. ,MESSAGE_TYPE_CALLRESULT
  7151. ,uuid
  7152. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7153. json_object_put(InstallCertificate);
  7154. LWS_Send(message);
  7155. return result;
  7156. }
  7157. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7158. {
  7159. mtrace();
  7160. int result = PASS;
  7161. char message[4096]={0};
  7162. json_object *SignedUpdateFirmware = json_object_new_object();
  7163. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7164. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7165. sprintf(message,"[%d,\"%s\",%s]"
  7166. ,MESSAGE_TYPE_CALLRESULT
  7167. ,uuid
  7168. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7169. json_object_put(SignedUpdateFirmware);
  7170. LWS_Send(message);
  7171. return result;
  7172. }
  7173. int sendUnknownConfirmation(char *uuid)
  7174. {
  7175. mtrace();
  7176. int result = PASS;
  7177. char message[256]={0};
  7178. DEBUG_INFO("sendUnknownConfirmation...\n");
  7179. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7180. LWS_Send(message);
  7181. return result;
  7182. }
  7183. //==========================================
  7184. // Handle server request routine Start
  7185. //==========================================
  7186. int handleCancelReservationRequest(char *uuid, char *payload)
  7187. {
  7188. mtrace();
  7189. int result = FAIL;
  7190. int gunNO = 0;
  7191. int reservationIdInt = -1;
  7192. char comfirmstr[20];
  7193. DEBUG_INFO("handleCancelReservationRequest...\n");
  7194. json_object *CancelReservation;
  7195. CancelReservation = json_tokener_parse(payload);
  7196. if(!is_error(CancelReservation))
  7197. {
  7198. // Required data
  7199. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7200. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7201. }
  7202. json_object_put(CancelReservation);
  7203. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7204. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7205. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7206. if(reservationIdInt != -1)
  7207. {
  7208. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7209. //check Transaction active
  7210. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7212. {
  7213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7214. {
  7215. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7216. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7217. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7218. {
  7219. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7220. }
  7221. else
  7222. {
  7223. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7224. }
  7225. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7226. goto end;
  7227. }
  7228. }
  7229. for (int index = 0; index < CCS_QUANTITY; index++)
  7230. {
  7231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7232. {
  7233. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7234. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7235. if(gunType[2] == GUN_TYPE_CCS)
  7236. {
  7237. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7238. }
  7239. else
  7240. {
  7241. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7242. }
  7243. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7244. goto end;
  7245. }
  7246. }
  7247. for (int index = 0; index < GB_QUANTITY; index++)
  7248. {
  7249. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7250. {
  7251. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7252. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7253. if(gunType[2] == GUN_TYPE_GBT)
  7254. {
  7255. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7256. }
  7257. else
  7258. {
  7259. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7260. }
  7261. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7262. goto end;
  7263. }
  7264. }
  7265. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7266. {
  7267. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7268. {
  7269. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7270. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7271. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7272. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7273. goto end;
  7274. }
  7275. }
  7276. for (int index = 0; index < AC_QUANTITY; index++)
  7277. {
  7278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7279. {
  7280. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7281. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7283. {
  7284. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7285. }
  7286. else
  7287. {
  7288. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7289. }
  7290. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7291. goto end;
  7292. }
  7293. }
  7294. }
  7295. //The reservationId does NOT match the reservationId
  7296. sendCancelReservationConfirmation(uuid, comfirmstr);
  7297. end:
  7298. // Fill in ocpp packet uuid
  7299. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7300. return result;
  7301. }
  7302. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7303. {
  7304. mtrace();
  7305. int result = FAIL;
  7306. int gunIndex = 0;
  7307. char typeStr[16]={0};
  7308. char comfirmstr[20];
  7309. int specificId = FALSE;
  7310. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7311. json_object *ChangeAvailability;
  7312. ChangeAvailability = json_tokener_parse(payload);
  7313. if(!is_error(ChangeAvailability))
  7314. {
  7315. // Required data
  7316. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7317. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7318. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7319. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7320. }
  7321. json_object_put(ChangeAvailability);
  7322. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7323. {
  7324. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7325. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7326. }
  7327. else if(gunIndex == 0)
  7328. {
  7329. for(int i=0; i < gunTotalNumber; i++)
  7330. {
  7331. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7332. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7333. }
  7334. }
  7335. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7337. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7338. {
  7339. specificId = TRUE;
  7340. }
  7341. if(specificId == FALSE)
  7342. goto end;
  7343. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7344. {
  7345. //----------------------gunIndex is 0 ------------------------------------------------//
  7346. if(gunIndex == 0)
  7347. {
  7348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7349. {
  7350. for(int i=0; i < gunTotalNumber; i++)
  7351. {
  7352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7353. {
  7354. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7355. {
  7356. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7357. {
  7358. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7359. goto end;
  7360. }
  7361. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7362. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7363. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7364. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7365. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7366. {
  7367. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7368. goto end;
  7369. }
  7370. }
  7371. }//END FOR CHAdeMO_QUANTITY
  7372. for (int index = 0; index < CCS_QUANTITY; index++)
  7373. {
  7374. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7375. {
  7376. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7377. {
  7378. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7379. goto end;
  7380. }
  7381. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7382. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7383. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7384. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7385. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7386. {
  7387. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7388. goto end;
  7389. }
  7390. }
  7391. }//END FOR CCS_QUANTITY
  7392. for (int index = 0; index < GB_QUANTITY; index++)
  7393. {
  7394. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7395. {
  7396. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7397. {
  7398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7399. goto end;
  7400. }
  7401. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7402. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7403. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7404. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7405. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7406. {
  7407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7408. goto end;
  7409. }
  7410. }
  7411. }// END FOR GB_QUANTITY
  7412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7413. {
  7414. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7415. {
  7416. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7417. {
  7418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7419. goto end;
  7420. }
  7421. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7422. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7423. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7424. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7425. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7426. {
  7427. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7428. goto end;
  7429. }
  7430. }
  7431. }// END FOR GENERAL_GUN_QUANTITY
  7432. for (int index = 0; index < AC_QUANTITY; index++)
  7433. {
  7434. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7435. {
  7436. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7437. {
  7438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7439. goto end;
  7440. }
  7441. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7442. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7443. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7444. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7445. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7446. {
  7447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7448. goto end;
  7449. }
  7450. }
  7451. }//END FOR AC_QUANTITY
  7452. }// END FOR gunTotalNumber
  7453. }
  7454. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7455. {
  7456. for(int i=0; i < gunTotalNumber; i++)
  7457. {
  7458. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7459. {
  7460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7461. goto end;
  7462. }
  7463. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7464. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7465. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7466. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7467. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7468. {
  7469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7470. goto end;
  7471. }
  7472. }
  7473. }
  7474. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7475. goto end;
  7476. }
  7477. //----------------------gunIndex is not 0 ------------------------------------------------//
  7478. //check Transaction active
  7479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7480. {
  7481. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7482. {
  7483. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7484. {
  7485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7486. goto end;
  7487. }
  7488. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7489. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7490. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7491. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7492. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7493. {
  7494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7495. goto end;
  7496. }
  7497. else
  7498. {
  7499. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7501. goto end;
  7502. }
  7503. }
  7504. }//END FOR CHAdeMO_QUANTITY
  7505. for (int index = 0; index < CCS_QUANTITY; index++)
  7506. {
  7507. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7508. {
  7509. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7510. {
  7511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7512. goto end;
  7513. }
  7514. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7515. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7516. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7517. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7518. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7519. {
  7520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7521. goto end;
  7522. }
  7523. else
  7524. {
  7525. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7527. goto end;
  7528. }
  7529. }
  7530. }//END FOR CCS_QUANTITY
  7531. for (int index = 0; index < GB_QUANTITY; index++)
  7532. {
  7533. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7534. {
  7535. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7536. {
  7537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7538. goto end;
  7539. }
  7540. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7541. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7542. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7543. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7544. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7545. {
  7546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7547. goto end;
  7548. }
  7549. else
  7550. {
  7551. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7553. goto end;
  7554. }
  7555. }
  7556. }// END FOR GB_QUANTITY
  7557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7558. {
  7559. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7560. {
  7561. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7562. {
  7563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7564. goto end;
  7565. }
  7566. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7567. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7568. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7569. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7570. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7571. {
  7572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7573. goto end;
  7574. }
  7575. else
  7576. {
  7577. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7578. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7579. goto end;
  7580. }
  7581. }
  7582. }// END FOR GENERAL_GUN_QUANTITY
  7583. for (int index = 0; index < AC_QUANTITY; index++)
  7584. {
  7585. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7586. {
  7587. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7588. {
  7589. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7590. goto end;
  7591. }
  7592. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7593. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7594. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7595. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7596. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7597. {
  7598. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7599. goto end;
  7600. }
  7601. else
  7602. {
  7603. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7605. goto end;
  7606. }
  7607. }
  7608. }//END FOR AC_QUANTITY
  7609. }//END FOR AvailabilityTypeStr[Inoperative]
  7610. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7611. {
  7612. //----------------------gunIndex is 0 ------------------------------------------------//
  7613. if(gunIndex == 0)
  7614. {
  7615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7616. {
  7617. for(int i=0; i < gunTotalNumber; i++)
  7618. {
  7619. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7620. {
  7621. 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
  7622. {
  7623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7624. goto end;
  7625. }
  7626. }//END FOR CHAdeMO_QUANTITY
  7627. for (int index = 0; index < CCS_QUANTITY; index++)
  7628. {
  7629. 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
  7630. {
  7631. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7632. goto end;
  7633. }
  7634. }//END FOR CCS_QUANTITY
  7635. for (int index = 0; index < GB_QUANTITY; index++)
  7636. {
  7637. 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
  7638. {
  7639. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7641. goto end;
  7642. }
  7643. }// END FOR GB_QUANTITY
  7644. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7645. {
  7646. 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
  7647. {
  7648. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7650. goto end;
  7651. }
  7652. }// END FOR GENERAL_GUN_QUANTITY
  7653. for (int index = 0; index < AC_QUANTITY; index++)
  7654. {
  7655. 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
  7656. {
  7657. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7658. goto end;
  7659. }
  7660. }//END FOR CHAdeMO_QUANTITY
  7661. }// END FOR gunTotalNumber
  7662. }
  7663. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7664. {
  7665. for(int i=0; i < gunTotalNumber; i++)
  7666. {
  7667. for (int index = 0; index < AC_QUANTITY; index++)
  7668. {
  7669. 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
  7670. {
  7671. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7672. goto end;
  7673. }
  7674. }//END FOR CHAdeMO_QUANTITY
  7675. } // END FOR gunTotalNumber
  7676. }
  7677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7678. goto end;
  7679. }
  7680. //----------------------gunIndex is not 0 ------------------------------------------------//
  7681. //check Transaction active
  7682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7683. {
  7684. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7685. {
  7686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7687. goto end;
  7688. }
  7689. }//END FOR CHAdeMO_QUANTITY
  7690. for (int index = 0; index < CCS_QUANTITY; index++)
  7691. {
  7692. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7693. {
  7694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7695. goto end;
  7696. }
  7697. }//END FOR CCS_QUANTITY
  7698. for (int index = 0; index < GB_QUANTITY; index++)
  7699. {
  7700. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7701. {
  7702. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7703. goto end;
  7704. }
  7705. }// END FOR GB_QUANTITY
  7706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7707. {
  7708. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7709. {
  7710. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7711. goto end;
  7712. }
  7713. }// END FOR GENERAL_GUN_QUANTITY
  7714. for (int index = 0; index < AC_QUANTITY; index++)
  7715. {
  7716. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7717. {
  7718. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7719. goto end;
  7720. }
  7721. }//END FOR AC_QUANTITY
  7722. }//END FOR AvailabilityTypeStr[Operative]
  7723. end:
  7724. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7725. {
  7726. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7727. }
  7728. else
  7729. {
  7730. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7731. }
  7732. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7733. {
  7734. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7735. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7736. }
  7737. else if(gunIndex == 0)
  7738. {
  7739. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7740. {
  7741. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7742. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7743. }
  7744. }
  7745. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7746. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7747. return result;
  7748. }
  7749. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7750. {
  7751. mtrace();
  7752. int result = FAIL;
  7753. char keystr[40]={0};
  7754. char valuestr[256]={0};
  7755. char comfirmstr[20]={0};
  7756. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7757. json_object *ChangeConfiguration;
  7758. ChangeConfiguration = json_tokener_parse(payload);
  7759. if(!is_error(ChangeConfiguration))
  7760. {
  7761. // Required data
  7762. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7763. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7764. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7765. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7766. }
  7767. json_object_put(ChangeConfiguration);
  7768. if((uuid==NULL) || (payload ==NULL) )
  7769. {
  7770. DEBUG_ERROR("Payload is null\n");
  7771. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7772. }
  7773. else
  7774. {
  7775. int status = setKeyValue(keystr, valuestr);
  7776. switch(status)
  7777. {
  7778. case ConfigurationStatus_Accepted:
  7779. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7780. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7781. StoreConfigurationTable();
  7782. break;
  7783. case RebootRequired:
  7784. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7785. StoreConfigurationTable();
  7786. break;
  7787. case NotSupported:
  7788. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7789. break;
  7790. case ConfigurationStatus_Rejected:
  7791. default:
  7792. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7793. break;
  7794. }
  7795. }
  7796. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7797. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7798. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7799. {
  7800. ChageWebSocketPingInterval(atoi(valuestr));
  7801. }
  7802. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7803. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7804. {
  7805. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7806. SetOcppConnStatus(FALSE);
  7807. }
  7808. return result;
  7809. }
  7810. int handleClearCacheRequest(char *uuid, char *payload)
  7811. {
  7812. mtrace();
  7813. int result = FAIL;
  7814. char comfirmstr[20];
  7815. char rmFileCmd[100]={0};
  7816. struct stat stats;
  7817. DEBUG_INFO("handleClearCacheRequest...\n");
  7818. stat("/Storage/OCPP", &stats);
  7819. // Check for directory existence
  7820. if (S_ISDIR(stats.st_mode) == 1)
  7821. {}
  7822. else
  7823. {
  7824. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7825. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7826. system(rmFileCmd);
  7827. }
  7828. if(OCPP_cleanLocalCache())
  7829. {
  7830. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7831. }
  7832. else
  7833. {
  7834. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7835. }
  7836. sendClearCacheConfirmation(uuid, comfirmstr);
  7837. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7838. return result;
  7839. }
  7840. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7841. {
  7842. mtrace();
  7843. int result = FAIL;
  7844. int resultRename;
  7845. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7846. char chargingProfilePurposeStr[26]={0};
  7847. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7848. char tempchargingProfilePurposeStr[26]={0};
  7849. char str[100]={0};
  7850. char fname[200]={0};
  7851. char comfirmstr[20]={0};
  7852. char word[1600]={0};
  7853. int clearflag = FALSE;
  7854. int chargingProfileIdIsNULL = FALSE;
  7855. int connectorIsNULL = FALSE;
  7856. int chargingProfilePurposeIsNULL = FALSE;
  7857. int stackLevelIsNULL = FALSE;
  7858. //int GotoEnd = FALSE;
  7859. FILE *fptr1, *fptr2;
  7860. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7861. int n_chargingProfile=0;
  7862. int isEmptyFile = FALSE;
  7863. char sLineWord[1600]={0};
  7864. char chargingProfiles[10][100]={0};
  7865. int ChargeProfileCount = 0;
  7866. int ch;
  7867. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7868. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7869. json_object *ClearChargingProfile;
  7870. ClearChargingProfile = json_tokener_parse(payload);
  7871. if(!is_error(ClearChargingProfile))
  7872. {
  7873. // Optional data
  7874. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7875. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7876. else
  7877. chargingProfileIdIsNULL = TRUE;
  7878. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7879. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7880. else
  7881. connectorIsNULL = TRUE;
  7882. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7883. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7884. else
  7885. chargingProfilePurposeIsNULL = TRUE;
  7886. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7887. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7888. else
  7889. stackLevelIsNULL = TRUE;
  7890. }
  7891. json_object_put(ClearChargingProfile);
  7892. if(connectorIsNULL == FALSE)
  7893. {
  7894. switch(connectorIdInt)
  7895. {
  7896. case 0:
  7897. if(chargingProfilePurposeIsNULL == TRUE)
  7898. {
  7899. int l = 0;
  7900. strcpy(fname, ChargePointMaxProfile_JSON);
  7901. if((access(fname,F_OK))!=-1)
  7902. {
  7903. strcpy(chargingProfiles[l], fname);
  7904. l = l + 1;
  7905. }
  7906. strcpy(fname, TxDefaultProfile_0_JSON);
  7907. if((access(fname,F_OK))!=-1)
  7908. {
  7909. strcpy(chargingProfiles[l], fname);
  7910. l = l + 1;
  7911. }
  7912. ChargeProfileCount = l;
  7913. }
  7914. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7915. {
  7916. strcpy(fname, ChargePointMaxProfile_JSON);
  7917. if((access(fname,F_OK))!=-1)
  7918. {
  7919. strcpy(chargingProfiles[0], fname);
  7920. ChargeProfileCount = 1;
  7921. }
  7922. }
  7923. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7924. {
  7925. strcpy(fname, TxDefaultProfile_0_JSON);
  7926. if((access(fname,F_OK))!=-1)
  7927. {
  7928. strcpy(chargingProfiles[0], fname);
  7929. ChargeProfileCount = 1;
  7930. }
  7931. }
  7932. break;
  7933. default:
  7934. if(chargingProfilePurposeIsNULL == TRUE)
  7935. {
  7936. int m = 0;
  7937. memset(fname, 0, ARRAY_SIZE(fname));
  7938. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7939. if((access(fname,F_OK))!=-1)
  7940. {
  7941. strcpy(chargingProfiles[m], fname);
  7942. m = m + 1;
  7943. }
  7944. memset(fname, 0, ARRAY_SIZE(fname));
  7945. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7946. if((access(fname,F_OK))!=-1)
  7947. {
  7948. strcpy(chargingProfiles[m], fname);
  7949. m = m + 1;
  7950. }
  7951. ChargeProfileCount = m;
  7952. }
  7953. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7954. {
  7955. //strcpy(fname, TxDefaultProfile_1_JSON);
  7956. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7957. if((access(fname,F_OK))!=-1)
  7958. {
  7959. strcpy(chargingProfiles[0], fname);
  7960. ChargeProfileCount = 1;
  7961. }
  7962. }
  7963. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7964. {
  7965. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7966. if((access(fname,F_OK))!=-1)
  7967. {
  7968. strcpy(chargingProfiles[0], fname);
  7969. ChargeProfileCount = 1;
  7970. }
  7971. //strcpy(fname, TxProfile_1_JSON);
  7972. }
  7973. //strcpy(fname, ChargePointMaxProfile_JSON );
  7974. break;
  7975. }
  7976. }
  7977. else // Check all Charging Profiles
  7978. {
  7979. int i = 0;
  7980. char fnametemp[200]={0};
  7981. ChargeProfileCount = 0;
  7982. //Check ChargePointMaxProfile.json exit
  7983. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7984. {
  7985. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7986. i = i + 1;
  7987. }
  7988. //Check TxDefaultProfile_0.json exit
  7989. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7990. {
  7991. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7992. i = i + 1;
  7993. }
  7994. //Check TxDefaultProfile_%d.json
  7995. for(int j=1; j <= gunTotalNumber; j++)
  7996. {
  7997. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7998. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7999. if((access(fnametemp,F_OK))!=-1)
  8000. {
  8001. strcpy(chargingProfiles[i], fnametemp);
  8002. i = i + 1;
  8003. }
  8004. }
  8005. //Check TxProfile_%d.json
  8006. for(int j=1; j <= gunTotalNumber; j++)
  8007. {
  8008. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8009. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8010. if((access(fnametemp,F_OK))!=-1)
  8011. {
  8012. strcpy(chargingProfiles[i], fnametemp);
  8013. i = i + 1;
  8014. }
  8015. }
  8016. ChargeProfileCount = i;
  8017. }// End connectorIsNULL is TRUE
  8018. if(ChargeProfileCount == 0)
  8019. {
  8020. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8021. goto end;
  8022. }
  8023. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8024. {
  8025. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8026. goto end;
  8027. }
  8028. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8029. {
  8030. memset(str, 0, ARRAY_SIZE(str));
  8031. // clear temp file
  8032. sprintf(str,"rm -f %s",temp);
  8033. system(str);
  8034. for(int k=0; k < ChargeProfileCount; k++)
  8035. {
  8036. memset(str, 0, ARRAY_SIZE(str));
  8037. //clear file in C
  8038. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8039. system(str);
  8040. }
  8041. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8042. goto end;
  8043. }
  8044. else if(connectorIsNULL == TRUE)
  8045. {
  8046. for(int k=0; k < ChargeProfileCount; k++)
  8047. {
  8048. fptr1 = fopen(chargingProfiles[k], "r");
  8049. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8050. //Check Charging Profile Count
  8051. while(fscanf(fptr1, "%s", word) != EOF)
  8052. {
  8053. //DEBUG_INFO("word=%s\n",word);
  8054. if(strstr(word, "chargingProfileId")!= NULL)
  8055. {
  8056. //DEBUG_INFO("test chargingProfileId \n");
  8057. n_chargingProfile = n_chargingProfile + 1;
  8058. //DEBUG_INFO("chargingProfileId Found\n");
  8059. }
  8060. }
  8061. rewind(fptr1);
  8062. //search Charging Profile Element
  8063. //int i= 0;
  8064. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8065. {
  8066. json_object *tmpProfilee;
  8067. tmpProfilee = json_tokener_parse(sLineWord);
  8068. if(!is_error(tmpProfilee))
  8069. {
  8070. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8071. {
  8072. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8073. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8074. }
  8075. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8076. {
  8077. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8078. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8079. }
  8080. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8081. {
  8082. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8083. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8084. }
  8085. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8086. {
  8087. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8088. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8089. }
  8090. }
  8091. json_object_put(tmpProfilee);
  8092. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8093. {
  8094. //------- not write to fptr2-------//
  8095. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8096. //clearflag = TRUE;
  8097. }
  8098. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8099. {
  8100. //------- not write to fptr2-------//
  8101. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8102. }
  8103. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8104. {
  8105. //------- not write to fptr2-------//
  8106. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8107. }
  8108. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8109. {
  8110. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8111. }
  8112. else
  8113. {
  8114. fprintf(fptr2, sLineWord);//writing data into file
  8115. }
  8116. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8117. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8118. if(clearflag == TRUE)
  8119. {
  8120. fclose(fptr1);
  8121. fclose(fptr2);
  8122. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8123. system(str);
  8124. // clear temp file
  8125. sprintf(str,"rm -f %s",temp);
  8126. system(str);
  8127. }
  8128. else
  8129. {
  8130. fclose(fptr1);
  8131. fclose(fptr2);
  8132. memset(str, 0, ARRAY_SIZE(str));
  8133. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8134. system(str);
  8135. resultRename = rename(temp, chargingProfiles[k]);
  8136. if(resultRename == 0)
  8137. {
  8138. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8139. }
  8140. else
  8141. {
  8142. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8143. }
  8144. if(comfirmstr[0]== 0)
  8145. {
  8146. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8147. }
  8148. //Check chargingProfile is empty file
  8149. /*------ Read the file ----------------*/
  8150. fptr1=fopen(chargingProfiles[k],"r");
  8151. ch=fgetc(fptr1);
  8152. rewind(fptr1);
  8153. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8154. if(ch!=EOF)
  8155. {
  8156. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8157. {
  8158. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8159. if(sLineWord[0]=='\0')
  8160. {
  8161. isEmptyFile = TRUE;
  8162. break;
  8163. }
  8164. else
  8165. {
  8166. isEmptyFile = FALSE;
  8167. break;
  8168. }
  8169. }
  8170. }
  8171. else
  8172. isEmptyFile = TRUE;
  8173. fclose(fptr1);
  8174. if(isEmptyFile == TRUE)
  8175. {
  8176. memset(str, 0, ARRAY_SIZE(str));
  8177. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8178. system(str);
  8179. }
  8180. }
  8181. }// End of while(int k=0; k < ChargePointCount; k++)
  8182. }
  8183. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8184. {
  8185. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8186. for(int k=0; k < ChargeProfileCount; k++)
  8187. {
  8188. fptr1 = fopen(chargingProfiles[k], "r");
  8189. fptr2 = fopen(temp, "w+");
  8190. //Check Charging Profile Count
  8191. while(fscanf(fptr1, "%s", word) != EOF)
  8192. {
  8193. //DEBUG_INFO("word=%s\n",word);
  8194. if(strstr(word, "chargingProfileId")!= NULL)
  8195. {
  8196. n_chargingProfile = n_chargingProfile + 1;
  8197. }
  8198. }
  8199. rewind(fptr1);
  8200. //search Charging Profile Element
  8201. //int i= 0;
  8202. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8203. {
  8204. json_object *tmpProfilee;
  8205. tmpProfilee = json_tokener_parse(sLineWord);
  8206. if(!is_error(tmpProfilee))
  8207. {
  8208. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8209. {
  8210. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8211. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8212. }
  8213. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8214. {
  8215. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8216. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8217. }
  8218. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8219. {
  8220. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8221. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8222. }
  8223. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8224. {
  8225. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8226. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8227. }
  8228. }
  8229. json_object_put(tmpProfilee);
  8230. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8231. {
  8232. //------- not write to fptr2-------//
  8233. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8234. //clearflag = TRUE;
  8235. }
  8236. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8237. {
  8238. //------- not write to fptr2-------//
  8239. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8240. }
  8241. else if(stackLevelIsNULL == TRUE)
  8242. {
  8243. //Clear Whole File
  8244. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8245. clearflag = TRUE;
  8246. break;
  8247. }
  8248. else
  8249. {
  8250. fprintf(fptr2, sLineWord);//writing data into file
  8251. }
  8252. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8253. }
  8254. if(clearflag == TRUE)
  8255. {
  8256. fclose(fptr1);
  8257. fclose(fptr2);
  8258. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8259. system(str);
  8260. // clear temp file
  8261. sprintf(str,"rm -f %s",temp);
  8262. system(str);
  8263. }
  8264. else
  8265. {
  8266. fclose(fptr1);
  8267. fclose(fptr2);
  8268. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8269. system(str);
  8270. resultRename = rename(temp, chargingProfiles[k]);
  8271. if(resultRename == 0)
  8272. {
  8273. DEBUG_INFO("File ChargingProfile renamed successfully");
  8274. }
  8275. else
  8276. {
  8277. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8278. }
  8279. if(comfirmstr[0]== 0)
  8280. {
  8281. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8282. }
  8283. //Check chargingProfile is empty file
  8284. /*------ Read the file ----------------*/
  8285. fptr1=fopen(chargingProfiles[k],"r");
  8286. ch=fgetc(fptr1);
  8287. rewind(fptr1);
  8288. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8289. if(ch!=EOF)
  8290. {
  8291. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8292. {
  8293. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8294. if(sLineWord[0]=='\0')
  8295. {
  8296. isEmptyFile = TRUE;
  8297. break;
  8298. }
  8299. else
  8300. {
  8301. isEmptyFile = FALSE;
  8302. break;
  8303. }
  8304. }
  8305. }
  8306. else
  8307. isEmptyFile = TRUE;
  8308. fclose(fptr1);
  8309. if(isEmptyFile == TRUE)
  8310. {
  8311. memset(str, 0, ARRAY_SIZE(str));
  8312. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8313. system(str);
  8314. }
  8315. /*------- End of reading ---------------*/
  8316. }
  8317. } // while(int k=0; k < ChargeProfileCount; k++)
  8318. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8319. end:
  8320. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8321. {
  8322. if(connectorIdInt == 0)
  8323. {
  8324. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8325. {
  8326. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8327. }
  8328. }
  8329. else
  8330. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8331. }
  8332. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8333. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8334. return result;
  8335. }
  8336. void createFirmwareVersionByDataTransfer(void)
  8337. {
  8338. json_object *FirmwareDataTransfer = json_object_new_object();
  8339. // AC & DC model
  8340. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8341. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8342. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8343. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8344. // DC model
  8345. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8346. {
  8347. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8348. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8349. (gunType[3] != GUN_TYPE_UNKNOWN))
  8350. {
  8351. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8352. }
  8353. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8354. {
  8355. // DS DM DW
  8356. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8357. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8358. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8359. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8360. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8361. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8362. }
  8363. else
  8364. {
  8365. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8366. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8367. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8368. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8369. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8370. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8371. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8372. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8373. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8374. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8375. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8376. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8377. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8378. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8379. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8380. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8381. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8382. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8383. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8384. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8385. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8386. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8387. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8388. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8389. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8390. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8391. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8392. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8393. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8394. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8395. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8396. }
  8397. }
  8398. // 4G model
  8399. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8400. {
  8401. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8402. }
  8403. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8404. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8405. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8406. json_object_put(FirmwareDataTransfer);
  8407. }
  8408. int handleDataTransferRequest(char *uuid, char *payload)
  8409. {
  8410. mtrace();
  8411. json_object *response = json_object_new_object();
  8412. int result = FAIL;
  8413. char tempvendorId[255]={0};
  8414. char tempmessageId[50]={0};
  8415. char tempdata[512]={0};
  8416. char message[2048]={0};
  8417. DEBUG_INFO("handleDataTransferRequest...\n");
  8418. if((uuid != NULL) && (payload != NULL))
  8419. {
  8420. json_object *DataTransfer;
  8421. DataTransfer = json_tokener_parse(payload);
  8422. if(!is_error(DataTransfer))
  8423. {
  8424. // Required data
  8425. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8426. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8427. // Optional data
  8428. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8429. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8430. if(json_object_object_get(DataTransfer, "data") != NULL)
  8431. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8432. result = PASS;
  8433. }
  8434. json_object_put(DataTransfer);
  8435. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8436. {
  8437. // Send all moudle firmware version on EVSE
  8438. createFirmwareVersionByDataTransfer();
  8439. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8440. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8441. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8442. json_object_put(response);
  8443. }
  8444. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8445. {
  8446. system("/usr/bin/run_tmate_restart.sh &");
  8447. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8448. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8449. json_object_put(response);
  8450. }
  8451. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8452. {
  8453. json_object *data;
  8454. data = json_tokener_parse(tempdata);
  8455. if(!is_error(data))
  8456. {
  8457. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8458. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8459. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8460. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8461. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8462. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8463. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8464. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8465. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8466. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8467. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8468. }
  8469. else
  8470. {
  8471. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8472. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8473. }
  8474. json_object_put(data);
  8475. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8476. json_object_put(response);
  8477. }
  8478. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8479. {
  8480. json_object *data;
  8481. data = json_tokener_parse(tempdata);
  8482. if(!is_error(data))
  8483. {
  8484. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8485. if(json_object_object_get(data, "idToken") != NULL)
  8486. {
  8487. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8488. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8489. }
  8490. if(json_object_object_get(data, "price") != NULL)
  8491. {
  8492. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8493. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8494. }
  8495. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8496. }
  8497. else
  8498. {
  8499. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8500. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8501. }
  8502. json_object_put(data);
  8503. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8504. json_object_put(response);
  8505. }
  8506. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8507. {
  8508. json_object *data;
  8509. data = json_tokener_parse(tempdata);
  8510. if(!is_error(data))
  8511. {
  8512. if(json_object_object_get(data, "txId") != NULL)
  8513. {
  8514. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8515. for(int idx = 0;idx<gunTotalNumber;idx++)
  8516. {
  8517. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8518. {
  8519. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8520. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8521. if(json_object_object_get(data, "description") != NULL)
  8522. {
  8523. // California pricing V1.0
  8524. DEBUG_INFO("California pricing V1.0\n");
  8525. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8526. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8527. }
  8528. else
  8529. {
  8530. // California pricing V1.1
  8531. DEBUG_INFO("California pricing V1.1\n");
  8532. if(json_object_object_get(data, "timestamp") != NULL)
  8533. {
  8534. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8535. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8536. }
  8537. if(json_object_object_get(data, "meterValue") != NULL)
  8538. {
  8539. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8540. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8541. }
  8542. if(json_object_object_get(data, "cost") != NULL)
  8543. {
  8544. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8545. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8546. }
  8547. if(json_object_object_get(data, "state") != NULL)
  8548. {
  8549. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8550. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8551. }
  8552. if(json_object_object_get(data, "chargingPrice") != NULL)
  8553. {
  8554. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8555. {
  8556. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8557. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8558. }
  8559. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8560. {
  8561. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8562. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8563. }
  8564. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8565. {
  8566. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8567. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8568. }
  8569. }
  8570. if(json_object_object_get(data, "idlePrice") != NULL)
  8571. {
  8572. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8573. {
  8574. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8575. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8576. }
  8577. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8578. {
  8579. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8580. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8581. }
  8582. }
  8583. if(json_object_object_get(data, "nextPeriod") != NULL)
  8584. {
  8585. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8586. {
  8587. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8588. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8589. }
  8590. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8591. {
  8592. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8593. {
  8594. 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")));
  8595. 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"));
  8596. }
  8597. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8598. {
  8599. 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")));
  8600. 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"));
  8601. }
  8602. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8603. {
  8604. 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")));
  8605. 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"));
  8606. }
  8607. }
  8608. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8609. {
  8610. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8611. {
  8612. 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")));
  8613. 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"));
  8614. }
  8615. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8616. {
  8617. 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")));
  8618. 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"));
  8619. }
  8620. }
  8621. }
  8622. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8623. {
  8624. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8625. {
  8626. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8627. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8628. }
  8629. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8630. {
  8631. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8632. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8633. }
  8634. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8635. {
  8636. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8637. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8638. }
  8639. }
  8640. }
  8641. }
  8642. }
  8643. }
  8644. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8645. }
  8646. else
  8647. {
  8648. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8649. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8650. }
  8651. json_object_put(data);
  8652. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8653. json_object_put(response);
  8654. }
  8655. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8656. {
  8657. json_object *data;
  8658. data = json_tokener_parse(tempdata);
  8659. if(!is_error(data))
  8660. {
  8661. if(json_object_object_get(data, "txId") != NULL)
  8662. {
  8663. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8664. for(int idx = 0;idx<gunTotalNumber;idx++)
  8665. {
  8666. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8667. {
  8668. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8669. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8670. if(json_object_object_get(data, "description") != NULL)
  8671. {
  8672. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8673. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8674. }
  8675. }
  8676. }
  8677. }
  8678. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8679. }
  8680. else
  8681. {
  8682. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8683. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8684. }
  8685. json_object_put(data);
  8686. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8687. json_object_put(response);
  8688. }
  8689. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8690. {
  8691. json_object *data;
  8692. data = json_tokener_parse(tempdata);
  8693. if(!is_error(data))
  8694. {
  8695. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8696. if(json_object_object_get(data, "Content_Type") != NULL)
  8697. {
  8698. 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))
  8699. {
  8700. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8701. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8702. {
  8703. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8704. }
  8705. }
  8706. else
  8707. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8708. }
  8709. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8710. }
  8711. else
  8712. {
  8713. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8714. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8715. }
  8716. json_object_put(data);
  8717. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8718. json_object_put(response);
  8719. }
  8720. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8721. {
  8722. json_object *data;
  8723. data = json_tokener_parse(tempdata);
  8724. if(!is_error(data))
  8725. {
  8726. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8727. if(json_object_object_get(data, "Page_Index") != NULL)
  8728. {
  8729. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8730. }
  8731. if(json_object_object_get(data, "Duration") != NULL)
  8732. {
  8733. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8734. }
  8735. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8736. }
  8737. else
  8738. {
  8739. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8740. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8741. }
  8742. json_object_put(data);
  8743. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8744. json_object_put(response);
  8745. }
  8746. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8747. {
  8748. json_object *data;
  8749. data = json_tokener_parse(tempdata);
  8750. if(!is_error(data))
  8751. {
  8752. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8753. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8754. {
  8755. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8756. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8757. else
  8758. {
  8759. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8760. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8761. }
  8762. }
  8763. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8764. {
  8765. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8766. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8767. else
  8768. {
  8769. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8770. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8771. }
  8772. }
  8773. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8774. {
  8775. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8776. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8777. else
  8778. {
  8779. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8780. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8781. }
  8782. }
  8783. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8784. {
  8785. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8786. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8787. else
  8788. {
  8789. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8790. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8791. }
  8792. }
  8793. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8794. {
  8795. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8796. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8797. else
  8798. {
  8799. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8800. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8801. }
  8802. }
  8803. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8804. {
  8805. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8806. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8807. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8808. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8809. else
  8810. {
  8811. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8812. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8813. }
  8814. }
  8815. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8816. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8817. }
  8818. else
  8819. {
  8820. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8821. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8822. }
  8823. json_object_put(data);
  8824. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8825. json_object_put(response);
  8826. }
  8827. else
  8828. {
  8829. // Can not find valid message id
  8830. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8831. }
  8832. }
  8833. else
  8834. {
  8835. // Payload is null
  8836. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8837. }
  8838. LWS_Send(message);
  8839. return result;
  8840. }
  8841. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8842. {
  8843. mtrace();
  8844. int result = FAIL;
  8845. int connectorIdInt, durationInt;
  8846. char chargingRateUnitStr[4]={0};
  8847. char comfirmstr[20];
  8848. int confirmPeriods = 0;
  8849. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8850. json_object *GetCompositeSchedule;
  8851. GetCompositeSchedule = json_tokener_parse(payload);
  8852. if(!is_error(GetCompositeSchedule))
  8853. {
  8854. // Required data
  8855. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8856. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8857. else
  8858. connectorIdInt = -1;
  8859. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8860. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8861. else
  8862. durationInt = 86400;
  8863. // Optional data
  8864. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8865. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8866. }
  8867. json_object_put(GetCompositeSchedule);
  8868. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8869. if((connectorIdInt == 0) ||
  8870. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8871. {
  8872. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8873. struct StructChargingProfile tmpProfile[1];
  8874. if(strstr(chargingRateUnitStr, "W") != NULL)
  8875. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8876. else
  8877. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8878. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8879. {
  8880. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8881. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8882. }
  8883. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8884. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8885. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8886. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8887. {
  8888. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8889. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8890. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8891. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8892. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8893. {
  8894. confirmPeriods = idx;
  8895. break;
  8896. }
  8897. }
  8898. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8899. {
  8900. confirmPeriods += 1;
  8901. }
  8902. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8903. }
  8904. else
  8905. {
  8906. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8907. }
  8908. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8909. return result;
  8910. }
  8911. int handleGetConfigurationRequest(char *uuid, char *payload)
  8912. {
  8913. mtrace();
  8914. int result = FAIL;
  8915. int MaxKeySupported = 0;
  8916. int n_keys = 0;
  8917. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8918. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8919. json_object *GetConfiguration;
  8920. GetConfiguration = json_tokener_parse(payload);
  8921. if(!is_error(GetConfiguration))
  8922. {
  8923. // Optional data
  8924. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8925. {
  8926. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8927. {
  8928. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8929. n_keys = idx + 1;
  8930. }
  8931. }
  8932. }
  8933. json_object_put(GetConfiguration);
  8934. UnknownKeynum = 0;
  8935. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8936. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8937. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8938. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8939. if(n_keys != 0)
  8940. {
  8941. for(int i=0;i<n_keys;i++)
  8942. {
  8943. getKeyValue(requestKey[i]);
  8944. }
  8945. }
  8946. else
  8947. {
  8948. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8949. getKeyValue("");
  8950. }
  8951. processUnkownKey();
  8952. sendGetConfigurationConfirmation(uuid);
  8953. return result;
  8954. }
  8955. static char fnamePlusPath[100]={0};
  8956. static char fnamePWithNoPath[60]={0};
  8957. void checkUploadLog(void)
  8958. {
  8959. FILE *fp;
  8960. /* Open the command for reading. */
  8961. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8962. if (fp == NULL) {
  8963. DEBUG_WARN("Failed to run command\n" );
  8964. exit(1);
  8965. }
  8966. int ftppathlen = 0;
  8967. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8968. int i = 0;
  8969. /* Read the output a line at a time - output it. */
  8970. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8971. if(i==0)
  8972. {
  8973. ftppathlen = strlen(fnamePlusPath);
  8974. DEBUG_INFO("%s\n", fnamePlusPath);
  8975. fnamePlusPath[ftppathlen]='\0';
  8976. break;
  8977. }
  8978. i= i+1;
  8979. }
  8980. /* close */
  8981. pclose(fp);
  8982. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8983. {
  8984. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8985. {
  8986. fnamePlusPath[k]='\0';
  8987. }
  8988. }
  8989. i=1;
  8990. //char fname[60]={0};
  8991. while(i < ftppathlen)
  8992. {
  8993. int len=ftppathlen-i;
  8994. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8995. {
  8996. DEBUG_INFO("compare '/' all right\n");
  8997. break;
  8998. }
  8999. i=i+1;
  9000. }
  9001. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9002. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9003. fnamePWithNoPath[i+1] = '\0';
  9004. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9005. {
  9006. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9007. {
  9008. fnamePWithNoPath[j]='\0';
  9009. }
  9010. }
  9011. FILE* fp1 = fopen(fnamePlusPath, "r");
  9012. if (fp1)
  9013. {
  9014. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9015. // file exists
  9016. fclose(fp1);
  9017. }
  9018. else
  9019. {
  9020. // file doesn't exist
  9021. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9022. }
  9023. }
  9024. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9025. {
  9026. mtrace();
  9027. int result = FAIL;
  9028. time_t CurrentTime;
  9029. struct tm *tm;
  9030. pthread_t th_Status;
  9031. CurrentTime = time(NULL);
  9032. tm = localtime(&CurrentTime);
  9033. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9034. 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);
  9035. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9036. if(!interLock.isGetDiagnosticGoing)
  9037. {
  9038. interLock.isGetDiagnosticGoing = 1;
  9039. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9040. }
  9041. else
  9042. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9043. return result;
  9044. }
  9045. void* GetDiagnosticsProcess(void* data)
  9046. {
  9047. pthread_detach(pthread_self());
  9048. mtrace();
  9049. int retriesInt=0, retryIntervalInt=0;
  9050. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9051. 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};
  9052. int port=0;
  9053. int isSuccess = FALSE;
  9054. char cmdBuf[2048];
  9055. struct tm *tmNow;
  9056. time_t CurrentTime;
  9057. struct tm tmStart;
  9058. struct tm tmStop;
  9059. CurrentTime = time(NULL);
  9060. tmNow=localtime(&CurrentTime);
  9061. uint16_t targetYear, targetMonth;
  9062. json_object *GetDiagnostics;
  9063. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9064. GetDiagnostics = json_tokener_parse(data);
  9065. if(!is_error(GetDiagnostics))
  9066. {
  9067. // Required data
  9068. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9069. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9070. // Optional data
  9071. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9072. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9073. else
  9074. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9075. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9076. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9077. else
  9078. retryIntervalInt = 30;
  9079. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9080. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9081. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9082. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9083. }
  9084. json_object_put(GetDiagnostics);
  9085. // Pack log to compress file
  9086. 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) &&
  9087. (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))
  9088. {
  9089. // Pack system log
  9090. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9091. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9092. targetYear = tmStart.tm_year;
  9093. targetMonth = tmStart.tm_mon;
  9094. do
  9095. {
  9096. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9097. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9098. if(targetMonth+1>=13)
  9099. {
  9100. targetYear += 1;
  9101. targetMonth = 1;
  9102. }
  9103. else
  9104. {
  9105. targetMonth += 1;
  9106. }
  9107. }while((targetYear < (tmNow->tm_year+1900)) ||
  9108. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9109. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9110. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9111. system(cmdBuf);
  9112. // Pack charging & event log
  9113. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9114. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9115. targetYear = tmStart.tm_year;
  9116. targetMonth = tmStart.tm_mon;
  9117. do
  9118. {
  9119. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9120. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9121. if(targetMonth+1>=13)
  9122. {
  9123. targetYear += 1;
  9124. targetMonth = 1;
  9125. }
  9126. else
  9127. {
  9128. targetMonth += 1;
  9129. }
  9130. }while((targetYear < (tmNow->tm_year+1900)) ||
  9131. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9132. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9133. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9134. system(cmdBuf);
  9135. // Combine log file
  9136. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9137. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9138. }
  9139. else
  9140. {
  9141. system("exec /root/logPackTools 'log' 6");
  9142. }
  9143. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9144. system(cmdBuf);
  9145. checkUploadLog();
  9146. //****************location*******************/
  9147. if(strcmp(locationstr,"")==0)
  9148. {
  9149. DEBUG_INFO("location is <Empty>!\n");
  9150. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9151. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9152. goto end;
  9153. }
  9154. memset(protocol, 0, ARRAY_SIZE(protocol));
  9155. memset(user, 0, ARRAY_SIZE(user) );
  9156. memset(password, 0, ARRAY_SIZE(password));
  9157. memset(host, 0, ARRAY_SIZE(host));
  9158. memset(path, 0, ARRAY_SIZE(path));
  9159. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9160. memset(host1, 0, ARRAY_SIZE(host1));
  9161. memset(path1, 0, ARRAY_SIZE(path1));
  9162. /*location: ftp://user:password@host:port/path*/
  9163. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9164. if((access(fnamePlusPath,F_OK))!=-1)
  9165. {
  9166. DEBUG_INFO("fnamePlusPath exist.\n");
  9167. }
  9168. else
  9169. {
  9170. DEBUG_INFO("fnamePlusPath not exist!\n");
  9171. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9172. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9173. goto end;
  9174. }
  9175. if(strchr(locationstr,'@')==NULL)
  9176. {
  9177. sscanf(locationstr,
  9178. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9179. protocol, host, &port, path);
  9180. strcpy(user,"anonymous");
  9181. strcpy(password,"");
  9182. }
  9183. else
  9184. {
  9185. //DEBUG_INFO("pch=%s\n", pch);
  9186. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9187. protocol, user, password, host, &port, path);
  9188. }
  9189. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9190. {
  9191. DEBUG_INFO("protocol is not ftp/http ! \n");
  9192. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9193. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9194. goto end;
  9195. }
  9196. if(strncmp(locationstr,"http", 4) == 0)
  9197. {
  9198. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9199. sprintf(ftppath,"/%s", path);
  9200. do
  9201. {
  9202. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9203. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9204. sleep(3);
  9205. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9206. if(!isSuccess)
  9207. {
  9208. DEBUG_INFO("Diagnostics fail.\n");
  9209. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9210. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9211. sleep(retryIntervalInt);
  9212. }
  9213. else
  9214. {
  9215. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9216. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9217. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9218. }
  9219. retriesInt--;
  9220. }while((isSuccess == 0)&&(retriesInt >= 0));
  9221. }
  9222. else
  9223. {
  9224. sscanf(host,"%[^/]%s",host1, path1);
  9225. if(strlen(path) > 0)
  9226. sprintf(ftppath,"/%s", path);
  9227. else
  9228. sprintf(ftppath,"/%s", path1);
  9229. int ftppathlen=strlen(ftppath);
  9230. int i=1;
  9231. char filenametemp[50];
  9232. while(i < ftppathlen)
  9233. {
  9234. int len=ftppathlen-i;
  9235. if(ftppath[len]== 47) // '/' ascll code: 47
  9236. {
  9237. DEBUG_INFO("find '/' all right\n");
  9238. break;
  9239. }
  9240. i=i+1;
  9241. }
  9242. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9243. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9244. filenametemp[i+1] = 0;
  9245. if(port == 0)
  9246. port = 21;
  9247. do
  9248. {
  9249. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9250. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9251. sleep(3);
  9252. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9253. if(!isSuccess)
  9254. {
  9255. DEBUG_INFO("Diagnostics fail.\n");
  9256. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9257. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9258. sleep(retryIntervalInt);
  9259. }
  9260. else
  9261. {
  9262. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9263. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9264. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9265. }
  9266. retriesInt--;
  9267. }while((!isSuccess)&&(retriesInt >= 0));
  9268. }
  9269. end:
  9270. system("rm -f /mnt/*");
  9271. sleep(5);
  9272. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9273. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9274. interLock.isGetDiagnosticGoing = 0;
  9275. pthread_exit(NULL);
  9276. }
  9277. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9278. {
  9279. mtrace();
  9280. int result = FAIL;
  9281. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9282. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9283. {
  9284. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9285. locallistVersion = -1;
  9286. }
  9287. else
  9288. {
  9289. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9290. OCPP_getListVerion();
  9291. }
  9292. //from db.OCPP_getListVerion
  9293. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9294. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9295. sendGetLocalListVersionConfirmation(uuid,"");
  9296. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9297. return result;
  9298. }
  9299. int handleRemoteStartRequest(char *uuid, char *payload)
  9300. {
  9301. mtrace();
  9302. int result = FAIL;
  9303. int connectorIdInt=-1;
  9304. int tempIndex = 0;
  9305. int connectorIdIsNULL, chargingProfileIsNULL;
  9306. char comfirmstr[20]={0};
  9307. char cmdBuf[512];
  9308. json_object *RemoteStartTransaction;
  9309. FILE *fp;
  9310. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9311. if(server_pending == TRUE)
  9312. {
  9313. return 0;
  9314. }
  9315. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9316. RemoteStartTransaction = json_tokener_parse(payload);
  9317. if(!is_error(RemoteStartTransaction))
  9318. {
  9319. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9320. {
  9321. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9322. }
  9323. else
  9324. {
  9325. connectorIdIsNULL = TRUE;
  9326. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9327. {
  9328. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9329. {
  9330. connectorIdIsNULL = FALSE;
  9331. connectorIdInt = (gun_index+1);
  9332. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9333. break;
  9334. }
  9335. }
  9336. }
  9337. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9338. {
  9339. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9340. // Required data
  9341. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9342. // Optional data
  9343. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9344. {
  9345. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9346. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9347. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9348. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9349. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9350. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9351. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9352. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9353. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9354. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9355. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9356. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9357. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9358. {
  9359. 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")));
  9360. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9361. 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"));
  9362. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9363. 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"));
  9364. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9365. 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")));
  9366. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9367. {
  9368. 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++)
  9369. {
  9370. 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"));
  9371. 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"));
  9372. 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)
  9373. 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"));
  9374. }
  9375. }
  9376. }
  9377. }
  9378. else
  9379. {
  9380. chargingProfileIsNULL = TRUE;
  9381. }
  9382. }
  9383. }
  9384. else
  9385. {
  9386. connectorIdIsNULL = TRUE;
  9387. }
  9388. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9389. {
  9390. DEBUG_WARN("Connector id is NULL\n.");
  9391. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9392. goto end;
  9393. }
  9394. /*
  9395. enum _SYSTEM_STATUS
  9396. {
  9397. S_BOOTING = 0,
  9398. S_IDLE, = 1
  9399. S_AUTHORIZING, = 2
  9400. S_REASSIGN_CHECK, = 3
  9401. S_REASSIGN, = 4
  9402. S_PRECHARGE, = 5
  9403. S_PREPARING_FOR_EV, = 6
  9404. S_PREPARING_FOR_EVSE, = 7
  9405. S_CHARGING, = 8
  9406. S_TERMINATING, = 9
  9407. S_COMPLETE, = 10
  9408. S_ALARM, = 11
  9409. S_FAULT = 12
  9410. }
  9411. */
  9412. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9413. {
  9414. //check Transaction active
  9415. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9416. {
  9417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9418. {
  9419. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9420. }
  9421. else
  9422. {
  9423. tempIndex = connectorIdInt -1;
  9424. }
  9425. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9426. {
  9427. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9428. {
  9429. 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))
  9430. {
  9431. //Reserved
  9432. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9433. }
  9434. 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))
  9435. {
  9436. //Reserved
  9437. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9438. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9439. goto end;
  9440. }
  9441. else
  9442. {
  9443. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9444. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9445. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9446. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9447. {
  9448. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9449. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9450. goto end;
  9451. }
  9452. }//END FOR ELSE
  9453. }
  9454. }// END FOR CHAdeMO_QUANTITY
  9455. }
  9456. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9457. {
  9458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9459. {
  9460. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9461. }
  9462. else
  9463. {
  9464. tempIndex = connectorIdInt -1;
  9465. }
  9466. for (int index = 0; index < CCS_QUANTITY; index++)
  9467. {
  9468. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9469. {
  9470. 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))
  9471. {
  9472. //Reserved
  9473. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9474. }
  9475. 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))
  9476. {
  9477. //Reserved
  9478. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9480. goto end;
  9481. }
  9482. else
  9483. {
  9484. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9485. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9486. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9487. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9488. {
  9489. DEBUG_WARN("CCS connector not allow start\n.");
  9490. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9491. goto end;
  9492. }
  9493. }// END FOR ELSE
  9494. }
  9495. }// END FOR CCS_QUANTITY
  9496. }
  9497. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9498. {
  9499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9500. {
  9501. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9502. }
  9503. else
  9504. {
  9505. tempIndex = connectorIdInt -1;
  9506. }
  9507. for (int index = 0; index < GB_QUANTITY; index++)
  9508. {
  9509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9510. {
  9511. 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))
  9512. {
  9513. //Reserved
  9514. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9515. }
  9516. 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))
  9517. {
  9518. //Reserved
  9519. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9520. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9521. goto end;
  9522. }
  9523. else
  9524. {
  9525. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9526. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9527. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9528. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9529. {
  9530. DEBUG_WARN("GB connector not allow start\n.");
  9531. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9532. goto end;
  9533. }
  9534. }// END FOR ELSE
  9535. }
  9536. } // END FOR GB_QUANTITY
  9537. }
  9538. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9539. {
  9540. tempIndex = connectorIdInt -1;
  9541. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9542. {
  9543. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9544. {
  9545. 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))
  9546. {
  9547. //Reserved
  9548. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9549. }
  9550. 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))
  9551. {
  9552. //Reserved
  9553. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9554. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9555. goto end;
  9556. }
  9557. else
  9558. {
  9559. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9560. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9561. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9562. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9563. {
  9564. DEBUG_WARN("GB connector not allow start\n.");
  9565. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9566. goto end;
  9567. }
  9568. }// END FOR ELSE
  9569. }
  9570. } // END FOR GB_QUANTITY
  9571. }
  9572. else
  9573. {
  9574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9575. {
  9576. tempIndex = 2;
  9577. }
  9578. else
  9579. {
  9580. tempIndex = connectorIdInt -1;
  9581. }
  9582. for (int index = 0; index < AC_QUANTITY; index++)
  9583. {
  9584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9585. {
  9586. 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))
  9587. {
  9588. //Reserved
  9589. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9590. }
  9591. 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))
  9592. {
  9593. //Reserved
  9594. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9595. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9596. goto end;
  9597. }
  9598. else
  9599. {
  9600. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9601. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9602. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9603. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9604. {
  9605. DEBUG_WARN("AC connector not allow start\n.");
  9606. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9607. goto end;
  9608. }
  9609. }//END FOR ELSE
  9610. }
  9611. }// END FOR AC_QUANTITY
  9612. }
  9613. if(chargingProfileIsNULL == FALSE)
  9614. {
  9615. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9616. {
  9617. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9618. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9619. //memset idTag
  9620. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9621. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9622. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9623. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9624. // Save profile to file
  9625. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9626. system(cmdBuf);
  9627. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9628. fp = fopen(cmdBuf, "w");
  9629. 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));
  9630. fclose(fp);
  9631. }
  9632. else
  9633. {
  9634. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9635. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9636. }
  9637. }
  9638. else
  9639. {
  9640. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9641. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9642. //memset idTag
  9643. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9644. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9645. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9646. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9647. }
  9648. }
  9649. else
  9650. {
  9651. DEBUG_WARN("Connector id over\n.");
  9652. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9653. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9654. }
  9655. end:
  9656. json_object_put(RemoteStartTransaction);
  9657. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9658. {
  9659. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9660. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9661. }
  9662. //OCPP send RemoteStartConfirmation by first.
  9663. sendRemoteStartConfirmation(uuid, comfirmstr);
  9664. return result;
  9665. }
  9666. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9667. {
  9668. mtrace();
  9669. int result = FAIL;
  9670. int match = FALSE;
  9671. int GunNO = 0;
  9672. int tempIndex = 0;
  9673. int transactionIdInt=0;
  9674. int transactionIdIsNULL= TRUE;
  9675. char comfirmstr[20];
  9676. json_object *RemoteStopTransaction;
  9677. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9678. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9679. if(server_pending == TRUE)
  9680. {
  9681. return 0;
  9682. }
  9683. RemoteStopTransaction = json_tokener_parse(payload);
  9684. if(!is_error(RemoteStopTransaction))
  9685. {
  9686. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9687. {
  9688. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9689. transactionIdIsNULL = FALSE;
  9690. }
  9691. }
  9692. json_object_put(RemoteStopTransaction);
  9693. if(transactionIdIsNULL == FALSE)
  9694. {
  9695. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9696. {
  9697. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9698. {
  9699. //check Transaction active
  9700. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9701. {
  9702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9703. {
  9704. tempIndex = ((gun_index==2) ? 1: 0);
  9705. }
  9706. else
  9707. {
  9708. tempIndex = gun_index;
  9709. }
  9710. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9711. {
  9712. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9713. {
  9714. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9715. {
  9716. match = TRUE;
  9717. GunNO = gun_index;
  9718. }
  9719. }
  9720. }// END FOR CHAdeMO_QUANTITY
  9721. }
  9722. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9723. {
  9724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9725. {
  9726. tempIndex = ((gun_index==2) ? 1: 0);
  9727. }
  9728. else
  9729. {
  9730. tempIndex = gun_index;
  9731. }
  9732. for (int index = 0; index < CCS_QUANTITY; index++)
  9733. {
  9734. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9735. {
  9736. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9737. {
  9738. match = TRUE;
  9739. GunNO = gun_index;
  9740. }
  9741. }
  9742. }// END FOR CCS_QUANTITY
  9743. }
  9744. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9745. {
  9746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9747. {
  9748. tempIndex = ((gun_index==2) ? 1: 0);
  9749. }
  9750. else
  9751. {
  9752. tempIndex = gun_index;
  9753. }
  9754. for (int index = 0; index < GB_QUANTITY; index++)
  9755. {
  9756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9757. {
  9758. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9759. {
  9760. match = TRUE;
  9761. GunNO = gun_index;
  9762. }
  9763. }
  9764. }// END FOR GB_QUANTITY
  9765. }
  9766. else if(gunType[gun_index] == GUN_TYPE_DO)
  9767. {
  9768. tempIndex = gun_index;
  9769. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9770. {
  9771. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9772. {
  9773. 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
  9774. {
  9775. match = TRUE;
  9776. GunNO = gun_index;
  9777. }
  9778. }
  9779. }// END FOR GB_QUANTITY
  9780. }
  9781. else
  9782. {
  9783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9784. {
  9785. tempIndex = 2;
  9786. }
  9787. else
  9788. {
  9789. tempIndex = gun_index;
  9790. }
  9791. for (int index = 0; index < AC_QUANTITY; index++)
  9792. {
  9793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9794. {
  9795. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9796. {
  9797. match = TRUE;
  9798. GunNO = gun_index;
  9799. }
  9800. }
  9801. }// END FOR CHAdeMO_QUANTITY
  9802. } // END FOR AC ELSE
  9803. }// CHECK IF ResponseTransactionId == transactionIdInt
  9804. }//END FOR
  9805. if( match == TRUE)
  9806. {
  9807. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9808. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9809. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9810. }
  9811. else
  9812. {
  9813. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9814. }
  9815. }
  9816. else
  9817. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9818. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9819. return result;
  9820. }
  9821. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9822. {
  9823. mtrace();
  9824. int result = FAIL;
  9825. int connectorIdInt=0, reservationIdInt=0;
  9826. int tempIndex = 0;
  9827. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9828. char comfirmstr[20]={0};
  9829. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9830. int c = 0;
  9831. char *loc;
  9832. //char *ptr;
  9833. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9834. strcpy(sstrtemp, stringtrimspace(payload));
  9835. //***(1)connectorId ****/
  9836. c=0;
  9837. loc = strstr(sstrtemp, "connectorId");
  9838. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9839. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9840. {
  9841. sstr[c] = loc[strlen("connectorId")+2+c];
  9842. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9843. c++;
  9844. }
  9845. sstr[c] = '\0';
  9846. connectorIdInt = atoi(sstr);
  9847. //***(2)expiryDate ****/
  9848. loc = strstr(sstrtemp, "expiryDate");
  9849. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9850. c = 0;
  9851. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9852. {
  9853. sstr[c] = loc[3+strlen("expiryDate")+c];
  9854. c++;
  9855. }
  9856. sstr[c] = '\0';
  9857. strcpy(expiryDatestr, sstr);
  9858. //***(3)idTag ****/
  9859. loc = strstr(sstrtemp, "idTag");
  9860. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9861. c = 0;
  9862. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9863. {
  9864. sstr[c] = loc[3+strlen("idTag")+c];
  9865. c++;
  9866. }
  9867. sstr[c] = '\0';
  9868. strcpy(idTagstr, sstr);
  9869. //***(4)parentIdTag ****/
  9870. loc = strstr(sstrtemp, "parentIdTag");
  9871. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9872. c = 0;
  9873. if(loc == NULL)
  9874. {
  9875. strcpy(parentIdTagstr, "");
  9876. }
  9877. else
  9878. {
  9879. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9880. {
  9881. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9882. c++;
  9883. }
  9884. sstr[c] = '\0';
  9885. strcpy(parentIdTagstr, sstr);
  9886. }
  9887. //***(5)reservationId ****/
  9888. c=0;
  9889. loc = strstr(sstrtemp, "reservationId");
  9890. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9891. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9892. {
  9893. sstr[c] = loc[strlen("reservationId")+2+c];
  9894. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9895. c++;
  9896. }
  9897. sstr[c] = '\0';
  9898. reservationIdInt = atoi(sstr);
  9899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9900. /*
  9901. enum SYSTEM_STATUS
  9902. {
  9903. SYS_MODE_BOOTING = 0,
  9904. SYS_MODE_IDLE = 1,
  9905. SYS_MODE_AUTHORIZING = 2,
  9906. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9907. SYS_MODE_REASSIGN = 4,
  9908. SYS_MODE_PREPARING = 5,
  9909. SYS_MODE_PREPARE_FOR_EV = 6,
  9910. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9911. SYS_MODE_CHARGING = 8,
  9912. SYS_MODE_TERMINATING = 9,
  9913. SYS_MODE_COMPLETE = 10,
  9914. SYS_MODE_ALARM = 11,
  9915. SYS_MODE_FAULT = 12,
  9916. SYS_MODE_RESERVATION = 13,
  9917. SYS_MODE_BOOKING = 14,
  9918. SYS_MODE_MAINTAIN = 15,
  9919. SYS_MODE_DEBUG = 16,
  9920. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9921. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9922. SYS_MODE_UPDATE = 19
  9923. };
  9924. */
  9925. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9926. {
  9927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9928. goto end;
  9929. }
  9930. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9931. {
  9932. //check Transaction active
  9933. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9934. {
  9935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9936. {
  9937. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9938. }
  9939. else
  9940. {
  9941. tempIndex = connectorIdInt -1;
  9942. }
  9943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9944. {
  9945. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9946. {
  9947. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9948. {
  9949. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9950. {
  9951. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9952. {
  9953. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9955. }
  9956. 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'))
  9957. {
  9958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9959. }
  9960. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9961. {
  9962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9963. }
  9964. else
  9965. {
  9966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9967. }
  9968. }
  9969. 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
  9970. {
  9971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9972. }
  9973. }
  9974. else
  9975. {
  9976. //replace reservation
  9977. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9979. }
  9980. }
  9981. } // END FOR CHAdeMO_QUANTITY
  9982. }
  9983. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9984. {
  9985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9986. {
  9987. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9988. }
  9989. else
  9990. {
  9991. tempIndex = connectorIdInt -1;
  9992. }
  9993. for (int index = 0; index < CCS_QUANTITY; index++)
  9994. {
  9995. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9996. {
  9997. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9998. {
  9999. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10000. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10001. {
  10002. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10003. {
  10004. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10006. }
  10007. 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'))
  10008. {
  10009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10010. }
  10011. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10012. {
  10013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10014. }
  10015. else
  10016. {
  10017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10018. }
  10019. }
  10020. 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
  10021. {
  10022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10023. }
  10024. }
  10025. else
  10026. {
  10027. //replace reservation
  10028. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10030. }
  10031. }
  10032. } // END FOR CCS_QUANTITY
  10033. }
  10034. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10035. {
  10036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10037. {
  10038. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10039. }
  10040. else
  10041. {
  10042. tempIndex = connectorIdInt -1;
  10043. }
  10044. for (int index = 0; index < GB_QUANTITY; index++)
  10045. {
  10046. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10047. {
  10048. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10049. {
  10050. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10051. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10052. {
  10053. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10054. {
  10055. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10057. }
  10058. 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'))
  10059. {
  10060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10061. }
  10062. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10063. {
  10064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10065. }
  10066. else
  10067. {
  10068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10069. }
  10070. }
  10071. 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
  10072. {
  10073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10074. }
  10075. }
  10076. else
  10077. {
  10078. //replace reservation
  10079. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10081. }
  10082. }
  10083. }// END FOR GB_QUANTITY
  10084. }
  10085. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10086. {
  10087. tempIndex = connectorIdInt -1;
  10088. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10089. {
  10090. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10091. {
  10092. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10093. {
  10094. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10095. 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
  10096. {
  10097. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10098. {
  10099. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10101. }
  10102. 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'))
  10103. {
  10104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10105. }
  10106. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10107. {
  10108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10109. }
  10110. else
  10111. {
  10112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10113. }
  10114. }
  10115. 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
  10116. {
  10117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10118. }
  10119. }
  10120. else
  10121. {
  10122. //replace reservation
  10123. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10125. }
  10126. }
  10127. }// END FOR GB_QUANTITY
  10128. }
  10129. else
  10130. {
  10131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10132. {
  10133. tempIndex = 2;
  10134. }
  10135. else
  10136. {
  10137. tempIndex = (connectorIdInt -1);
  10138. }
  10139. for (int index = 0; index < AC_QUANTITY; index++)
  10140. {
  10141. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10142. {
  10143. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10144. {
  10145. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10146. {
  10147. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10148. {
  10149. 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))
  10150. {
  10151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10152. }
  10153. else
  10154. {
  10155. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10157. }
  10158. }
  10159. 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'))
  10160. {
  10161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10162. }
  10163. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10164. {
  10165. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10166. }
  10167. else
  10168. {
  10169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10170. }
  10171. }
  10172. 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
  10173. {
  10174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10175. }
  10176. }
  10177. else
  10178. {
  10179. //replace reservation
  10180. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10182. }
  10183. }
  10184. } // END FOR AC_QUANTITY
  10185. }
  10186. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10187. }
  10188. else if(connectorIdInt == 0)
  10189. {
  10190. //check Transaction active
  10191. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10192. {
  10193. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10194. {
  10195. 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'))
  10196. {
  10197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10198. goto end;
  10199. }
  10200. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10201. {
  10202. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10203. goto end;
  10204. }
  10205. 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
  10206. {
  10207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10208. goto end;
  10209. }
  10210. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10211. {
  10212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10213. goto end;
  10214. }
  10215. }
  10216. }// END FOR CHAdeMO_QUANTITY
  10217. for (int index = 0; index < CCS_QUANTITY; index++)
  10218. {
  10219. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10220. {
  10221. 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'))
  10222. {
  10223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10224. goto end;
  10225. }
  10226. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10227. {
  10228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10229. goto end;
  10230. }
  10231. 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
  10232. {
  10233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10234. goto end;
  10235. }
  10236. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10237. {
  10238. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10239. goto end;
  10240. }
  10241. }
  10242. } // END FOR CCS_QUANTITY
  10243. for (int index = 0; index < GB_QUANTITY; index++)
  10244. {
  10245. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10246. {
  10247. 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'))
  10248. {
  10249. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10250. goto end;
  10251. }
  10252. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10253. {
  10254. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10255. goto end;
  10256. }
  10257. 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
  10258. {
  10259. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10260. goto end;
  10261. }
  10262. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10263. {
  10264. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10265. goto end;
  10266. }
  10267. }
  10268. } // END FOR GB_QUANTITY
  10269. for (int index = 0; index < AC_QUANTITY; index++)
  10270. {
  10271. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10272. {
  10273. 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'))
  10274. {
  10275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10276. goto end;
  10277. }
  10278. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10279. {
  10280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10281. goto end;
  10282. }
  10283. 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
  10284. {
  10285. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10286. goto end;
  10287. }
  10288. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10289. {
  10290. 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))
  10291. {
  10292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10293. goto end;
  10294. }
  10295. }
  10296. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10297. {
  10298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10299. goto end;
  10300. }
  10301. }
  10302. }// END FOR AC_QUANTITY
  10303. //The connectorId is 0
  10304. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10305. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10306. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10307. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10308. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10309. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10310. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10311. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10312. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10313. result = TRUE;
  10314. return result;
  10315. }
  10316. else
  10317. {
  10318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10319. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10320. }
  10321. if(strcmp(comfirmstr,"Accepted") == 0)
  10322. {
  10323. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10324. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10325. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10326. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10327. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10328. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10329. result = TRUE;
  10330. return result;
  10331. }
  10332. end:
  10333. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10334. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10335. return result;
  10336. }
  10337. int handleResetRequest(char *uuid, char *payload)
  10338. {
  10339. mtrace();
  10340. int result = FAIL;
  10341. char sstr[10]={0},sstrtemp[30]={ 0 };
  10342. char typestr[10]={0};
  10343. char comfirmstr[20]={0};
  10344. int c = 0;
  10345. char *loc;
  10346. DEBUG_INFO("handleResetRequest...\n");
  10347. strcpy(sstrtemp, stringtrimspace(payload));
  10348. loc = strstr(sstrtemp, "type");
  10349. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10350. c = 0;
  10351. while (loc[3+strlen("type")+c] != '\"')
  10352. {
  10353. sstr[c] = loc[3+strlen("type")+c];
  10354. c++;
  10355. }
  10356. sstr[c] = '\0';
  10357. strcpy(typestr,sstr);
  10358. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10359. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10360. {
  10361. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10362. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10363. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10364. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10365. }
  10366. else
  10367. {
  10368. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10369. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10370. result = PASS;
  10371. }
  10372. sendResetConfirmation(uuid, comfirmstr);
  10373. return result;
  10374. }
  10375. int handleSendLocalListRequest(char *uuid, char *payload)
  10376. {
  10377. mtrace();
  10378. int result = FAIL;
  10379. char comfirmstr[20];
  10380. int checkState_Faulted = FALSE;
  10381. json_object *SendLocalList;
  10382. DEBUG_INFO("handleSendLocalListRequest...\n");
  10383. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10384. {
  10385. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10386. goto end;
  10387. }
  10388. //check Charge Point state
  10389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10390. {
  10391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10392. {
  10393. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10394. }
  10395. }
  10396. for (int index = 0; index < CCS_QUANTITY; index++)
  10397. {
  10398. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10399. {
  10400. checkState_Faulted = TRUE; //OCPP Status
  10401. }
  10402. }
  10403. for (int index = 0; index < GB_QUANTITY; index++)
  10404. {
  10405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10406. {
  10407. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10408. }
  10409. }
  10410. //check Charge Point state
  10411. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10412. {
  10413. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10414. {
  10415. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10416. }
  10417. }
  10418. //check Charge Point state
  10419. for (int index = 0; index < AC_QUANTITY; index++)
  10420. {
  10421. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10422. {
  10423. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10424. }
  10425. }
  10426. if(checkState_Faulted == TRUE)
  10427. {
  10428. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10429. goto end;
  10430. }
  10431. // Parsing payload
  10432. SendLocalList = json_tokener_parse(payload);
  10433. if(!is_error(SendLocalList))
  10434. {
  10435. // Required data
  10436. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10437. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10438. // Optional data
  10439. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10440. {
  10441. //Check UpdateType
  10442. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10443. {
  10444. //Local list full update
  10445. DEBUG_INFO("Local list full update.\n");
  10446. OCPP_getListVerion();
  10447. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10448. {
  10449. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10450. goto end;
  10451. }
  10452. OCPP_cleanLocalList();
  10453. }
  10454. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10455. {
  10456. //Local list different update
  10457. DEBUG_INFO("Local list different update.\n");
  10458. OCPP_getListVerion();
  10459. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10460. {
  10461. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10462. goto end;
  10463. }
  10464. }
  10465. else
  10466. {
  10467. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10468. goto end;
  10469. }
  10470. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10471. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10472. {
  10473. 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")));
  10474. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10475. {
  10476. 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")));
  10477. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10478. 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")));
  10479. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10480. 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")));
  10481. }
  10482. // Add to db
  10483. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10484. {
  10485. //Local list full update
  10486. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10487. idx,
  10488. ShmOCPP16Data->SendLocalList.ListVersion,
  10489. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10490. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10491. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10492. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10493. // update list
  10494. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10495. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10496. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10497. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10498. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10499. }
  10500. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10501. {
  10502. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10503. idx,
  10504. ShmOCPP16Data->SendLocalList.ListVersion,
  10505. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10506. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10507. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10508. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10509. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10510. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10511. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10512. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10513. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10514. }
  10515. }
  10516. }
  10517. else
  10518. {
  10519. //Check UpdateType
  10520. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10521. {
  10522. //Local list full update
  10523. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10524. OCPP_cleanLocalList();
  10525. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10526. goto end;
  10527. }
  10528. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10529. {
  10530. //Local list different update
  10531. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10532. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10533. goto end;
  10534. }
  10535. }
  10536. result = PASS;
  10537. }
  10538. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10539. end:
  10540. json_object_put(SendLocalList);
  10541. sendSendLocalListConfirmation(uuid, comfirmstr);
  10542. return result;
  10543. }
  10544. #define MAX 200
  10545. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10546. {
  10547. mtrace();
  10548. int result = FAIL;
  10549. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10550. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10551. char chargingProfilePurposeStr[30]={0};
  10552. char chargingProfileKindStr[16]={0};
  10553. char recurrencyKindStr[10]={0};
  10554. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10555. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10556. int chargingSchedulePeriodCount = 0;
  10557. char comfirmstr[20]={0};
  10558. int meet= FALSE;
  10559. FILE *fptr1;
  10560. char filename[MAX]={0};
  10561. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10562. char rmFileCmd[50]={0};
  10563. char tempchargingProfilePurposeStr[30]={0};
  10564. char word[1600]={0};
  10565. int n_chargingProfile = 0;
  10566. json_object *SetChargingProfile;
  10567. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10568. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10569. SetChargingProfile = json_tokener_parse(payload);
  10570. if(!is_error(SetChargingProfile))
  10571. {
  10572. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10573. {
  10574. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10575. if(connectorIdInt == 0)
  10576. {
  10577. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10578. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10579. }
  10580. else
  10581. {
  10582. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10583. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10584. }
  10585. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10586. }
  10587. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10588. {
  10589. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10590. {
  10591. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10592. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10593. {
  10594. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10595. }
  10596. else
  10597. {
  10598. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10599. }
  10600. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10601. }
  10602. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10603. {
  10604. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10605. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10606. {
  10607. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10608. }
  10609. else
  10610. {
  10611. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10612. }
  10613. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10614. }
  10615. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10616. {
  10617. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10618. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10619. {
  10620. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10621. }
  10622. else
  10623. {
  10624. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10625. }
  10626. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10627. }
  10628. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10629. {
  10630. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10631. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10632. {
  10633. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10634. }
  10635. else
  10636. {
  10637. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10638. }
  10639. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10640. }
  10641. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10642. {
  10643. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10644. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10645. {
  10646. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10647. }
  10648. else
  10649. {
  10650. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10651. }
  10652. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10653. }
  10654. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10655. {
  10656. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10657. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10658. {
  10659. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10660. }
  10661. else
  10662. {
  10663. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10664. }
  10665. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10666. }
  10667. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10668. {
  10669. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10670. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10671. {
  10672. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10673. }
  10674. else
  10675. {
  10676. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10677. }
  10678. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10679. }
  10680. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10681. {
  10682. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10683. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10684. {
  10685. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10686. }
  10687. else
  10688. {
  10689. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10690. }
  10691. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10692. }
  10693. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10694. {
  10695. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10696. {
  10697. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10698. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10699. {
  10700. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10701. }
  10702. else
  10703. {
  10704. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10705. }
  10706. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10707. }
  10708. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10709. {
  10710. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10711. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10712. {
  10713. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10714. }
  10715. else
  10716. {
  10717. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10718. }
  10719. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10720. }
  10721. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10722. {
  10723. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10724. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10725. {
  10726. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10727. }
  10728. else
  10729. {
  10730. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10731. }
  10732. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10733. }
  10734. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10735. {
  10736. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10737. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10738. {
  10739. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10740. }
  10741. else
  10742. {
  10743. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10744. }
  10745. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10746. }
  10747. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10748. {
  10749. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10750. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10751. if(chargingSchedulePeriodCount <= 10)
  10752. {
  10753. 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++)
  10754. {
  10755. 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)
  10756. {
  10757. startPeriodInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10758. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10759. {
  10760. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10761. }
  10762. else
  10763. {
  10764. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10765. }
  10766. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10767. }
  10768. 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)
  10769. {
  10770. limitflaot[idxPeriod] = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10771. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10772. {
  10773. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10774. }
  10775. else
  10776. {
  10777. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10778. }
  10779. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10780. }
  10781. 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)
  10782. {
  10783. numberPhasesInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10784. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10785. {
  10786. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10787. }
  10788. else
  10789. {
  10790. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10791. }
  10792. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10793. }
  10794. }
  10795. }
  10796. }
  10797. }
  10798. }
  10799. }
  10800. json_object_put(SetChargingProfile);
  10801. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10802. {
  10803. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10804. goto end;
  10805. }
  10806. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10807. {
  10808. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10809. if(connectorIdInt != 0)
  10810. {
  10811. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10812. goto end;
  10813. }
  10814. strcpy(filename, ChargePointMaxProfile_JSON );
  10815. fptr1 = fopen(filename, "r");
  10816. if (!fptr1)
  10817. {
  10818. //file not exist
  10819. DEBUG_INFO("Unable to open the input file!!\n");
  10820. fptr1 = fopen(filename, "w+");
  10821. }
  10822. else
  10823. {
  10824. //Check Charging Profile Count
  10825. while(fscanf(fptr1, "%s", word) != EOF)
  10826. {
  10827. //DEBUG_INFO("word=%s\n",word);
  10828. if(strstr(word, "chargingProfileId")!= NULL)
  10829. {
  10830. //DEBUG_INFO("test chargingProfileId \n");
  10831. n_chargingProfile = n_chargingProfile + 1;
  10832. //DEBUG_INFO("chargingProfileId Found\n");
  10833. }
  10834. }
  10835. }
  10836. fclose(fptr1);
  10837. }
  10838. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10839. {
  10840. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10841. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10842. {
  10843. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10844. goto end;
  10845. }
  10846. memset(filename, 0, ARRAY_SIZE(filename));
  10847. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10848. fptr1 = fopen(filename, "r");
  10849. if (!fptr1)
  10850. {
  10851. //file not exist
  10852. //DEBUG_INFO("Unable to open the input file!!\n");
  10853. fptr1 = fopen(filename, "w+");
  10854. }
  10855. else
  10856. {
  10857. //Check Charging Profile Count
  10858. while(fscanf(fptr1, "%s", word) != EOF)
  10859. {
  10860. //DEBUG_INFO("word=%s\n",word);
  10861. if(strstr(word, "chargingProfileId")!= NULL)
  10862. {
  10863. //DEBUG_INFO("test chargingProfileId \n");
  10864. n_chargingProfile = n_chargingProfile + 1;
  10865. //DEBUG_INFO("chargingProfileId Found\n");
  10866. }
  10867. }
  10868. }
  10869. fclose(fptr1);
  10870. }
  10871. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10872. {
  10873. //printf("set chargingProfile 1-4\n");
  10874. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10875. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10876. if(connectorIdInt == 0)
  10877. {
  10878. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10879. goto end;
  10880. }
  10881. int tempIndex = 0;
  10882. //check Transaction active
  10883. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10884. {
  10885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10886. {
  10887. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10888. }
  10889. else
  10890. {
  10891. tempIndex = connectorIdInt -1;
  10892. }
  10893. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10894. {
  10895. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10896. {
  10897. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10898. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10899. {
  10900. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10901. {
  10902. meet = TRUE;
  10903. break;
  10904. }
  10905. }
  10906. }
  10907. }
  10908. }
  10909. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10910. {
  10911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10912. {
  10913. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10914. }
  10915. else
  10916. {
  10917. tempIndex = connectorIdInt -1;
  10918. }
  10919. for (int index = 0; index < CCS_QUANTITY; index++)
  10920. {
  10921. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10922. {
  10923. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10924. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10925. {
  10926. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10927. {
  10928. meet = TRUE;
  10929. break;
  10930. }
  10931. }
  10932. }
  10933. }
  10934. }
  10935. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10936. {
  10937. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10938. {
  10939. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10940. }
  10941. else
  10942. {
  10943. tempIndex = connectorIdInt -1;
  10944. }
  10945. for (int index = 0; index < GB_QUANTITY; index++)
  10946. {
  10947. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10948. {
  10949. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10950. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10951. {
  10952. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10953. {
  10954. meet = TRUE;
  10955. break;
  10956. }
  10957. }
  10958. }
  10959. }
  10960. }
  10961. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10962. {
  10963. tempIndex = connectorIdInt -1;
  10964. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10965. {
  10966. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10967. {
  10968. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10969. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10970. {
  10971. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10972. {
  10973. meet = TRUE;
  10974. break;
  10975. }
  10976. }
  10977. }
  10978. }
  10979. }
  10980. else
  10981. {
  10982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10983. {
  10984. tempIndex = 2;
  10985. }
  10986. else
  10987. {
  10988. tempIndex = (connectorIdInt -1);
  10989. }
  10990. for (int index = 0; index < AC_QUANTITY; index++)
  10991. {
  10992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10993. {
  10994. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10995. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10996. {
  10997. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10998. {
  10999. meet = TRUE;
  11000. break;
  11001. }
  11002. }
  11003. }
  11004. }
  11005. }
  11006. //check Transaction active
  11007. if(meet == FALSE)
  11008. {
  11009. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11010. goto end;
  11011. }
  11012. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  11013. {
  11014. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11015. goto end;
  11016. }
  11017. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11018. fptr1 = fopen(filename, "r");
  11019. if (!fptr1)
  11020. {
  11021. //file not exist
  11022. DEBUG_INFO("Unable to open the input file!!\n");
  11023. fptr1 = fopen(filename, "w+");
  11024. }
  11025. else
  11026. {
  11027. //Check Charging Profile Count
  11028. while(fscanf(fptr1, "%s", word) != EOF)
  11029. {
  11030. //DEBUG_INFO("word=%s\n",word);
  11031. if(strstr(word, "chargingProfileId")!= NULL)
  11032. {
  11033. //DEBUG_INFO("test chargingProfileId \n");
  11034. n_chargingProfile = n_chargingProfile + 1;
  11035. //DEBUG_INFO("chargingProfileId Found\n");
  11036. }
  11037. }
  11038. }
  11039. fclose(fptr1);
  11040. }
  11041. // Check ChargeProfileMaxStackLevel
  11042. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11043. {
  11044. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11045. goto end;
  11046. }
  11047. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11048. {
  11049. int i = 0;
  11050. char fnametemp[200]={0};
  11051. n_chargingProfile = 0;
  11052. //Check ChargePointMaxProfile.json exit
  11053. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11054. {
  11055. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11056. //Check Charging Profile Count
  11057. while(fscanf(fptr1, "%s", word) != EOF)
  11058. {
  11059. //DEBUG_INFO("word=%s\n",word);
  11060. if(strstr(word, "chargingProfileId")!= NULL)
  11061. {
  11062. //DEBUG_INFO("test chargingProfileId \n");
  11063. n_chargingProfile = n_chargingProfile + 1;
  11064. i = i + 1;
  11065. //DEBUG_INFO("chargingProfileId Found\n");
  11066. }
  11067. memset(word, 0, ARRAY_SIZE(word));
  11068. }
  11069. fclose(fptr1);
  11070. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  11071. }
  11072. //Check TxDefaultProfile_0.json exit
  11073. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  11074. {
  11075. i = 0;
  11076. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  11077. //Check Charging Profile Count
  11078. while(fscanf(fptr1, "%s", word) != EOF)
  11079. {
  11080. //DEBUG_INFO("word=%s\n",word);
  11081. if(strstr(word, "chargingProfileId")!= NULL)
  11082. {
  11083. //DEBUG_INFO("test chargingProfileId \n");
  11084. n_chargingProfile = n_chargingProfile + 1;
  11085. i = i + 1;
  11086. //DEBUG_INFO("chargingProfileId Found\n");
  11087. }
  11088. memset(word, 0, ARRAY_SIZE(word));
  11089. }
  11090. fclose(fptr1);
  11091. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  11092. }
  11093. //Check TxDefaultProfile_%d.json
  11094. for(int j=1; j <= gunTotalNumber; j++)
  11095. {
  11096. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11097. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  11098. if((access(fnametemp,F_OK))!=-1)
  11099. {
  11100. i = 0;
  11101. fptr1 = fopen(fnametemp, "r");
  11102. //Check Charging Profile Count
  11103. while(fscanf(fptr1, "%s", word) != EOF)
  11104. {
  11105. //DEBUG_INFO("word=%s\n",word);
  11106. if(strstr(word, "chargingProfileId")!= NULL)
  11107. {
  11108. //DEBUG_INFO("test chargingProfileId \n");
  11109. n_chargingProfile = n_chargingProfile + 1;
  11110. i = i + 1;
  11111. //DEBUG_INFO("chargingProfileId Found\n");
  11112. }
  11113. memset(word, 0, ARRAY_SIZE(word));
  11114. }
  11115. fclose(fptr1);
  11116. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11117. }
  11118. }
  11119. //Check TxProfile_%d.json
  11120. for(int j=1; j <= gunTotalNumber; j++)
  11121. {
  11122. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11123. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  11124. if((access(fnametemp,F_OK))!=-1)
  11125. {
  11126. i = 0;
  11127. fptr1 = fopen(fnametemp, "r");
  11128. //Check Charging Profile Count
  11129. while(fscanf(fptr1, "%s", word) != EOF)
  11130. {
  11131. //DEBUG_INFO("word=%s\n",word);
  11132. if(strstr(word, "chargingProfileId")!= NULL)
  11133. {
  11134. //DEBUG_INFO("test chargingProfileId \n");
  11135. n_chargingProfile = n_chargingProfile + 1;
  11136. i = i + 1;
  11137. //DEBUG_INFO("chargingProfileId Found\n");
  11138. }
  11139. memset(word, 0, ARRAY_SIZE(word));
  11140. }
  11141. fclose(fptr1);
  11142. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11143. }
  11144. }
  11145. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11146. {
  11147. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11148. goto end;
  11149. }
  11150. }
  11151. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11152. //**********************************Write to File********************************************************/
  11153. FILE *infile;
  11154. FILE *outfile;
  11155. infile = fopen (filename, "r");
  11156. outfile = fopen (tempfile, "w");
  11157. int d =0;
  11158. d = fgetc(infile);
  11159. rewind(infile);
  11160. if(d == EOF)
  11161. {
  11162. // Profile is empty
  11163. fprintf(outfile,"%s\n",payload);
  11164. fclose(infile);
  11165. fclose(outfile);
  11166. sprintf(rmFileCmd,"rm -f %s",filename);
  11167. system(rmFileCmd);
  11168. rename(tempfile, filename);
  11169. }
  11170. else
  11171. {
  11172. // Profile is not empty
  11173. char buf[2048]={0};
  11174. int ChargingProfileAdded = FALSE;
  11175. while (fgets(buf, sizeof(buf), infile) != NULL)
  11176. {
  11177. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  11178. json_object *tmpChargingProfile;
  11179. tmpChargingProfile = json_tokener_parse(buf);
  11180. if(!is_error(SetChargingProfile))
  11181. {
  11182. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  11183. {
  11184. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  11185. }
  11186. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11187. {
  11188. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11189. {
  11190. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11191. }
  11192. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11193. {
  11194. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  11195. }
  11196. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11197. {
  11198. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11199. }
  11200. }
  11201. }
  11202. json_object_put(tmpChargingProfile);
  11203. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  11204. {
  11205. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11206. {
  11207. //DEBUG_INFO("update set chargingProfile to file -0\n");
  11208. if(ChargingProfileAdded == FALSE)
  11209. {
  11210. fprintf(outfile,"%s\n",payload);
  11211. ChargingProfileAdded = TRUE;
  11212. }
  11213. }
  11214. else
  11215. {
  11216. if(tempstackLevelInt < stackLevelInt)
  11217. {
  11218. if(ChargingProfileAdded == FALSE)
  11219. {
  11220. fprintf(outfile,"%s\n",buf);
  11221. fprintf(outfile,"%s\n",payload);
  11222. ChargingProfileAdded = TRUE;
  11223. }
  11224. else
  11225. {
  11226. fprintf(outfile,"%s\n",buf);
  11227. }
  11228. }
  11229. else
  11230. {
  11231. if(ChargingProfileAdded == FALSE)
  11232. {
  11233. fprintf(outfile,"%s\n",buf);
  11234. fprintf(outfile,"%s\n",payload);
  11235. ChargingProfileAdded = TRUE;
  11236. }
  11237. else
  11238. {
  11239. fprintf(outfile,"%s\n",buf);
  11240. }
  11241. }
  11242. }
  11243. }
  11244. else
  11245. {
  11246. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11247. {
  11248. if(ChargingProfileAdded == FALSE)
  11249. {
  11250. fprintf(outfile,"%s\n",buf);
  11251. fprintf(outfile,"%s\n",payload);
  11252. ChargingProfileAdded = TRUE;
  11253. }
  11254. else
  11255. {
  11256. fprintf(outfile,"%s\n",buf);
  11257. }
  11258. }
  11259. else if(tempstackLevelInt < stackLevelInt)
  11260. {
  11261. if(ChargingProfileAdded == FALSE)
  11262. {
  11263. fprintf(outfile,"%s\n",buf);
  11264. fprintf(outfile,"%s\n",payload);
  11265. ChargingProfileAdded = TRUE;
  11266. }
  11267. else
  11268. {
  11269. fprintf(outfile,"%s\n",buf);
  11270. }
  11271. }
  11272. else
  11273. {
  11274. if(ChargingProfileAdded == FALSE)
  11275. {
  11276. fprintf(outfile,"%s\n",buf);
  11277. fprintf(outfile,"%s\n",payload);
  11278. ChargingProfileAdded = TRUE;
  11279. }
  11280. else
  11281. {
  11282. fprintf(outfile,"%s\n",buf);
  11283. }
  11284. }
  11285. }
  11286. } // end of while loop
  11287. fclose(infile);
  11288. fclose(outfile);
  11289. sprintf(rmFileCmd,"rm -f %s",filename);
  11290. system(rmFileCmd);
  11291. rename(tempfile, filename);
  11292. }
  11293. sleep(1);
  11294. result = TRUE;
  11295. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11296. end:
  11297. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11298. {
  11299. if(connectorIdInt == 0)
  11300. {
  11301. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11302. {
  11303. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11304. }
  11305. }
  11306. else
  11307. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11308. }
  11309. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11310. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11311. return result;
  11312. }
  11313. int handleTriggerMessageRequest(char *uuid, char *payload)
  11314. {
  11315. mtrace();
  11316. int result = FAIL;
  11317. int connectorIdIsNULL = FALSE;
  11318. int connectorIdInt =0;
  11319. char sstr[40]={0},sstrtemp[100]={ 0 };
  11320. char requestedMessagestr[40]={0};
  11321. char comfirmstr[20]={0};
  11322. int c = 0;
  11323. char *loc;
  11324. DEBUG_INFO("handleTriggerMessageRequest\n");
  11325. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11326. strcpy(sstrtemp, stringtrimspace(payload));
  11327. c = 0;
  11328. loc = strstr(sstrtemp, "requestedMessage");
  11329. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11330. {
  11331. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11332. c++;
  11333. }
  11334. sstr[c] = '\0';
  11335. strcpy(requestedMessagestr, sstr);
  11336. c = 0;
  11337. loc = strstr(sstrtemp, "connectorId");
  11338. if(loc == NULL)
  11339. {
  11340. connectorIdIsNULL = TRUE;
  11341. }
  11342. else
  11343. {
  11344. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11345. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11346. {
  11347. sstr[c] = loc[strlen("connectorId")+2+c];
  11348. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11349. c++;
  11350. }
  11351. sstr[c] = '\0';
  11352. connectorIdInt = atoi(sstr);
  11353. }
  11354. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11355. {
  11356. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11357. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11358. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11359. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11360. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11361. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11362. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11363. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11364. {
  11365. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11366. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11367. return TRUE;
  11368. }
  11369. else
  11370. {
  11371. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11372. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11373. }
  11374. }
  11375. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11376. {
  11377. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11378. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11379. return TRUE;
  11380. }
  11381. //==========================
  11382. // Trigger message
  11383. //==========================
  11384. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11385. {
  11386. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11387. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11388. {
  11389. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11390. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11391. }
  11392. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11393. }
  11394. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11395. {
  11396. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11397. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11398. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11399. }
  11400. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11401. {
  11402. //sendBootNotificationRequest();
  11403. server_sign = FALSE;
  11404. }
  11405. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11406. {
  11407. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11408. }
  11409. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11410. {
  11411. if(connectorIdIsNULL == FALSE)
  11412. {
  11413. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11414. {
  11415. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11416. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11417. }
  11418. }
  11419. else
  11420. {
  11421. for(int idx=0;idx< gunTotalNumber;idx++)
  11422. {
  11423. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11424. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11425. }
  11426. }
  11427. }
  11428. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11429. {
  11430. if(connectorIdIsNULL == FALSE)
  11431. {
  11432. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11433. {
  11434. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11435. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11436. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11437. }
  11438. }
  11439. else
  11440. {
  11441. for(int idx=0;idx< gunTotalNumber;idx++)
  11442. {
  11443. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11444. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11445. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11446. }
  11447. }
  11448. }
  11449. return result;
  11450. }
  11451. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11452. {
  11453. mtrace();
  11454. int result = FAIL;
  11455. int connectorIdInt =0;
  11456. char comfirmstr[20]={0};
  11457. int tempIndex = 0;
  11458. json_object *UnlockConnector;
  11459. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11460. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11461. UnlockConnector = json_tokener_parse(payload);
  11462. if(!is_error(UnlockConnector))
  11463. {
  11464. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11465. {
  11466. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11467. }
  11468. }
  11469. json_object_put(UnlockConnector);
  11470. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11471. if(gunTotalNumber == 0)
  11472. {
  11473. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11474. goto end;
  11475. }
  11476. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11477. {
  11478. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11479. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11480. goto end;
  11481. }
  11482. else
  11483. {
  11484. //check Transaction active
  11485. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11486. {
  11487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11488. {
  11489. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11490. }
  11491. else
  11492. {
  11493. tempIndex = connectorIdInt -1;
  11494. }
  11495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11496. {
  11497. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11498. {
  11499. //stop Transaction
  11500. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11501. }
  11502. }
  11503. }
  11504. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11505. {
  11506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11507. {
  11508. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11509. }
  11510. else
  11511. {
  11512. tempIndex = connectorIdInt -1;
  11513. }
  11514. for (int index = 0; index < CCS_QUANTITY; index++)
  11515. {
  11516. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11517. {
  11518. //stop Transaction
  11519. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11520. }
  11521. }
  11522. }
  11523. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11524. {
  11525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11526. {
  11527. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11528. }
  11529. else
  11530. {
  11531. tempIndex = connectorIdInt -1;
  11532. }
  11533. for (int index = 0; index < GB_QUANTITY; index++)
  11534. {
  11535. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11536. {
  11537. //stop Transaction
  11538. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11539. }
  11540. }
  11541. }
  11542. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11543. {
  11544. tempIndex = connectorIdInt -1;
  11545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11546. {
  11547. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  11548. {
  11549. //stop Transaction
  11550. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11551. }
  11552. }
  11553. }
  11554. else
  11555. {
  11556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11557. {
  11558. tempIndex = 2;
  11559. }
  11560. else
  11561. {
  11562. tempIndex = connectorIdInt-1;
  11563. }
  11564. for (int index = 0; index < AC_QUANTITY; index++)
  11565. {
  11566. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11567. {
  11568. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11569. }
  11570. }
  11571. }
  11572. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11573. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11574. result = TRUE;
  11575. return result;
  11576. }
  11577. end:
  11578. //json_object_put(obj); --- remove temporally
  11579. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11580. return result;
  11581. }
  11582. static char UpdateFirmwarepayloadData[300]={0};
  11583. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11584. {
  11585. mtrace();
  11586. int result = FAIL;
  11587. pthread_t t;
  11588. sendUpdateFirmwareConfirmation(uuid);
  11589. memset(UpdateFirmwarepayloadData, 0, 300);
  11590. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11591. if(!interLock.isUpdateFirmwareGoing)
  11592. {
  11593. interLock.isUpdateFirmwareGoing = 1;
  11594. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11595. }
  11596. else
  11597. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11598. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11599. return result;
  11600. }
  11601. void *UpdateFirmwareProcess(void *data)
  11602. {
  11603. pthread_detach(pthread_self());
  11604. mtrace();
  11605. int retriesInt =0, retryIntervalInt=0;
  11606. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11607. int port=0;
  11608. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11609. int isSuccess = 0;
  11610. char ftpbuf[1024];
  11611. char temp[1024];
  11612. char * pch;
  11613. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11614. json_object *UpdateFirmware;
  11615. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11616. if(!is_error(UpdateFirmware))
  11617. {
  11618. // Required data
  11619. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11620. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11621. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11622. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11623. // Optional data
  11624. if(json_object_object_get(UpdateFirmware, "retries"))
  11625. {
  11626. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11627. }
  11628. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11629. {
  11630. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11631. }
  11632. }
  11633. json_object_put(UpdateFirmware);
  11634. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11635. memset(path, 0, ARRAY_SIZE(path));
  11636. // Wait retrieveData
  11637. if(strlen(retrieveDatestr) > 10)
  11638. {
  11639. do
  11640. {
  11641. sleep(1);
  11642. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11643. }
  11644. // Ready to download
  11645. system("rm -f /mnt/*");
  11646. if(strncmp(locationstr,"http", 4) == 0)
  11647. {
  11648. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11649. sprintf(ftppath,"/%s", path);
  11650. DEBUG_INFO("locationstr: %s\n", locationstr);
  11651. DEBUG_INFO("protocol: %s\n",protocol);
  11652. DEBUG_INFO("host: %s\n",host);
  11653. DEBUG_INFO("path: %s\n",path);
  11654. DEBUG_INFO("ftppath: %s\n",ftppath);
  11655. int ftppathlen=strlen(ftppath);
  11656. int i=1;
  11657. char filenametemp[50];
  11658. while(i < ftppathlen)
  11659. {
  11660. int len=ftppathlen-i;
  11661. if(ftppath[len]== 47) // '/' ascll code: 47
  11662. {
  11663. DEBUG_INFO("compare '/' all right\n");
  11664. break;
  11665. }
  11666. i=i+1;
  11667. }
  11668. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11669. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11670. filenametemp[i+1] = 0;
  11671. do
  11672. {
  11673. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11674. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11675. sleep(1);
  11676. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11677. if(!isSuccess)
  11678. {
  11679. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11680. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11681. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11682. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11683. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11684. }
  11685. else
  11686. {
  11687. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11688. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11689. }
  11690. retriesInt--;
  11691. }while((isSuccess == 0)&&(retriesInt >= 0));
  11692. }
  11693. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11694. {
  11695. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11696. memset(temp, 0, ARRAY_SIZE(temp));
  11697. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11698. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11699. int ftppathlen=strlen(ftpbuf);
  11700. int i=1;
  11701. char filenametemp[50];
  11702. while(i < ftppathlen)
  11703. {
  11704. int len=ftppathlen-i;
  11705. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11706. {
  11707. DEBUG_INFO(" compare '/' all right\n");
  11708. break;
  11709. }
  11710. i=i+1;
  11711. }
  11712. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11713. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11714. filenametemp[i+1] = 0;
  11715. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11716. pch=strchr(temp,'@');
  11717. if(pch==NULL)
  11718. {
  11719. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11720. protocol, host, &port, path);
  11721. strcpy(user,"anonymous");
  11722. strcpy(password,"");
  11723. }
  11724. else
  11725. {
  11726. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11727. protocol, user, password, host, &port, path);
  11728. }
  11729. sscanf(host,"%[^/]%s",host1, path1);
  11730. sprintf(ftppath,"%s", path1);
  11731. //DEBUG_INFO("protocol =%s\n",protocol);
  11732. //DEBUG_INFO("user =%s\n",user);
  11733. //DEBUG_INFO("password =%s\n",password);
  11734. //DEBUG_INFO("host1 =%s\n",host1);
  11735. //DEBUG_INFO("port =%d\n",port);
  11736. //DEBUG_INFO("path1 =%s\n",path1);
  11737. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11738. //ftpFile(host, user, password, port, ftppath, fname);
  11739. //download firmware pthred
  11740. if(port == 0)
  11741. {
  11742. port = 21;
  11743. }
  11744. do
  11745. {
  11746. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11747. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11748. sleep(1);
  11749. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11750. if(!isSuccess)
  11751. {
  11752. //BulldogUtil.sleepMs(interval*1000);
  11753. DEBUG_INFO("Update firmware request and download file fail.\n");
  11754. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11755. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11756. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11757. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11758. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11759. }
  11760. else
  11761. {
  11762. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11763. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11764. }
  11765. retriesInt--;
  11766. }while((!isSuccess)&&(retriesInt >= 0));
  11767. }
  11768. else
  11769. {
  11770. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11771. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11772. sleep(1);
  11773. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11774. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11775. }
  11776. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11777. interLock.isUpdateFirmwareGoing = 0;
  11778. pthread_exit(NULL);
  11779. }
  11780. int handleCertificateSignedRequest(char *uuid, char *payload)
  11781. {
  11782. mtrace();
  11783. int result = PASS;
  11784. json_object *CertificateSigned;
  11785. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11786. CertificateSigned = json_tokener_parse(payload);
  11787. if(!is_error(CertificateSigned))
  11788. {
  11789. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11790. }
  11791. json_object_put(CertificateSigned);
  11792. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11793. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11794. fclose(fp);
  11795. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11796. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11797. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11798. sendCertificateSignedConfirmation(uuid);
  11799. return result;
  11800. }
  11801. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11802. {
  11803. mtrace();
  11804. int result = PASS;
  11805. json_object *DeleteCertificate;
  11806. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11807. DeleteCertificate = json_tokener_parse(payload);
  11808. if(!is_error(DeleteCertificate))
  11809. {
  11810. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11811. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11812. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11813. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11814. }
  11815. json_object_put(DeleteCertificate);
  11816. /*
  11817. * TODO: Delete certificateSigned process
  11818. */
  11819. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11820. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11821. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11822. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11823. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11824. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11825. sendDeleteCertificateConfirmation(uuid);
  11826. return result;
  11827. }
  11828. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11829. {
  11830. mtrace();
  11831. int result = PASS;
  11832. json_object *ExtendedTriggerMessage;
  11833. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11834. ExtendedTriggerMessage = json_tokener_parse(payload);
  11835. if(!is_error(ExtendedTriggerMessage))
  11836. {
  11837. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11838. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11839. {
  11840. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11841. }
  11842. else
  11843. {
  11844. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11845. }
  11846. }
  11847. json_object_put(ExtendedTriggerMessage);
  11848. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11849. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11850. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11851. {
  11852. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11853. }
  11854. else
  11855. {
  11856. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11857. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11858. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11859. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11860. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11861. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11862. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11863. {
  11864. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11865. }
  11866. else
  11867. {
  11868. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11869. }
  11870. }
  11871. sendExtendedTriggerMessageConfirmation(uuid);
  11872. //==========================
  11873. // Trigger message
  11874. //==========================
  11875. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11876. {
  11877. //sendBootNotificationRequest();
  11878. server_sign = FALSE;
  11879. }
  11880. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11881. {
  11882. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11883. }
  11884. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11885. {
  11886. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11887. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11888. {
  11889. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11890. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11891. }
  11892. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11893. }
  11894. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11895. {
  11896. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11897. }
  11898. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11899. {
  11900. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11901. {
  11902. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11903. }
  11904. else
  11905. {
  11906. for(int idx=0;idx< gunTotalNumber;idx++)
  11907. {
  11908. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11909. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11910. }
  11911. }
  11912. }
  11913. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11914. {
  11915. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11916. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11917. {
  11918. 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\" &");
  11919. }
  11920. }
  11921. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11922. {
  11923. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11924. {
  11925. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11926. }
  11927. else
  11928. {
  11929. for(int idx=0;idx< gunTotalNumber;idx++)
  11930. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11931. }
  11932. }
  11933. return result;
  11934. }
  11935. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11936. {
  11937. mtrace();
  11938. int result = PASS;
  11939. json_object *GetInstalledCertificateIds;
  11940. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11941. GetInstalledCertificateIds = json_tokener_parse(payload);
  11942. if(!is_error(GetInstalledCertificateIds))
  11943. {
  11944. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11945. }
  11946. json_object_put(GetInstalledCertificateIds);
  11947. /*
  11948. * TODO: Return installed certificate process
  11949. */
  11950. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11951. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11952. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11953. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11954. sendGetInstalledCertificateIdsConfirmation(uuid);
  11955. return result;
  11956. }
  11957. int handleGetLogRequest(char *uuid, char *payload)
  11958. {
  11959. mtrace();
  11960. int result = PASS;
  11961. json_object *GetLog;
  11962. DEBUG_INFO("handleGetLogRequest...\n");
  11963. GetLog = json_tokener_parse(payload);
  11964. if(!is_error(GetLog))
  11965. {
  11966. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11967. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11968. if(json_object_object_get(GetLog, "retries") != NULL)
  11969. {
  11970. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11971. }
  11972. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11973. {
  11974. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11975. }
  11976. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11977. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11978. {
  11979. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11980. }
  11981. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11982. {
  11983. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11984. }
  11985. }
  11986. json_object_put(GetLog);
  11987. /*
  11988. * TODO: Upload log process
  11989. */
  11990. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11991. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11992. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11993. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11994. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11995. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11996. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11997. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11998. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11999. sendGetLogConfirmation(uuid);
  12000. return result;
  12001. }
  12002. int handleInstallCertificateRequest(char *uuid, char *payload)
  12003. {
  12004. mtrace();
  12005. int result = PASS;
  12006. json_object *InstallCertificate;
  12007. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12008. InstallCertificate = json_tokener_parse(payload);
  12009. if(!is_error(InstallCertificate))
  12010. {
  12011. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12012. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12013. /*
  12014. * TODO: Install certificate process
  12015. */
  12016. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12017. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12018. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12019. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12020. sendInstallCertificateConfirmation(uuid);
  12021. }
  12022. json_object_put(InstallCertificate);
  12023. return result;
  12024. }
  12025. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12026. {
  12027. mtrace();
  12028. int result = PASS;
  12029. json_object *SignedUpdateFirmware;
  12030. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12031. SignedUpdateFirmware = json_tokener_parse(payload);
  12032. if(!is_error(SignedUpdateFirmware))
  12033. {
  12034. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12035. {
  12036. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12037. }
  12038. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12039. {
  12040. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12041. }
  12042. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12043. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12044. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12045. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12046. {
  12047. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12048. }
  12049. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12050. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12051. }
  12052. json_object_put(SignedUpdateFirmware);
  12053. /*
  12054. * TODO: Upgrade firmware process
  12055. */
  12056. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12057. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12058. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12059. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12060. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12061. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12062. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12063. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12064. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12065. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12066. sendInstallCertificateConfirmation(uuid);
  12067. return result;
  12068. }
  12069. int handleUnknownRequest(char *uuid, char *payload)
  12070. {
  12071. mtrace();
  12072. int result = PASS;
  12073. DEBUG_INFO("handleUnknownRequest...\n");
  12074. sendUnknownConfirmation(uuid);
  12075. result = PASS;
  12076. return result;
  12077. }
  12078. //==========================================
  12079. // Handle server response routine
  12080. //==========================================
  12081. void handleAuthorizeResponse(char *payload, int gun_index)
  12082. {
  12083. mtrace();
  12084. char expiryDatestr[30]={0};
  12085. char parentIdTagstr[20]={0};
  12086. char statusstr[20]={0};
  12087. int expiryDateISNULL=FALSE;
  12088. int parentIdTagISNULL=FALSE;
  12089. DEBUG_INFO("handleAuthorizeResponse...\n");
  12090. json_object *Authorize;
  12091. Authorize = json_tokener_parse(payload);
  12092. if(!is_error(Authorize))
  12093. {
  12094. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12095. {
  12096. // Required data
  12097. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12098. // Optional data
  12099. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12100. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12101. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12102. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12103. }
  12104. }
  12105. json_object_put(Authorize);
  12106. if(expiryDateISNULL == FALSE)
  12107. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12108. if(parentIdTagISNULL == FALSE)
  12109. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12110. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12111. //Update idTag information to authorization cache if supproted
  12112. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12113. {
  12114. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12115. }
  12116. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12117. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12118. authorizeRetryTimes = 0;
  12119. }
  12120. void handleBootNotificationResponse(char *payload, int gun_index)
  12121. {
  12122. mtrace();
  12123. char statusStr[12]={0};
  12124. char currentTimeStr[30]={0};
  12125. int intervalInt = 0;
  12126. DEBUG_INFO("handleBootNotificationResponse...\n");
  12127. json_object *BootNotification;
  12128. BootNotification = json_tokener_parse(payload);
  12129. if(!is_error(BootNotification))
  12130. {
  12131. // Required data
  12132. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12133. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12134. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12135. }
  12136. json_object_put(BootNotification);
  12137. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12138. BootNotificationInterval = intervalInt;
  12139. HeartBeatWaitTime = intervalInt;
  12140. //write back to ShmOCPP16Data->BootNotification
  12141. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12142. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12143. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12144. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12145. {
  12146. server_sign = TRUE;
  12147. server_pending =FALSE;
  12148. }
  12149. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12150. {
  12151. server_pending = TRUE;
  12152. }
  12153. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12154. srand(time(NULL));
  12155. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12156. SetOcppConnStatus(TRUE);
  12157. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12158. }
  12159. void handleDataTransferResponse(char *payload, int gun_index)
  12160. {
  12161. char sstr[160]={0};//sstr[200]={ 0 };
  12162. int c = 0;
  12163. char *loc;
  12164. DEBUG_INFO("handleDataTransferResponse ...\n");
  12165. loc = strstr(payload, "status");
  12166. c = 0;
  12167. while (loc[3+strlen("status")+c] != '\"')
  12168. {
  12169. sstr[c] = loc[3+strlen("status")+c];
  12170. c++;
  12171. }
  12172. sstr[c] = '\0';
  12173. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12174. }
  12175. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12176. {
  12177. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12178. //struct json_object *obj;
  12179. // obj = json_tokener_parse(payload);
  12180. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12181. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12182. //No fields are defined.
  12183. }
  12184. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12185. {
  12186. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12187. //struct json_object *obj;
  12188. // obj = json_tokener_parse(payload);
  12189. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12190. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12191. //No fields are defined.
  12192. }
  12193. void handleHeartbeatResponse(char *payload, int gun_index)
  12194. {
  12195. mtrace();
  12196. DEBUG_INFO("handleHeartbeatResponse...\n");
  12197. json_object *Heartbeat;
  12198. Heartbeat = json_tokener_parse(payload);
  12199. if(!is_error(Heartbeat))
  12200. {
  12201. // Required data
  12202. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12203. }
  12204. json_object_put(Heartbeat);
  12205. if(FirstHeartBeat == 0)
  12206. {
  12207. FirstHeartBeat = 1;
  12208. DEBUG_INFO("FirstHeartBeat \n");
  12209. }
  12210. HeartBeatWithNOResponse = 0;
  12211. clientTime.Heartbeat=time((time_t*)NULL);
  12212. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12213. }
  12214. void handleMeterValuesResponse(char *payload, int gun_index)
  12215. {
  12216. mtrace();
  12217. DEBUG_INFO("handleMeterValuesResponse...\n");
  12218. }
  12219. void handleStartTransactionResponse(char *payload, int gun_index)
  12220. {
  12221. mtrace();
  12222. //int transactionIdInt = 0;
  12223. FILE *outfile;
  12224. char data[100]={0};
  12225. DEBUG_INFO("handleStartTransactionResponse...\n");
  12226. json_object *StartTransaction;
  12227. StartTransaction = json_tokener_parse(payload);
  12228. if(!is_error(StartTransaction))
  12229. {
  12230. // Required data
  12231. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12232. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12233. // Optional data
  12234. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12235. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12236. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12237. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12238. }
  12239. json_object_put(StartTransaction);
  12240. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12241. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12242. //-----------Start : write to the Queue TransactionId file -----------------//
  12243. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12244. {}
  12245. else
  12246. {
  12247. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12248. if(log == NULL)
  12249. {
  12250. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12251. return ;
  12252. }
  12253. else
  12254. {
  12255. fclose(log);
  12256. }
  12257. }
  12258. // open file for writing
  12259. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12260. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12261. {
  12262. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12263. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12264. fputs(data, outfile);
  12265. fclose (outfile);
  12266. }
  12267. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12268. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12269. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12270. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12271. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12272. }
  12273. void handleStatusNotificationResponse(char *payload, int gun_index)
  12274. {
  12275. mtrace();
  12276. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12277. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12278. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12279. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12280. }
  12281. void handleStopTransactionnResponse(char *payload, int gun_index)
  12282. {
  12283. mtrace();
  12284. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12285. json_object *StopTransaction;
  12286. StopTransaction = json_tokener_parse(payload);
  12287. if(!is_error(StopTransaction))
  12288. {
  12289. // Optional data
  12290. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12291. {
  12292. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12293. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12294. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12295. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12296. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12297. }
  12298. }
  12299. json_object_put(StopTransaction);
  12300. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12301. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12302. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12303. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12304. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12305. }
  12306. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12307. {
  12308. mtrace();
  12309. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12310. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12311. }
  12312. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12313. {
  12314. mtrace();
  12315. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12316. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12317. }
  12318. void handleSignCertificateResponse(char *payload, int gun_index)
  12319. {
  12320. mtrace();
  12321. DEBUG_INFO("handleSignCertificateResponse...\n");
  12322. json_object *SignCertificate;
  12323. SignCertificate = json_tokener_parse(payload);
  12324. if(!is_error(SignCertificate))
  12325. {
  12326. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12327. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12328. }
  12329. json_object_put(SignCertificate);
  12330. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12331. }
  12332. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12333. {
  12334. mtrace();
  12335. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12336. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12337. }
  12338. //==========================================
  12339. // Handle Error routine
  12340. //==========================================
  12341. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12342. {
  12343. mtrace();
  12344. #ifdef SystemLogMessage
  12345. DEBUG_INFO("errorCode: %s\n", errorCode);
  12346. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12347. DEBUG_INFO("errorDetails: %s\n", payload);
  12348. #endif
  12349. }
  12350. //===============================================
  12351. // Common routine
  12352. //===============================================
  12353. int initialConfigurationTable(void)
  12354. {
  12355. //clock_t start_t, end_t, total_t;
  12356. FILE *fp;
  12357. FILE *outfile;
  12358. char str[512]={0};
  12359. char sstr[256]={0};
  12360. int c = 0;
  12361. char *loc;
  12362. int confVersion = 8;
  12363. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12364. //start_t = clock();
  12365. //printf("Starting of the program, start_t = %ld\n", start_t);
  12366. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12367. // Check configuration file size is correct
  12368. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12369. {
  12370. struct stat st;
  12371. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12372. if(st.st_size < 3100)
  12373. {
  12374. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12375. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12376. }
  12377. }
  12378. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12379. {
  12380. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12381. if(outfile == NULL)
  12382. {
  12383. DEBUG_INFO("Error opening file\n");
  12384. return FALSE;
  12385. }
  12386. /*Core Profile*/
  12387. //AllowOfflineTxForUnknownId
  12388. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12392. //AuthorizationCacheEnabled
  12393. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12397. //AuthorizeRemoteTxRequests
  12398. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12402. //BlinkRepeat
  12403. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12407. //ClockAlignedDataInterval
  12408. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12412. //ConnectionTimeOut
  12413. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12417. //GetConfigurationMaxKeys
  12418. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12422. // HeartbeatInterval
  12423. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12427. // LightIntensity
  12428. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12432. // LocalAuthorizeOffline
  12433. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12437. // LocalPreAuthorize
  12438. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12442. // MaxEnergyOnInvalidId
  12443. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12447. // MeterValuesAlignedData
  12448. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12450. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12451. 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" );
  12452. else
  12453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12455. // MeterValuesAlignedDataMaxLength
  12456. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12458. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12460. else
  12461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12463. // MeterValuesSampledData
  12464. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12467. 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" );
  12468. else
  12469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12471. // MeterValuesSampledDataMaxLength
  12472. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12474. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12476. else
  12477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12479. // MeterValueSampleInterval
  12480. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12484. // MinimumStatusDuration
  12485. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12488. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12490. // NumberOfConnectors
  12491. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12494. {
  12495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12496. }
  12497. else
  12498. {
  12499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12500. }
  12501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12502. // ResetRetries
  12503. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12507. // ConnectorPhaseRotation
  12508. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12512. // ConnectorPhaseRotationMaxLength
  12513. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12517. // StopTransactionOnEVSideDisconnect
  12518. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12522. // StopTransactionOnInvalidId
  12523. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12527. // StopTxnAlignedData
  12528. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12532. // StopTxnAlignedDataMaxLength
  12533. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12537. // StopTxnSampledData
  12538. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12540. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12542. else
  12543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12545. // StopTxnSampledDataMaxLength
  12546. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12549. {
  12550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12551. }
  12552. else
  12553. {
  12554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12555. }
  12556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12557. // SupportedFeatureProfiles
  12558. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12562. // SupportedFeatureProfilesMaxLength
  12563. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12567. // TransactionMessageAttempts
  12568. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12571. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12573. // TransactionMessageRetryInterval
  12574. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12577. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12579. // UnlockConnectorOnEVSideDisconnect
  12580. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12584. // WebSocketPingInterval
  12585. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12589. // QueueOffLineMeterValues
  12590. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12594. // AuthorizationKey
  12595. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12599. // SecurityProfile
  12600. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12604. // DefaultPrice
  12605. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12609. // CustomDisplayCostAndPrice
  12610. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12614. // CustomIdleFeeAfterStop
  12615. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12619. // TimeOffset
  12620. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12624. // NextTimeOffsetTransitionDateTime
  12625. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12629. // TimeOffsetNextTransition
  12630. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12634. // Configuration Version
  12635. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12637. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12639. //* Local Auth List Management Profile*/
  12640. #if 0
  12641. //For OCTT Test Case
  12642. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12645. #endif
  12646. #if 1
  12647. //LocalAuthListEnabled
  12648. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12652. #endif
  12653. //LocalAuthListMaxLength
  12654. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12658. //SendLocalListMaxLength
  12659. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12663. //ReserveConnectorZeroSupported
  12664. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12668. //* Smart Charging Profile */
  12669. //ChargeProfileMaxStackLevel
  12670. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12674. // ChargingScheduleAllowedChargingRateUnit
  12675. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12679. // ChargingScheduleMaxPeriods
  12680. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12684. // ConnectorSwitch3to1PhaseSupported
  12685. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12689. // MaxChargingProfilesInstalled
  12690. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12694. fclose(outfile);
  12695. }
  12696. else
  12697. {
  12698. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12699. char keystr[60]={0};
  12700. char readonlystr[10]={0};
  12701. char valuestr[256]={0};
  12702. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12703. if(fp == NULL) {
  12704. DEBUG_INFO("Error opening file");
  12705. return FALSE;
  12706. }
  12707. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12708. {
  12709. //DEBUG_INFO("Get Configuration \n");
  12710. if(strlen(str) > 0)
  12711. {
  12712. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12713. //*************************key*********************************/
  12714. if(strstr(str, "key") != NULL)
  12715. {
  12716. loc = strstr(str, "key");
  12717. c = 0;
  12718. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12719. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12720. {
  12721. sstr[c] = loc[strlen("key")+3+c];
  12722. c++;
  12723. }
  12724. sstr[c] = '\0';
  12725. strcpy(keystr,sstr);
  12726. }
  12727. //*************************readonly*********************************/
  12728. if(strstr(str, "readonly") != NULL)
  12729. {
  12730. loc = strstr(str, "readonly");
  12731. c = 0;
  12732. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12733. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12734. {
  12735. sstr[c] = loc[strlen("readonly")+2+c];
  12736. c++;
  12737. }
  12738. sstr[c] = '\0';
  12739. strcpy(readonlystr,sstr);
  12740. }
  12741. //*************************value*********************************/
  12742. if(strstr(str, "value") != NULL)
  12743. {
  12744. loc = strstr(str, "value");
  12745. c = 0;
  12746. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12747. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12748. {
  12749. sstr[c] = loc[strlen("value")+3+c];
  12750. c++;
  12751. }
  12752. sstr[c] = '\0';
  12753. strcpy(valuestr,sstr);
  12754. }
  12755. // DEBUG_INFO("keystr=%s\n",keystr);
  12756. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12757. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12758. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12759. {
  12760. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12761. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12763. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12764. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12765. }
  12766. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12767. {
  12768. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12769. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12771. }
  12772. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12773. {
  12774. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12776. }
  12777. if(strcmp(keystr, "BlinkRepeat") == 0)
  12778. {
  12779. //Charger.BlinkRepeat = Integer.parseInt(value);
  12780. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12782. }
  12783. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12784. {
  12785. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12787. }
  12788. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12789. {
  12790. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12792. }
  12793. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12794. {
  12795. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12797. }
  12798. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12799. {
  12800. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12802. HeartBeatWaitTime = atoi(valuestr);
  12803. }
  12804. if(strcmp(keystr, "LightIntensity") == 0)
  12805. {
  12806. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12808. }
  12809. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12810. {
  12811. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12813. }
  12814. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12815. {
  12816. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12818. }
  12819. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12820. {
  12821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12823. }
  12824. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12825. {
  12826. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12828. }
  12829. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12830. {
  12831. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12833. }
  12834. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12835. {
  12836. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12838. }
  12839. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12840. {
  12841. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12843. }
  12844. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12845. {
  12846. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12848. }
  12849. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12850. {
  12851. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12853. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12854. }
  12855. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12856. {
  12857. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12859. }
  12860. if(strcmp(keystr, "ResetRetries") == 0)
  12861. {
  12862. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12864. }
  12865. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12866. {
  12867. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12869. }
  12870. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12871. {
  12872. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12874. }
  12875. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12876. {
  12877. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12879. }
  12880. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12881. {
  12882. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12884. }
  12885. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12886. {
  12887. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12889. }
  12890. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12891. {
  12892. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12894. }
  12895. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12896. {
  12897. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12899. }
  12900. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12901. {
  12902. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12904. }
  12905. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12906. {
  12907. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12909. }
  12910. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12911. {
  12912. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12914. }
  12915. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12916. {
  12917. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12919. TransactionMessageAttemptsValue = atoi(valuestr);
  12920. }
  12921. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12922. {
  12923. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12925. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12926. }
  12927. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12928. {
  12929. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12931. }
  12932. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12933. {
  12934. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12936. }
  12937. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12938. {
  12939. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12941. }
  12942. if(strcmp(keystr, "AuthorizationKey") == 0)
  12943. {
  12944. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12945. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12947. }
  12948. if(strcmp(keystr, "SecurityProfile") == 0)
  12949. {
  12950. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12952. }
  12953. if(strcmp(keystr, "DefaultPrice") == 0)
  12954. {
  12955. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12957. }
  12958. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12959. {
  12960. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12962. }
  12963. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12964. {
  12965. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12967. }
  12968. if(strcmp(keystr, "TimeOffset") == 0)
  12969. {
  12970. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12972. }
  12973. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12974. {
  12975. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12977. }
  12978. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12979. {
  12980. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12982. }
  12983. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12984. {
  12985. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12987. }
  12988. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12989. {
  12990. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12992. }
  12993. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12994. {
  12995. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12997. }
  12998. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12999. {
  13000. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13002. }
  13003. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13004. {
  13005. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13007. }
  13008. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13009. {
  13010. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13012. }
  13013. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13014. {
  13015. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13017. }
  13018. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13019. {
  13020. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13022. }
  13023. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13024. {
  13025. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13027. }
  13028. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13029. {
  13030. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13032. }
  13033. }
  13034. }
  13035. fclose(fp);
  13036. }
  13037. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13038. {
  13039. return PASS;
  13040. }
  13041. else
  13042. {
  13043. return FAIL;
  13044. }
  13045. }
  13046. void StoreConfigurationTable(void)
  13047. {
  13048. FILE *outfile;
  13049. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13050. if(outfile == NULL)
  13051. {
  13052. DEBUG_INFO("Error opening file");
  13053. return ;
  13054. }
  13055. /*Core Profile*/
  13056. //AllowOfflineTxForUnknownId
  13057. /*
  13058. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13059. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13062. */
  13063. //DEBUG_INFO("data=%s\n",data);
  13064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13065. //AuthorizationCacheEnabled
  13066. /*
  13067. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13070. */
  13071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13072. //AuthorizeRemoteTxRequests
  13073. /*
  13074. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13077. */
  13078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13079. //BlinkRepeat
  13080. /*
  13081. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13084. */
  13085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13086. //ClockAlignedDataInterval
  13087. /*
  13088. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13091. */
  13092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13093. //ConnectionTimeOut
  13094. /*
  13095. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13098. */
  13099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13100. //GetConfigurationMaxKeys
  13101. /*
  13102. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13105. */
  13106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13107. // HeartbeatInterval
  13108. /*
  13109. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13112. */
  13113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13114. // LightIntensity
  13115. /*
  13116. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13119. */
  13120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13121. // LocalAuthorizeOffline
  13122. /*
  13123. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13126. */
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13128. // LocalPreAuthorize
  13129. /*
  13130. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13133. */
  13134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13135. // MaxEnergyOnInvalidId
  13136. /*
  13137. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13140. */
  13141. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13143. // MeterValuesAlignedData
  13144. /*
  13145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13148. */
  13149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13150. // MeterValuesAlignedDataMaxLength
  13151. /*
  13152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13155. */
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13157. // MeterValuesSampledData
  13158. /*
  13159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13162. */
  13163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13164. // MeterValuesSampledDataMaxLength
  13165. /*
  13166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13169. */
  13170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13171. // MeterValueSampleInterval
  13172. /*
  13173. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13176. */
  13177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13178. // MinimumStatusDuration
  13179. /*
  13180. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13183. */
  13184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13185. // NumberOfConnectors
  13186. /*
  13187. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13190. {
  13191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13192. }
  13193. else
  13194. {
  13195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13196. }
  13197. */
  13198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13199. // ResetRetries
  13200. /*
  13201. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13204. */
  13205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13206. // ConnectorPhaseRotation
  13207. /*
  13208. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13211. */
  13212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13213. // ConnectorPhaseRotationMaxLength
  13214. /*
  13215. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13218. */
  13219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13220. // StopTransactionOnEVSideDisconnect
  13221. /*
  13222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13225. */
  13226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13227. // StopTransactionOnInvalidId
  13228. /*
  13229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13232. */
  13233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13234. // StopTxnAlignedData
  13235. /*
  13236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13239. */
  13240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13241. // StopTxnAlignedDataMaxLength
  13242. /*
  13243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13246. */
  13247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13248. // StopTxnSampledData
  13249. /*
  13250. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13253. */
  13254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13255. // StopTxnSampledDataMaxLength
  13256. /*
  13257. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13260. */
  13261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13262. // SupportedFeatureProfiles
  13263. /*
  13264. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13267. */
  13268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13269. // SupportedFeatureProfilesMaxLength
  13270. /*
  13271. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13274. */
  13275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13276. // TransactionMessageAttempts
  13277. /*
  13278. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13281. */
  13282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13283. // TransactionMessageRetryInterval
  13284. /*
  13285. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13288. */
  13289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13290. // UnlockConnectorOnEVSideDisconnect
  13291. /*
  13292. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13295. */
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13297. // WebSocketPingInterval
  13298. /*
  13299. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13302. */
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13304. // QueueOffLineMeterValues
  13305. /*
  13306. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13309. */
  13310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13311. // AuthorizationKey
  13312. /*
  13313. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13316. */
  13317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13318. // SecurityProfile
  13319. /*
  13320. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13323. */
  13324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13325. // DefaultPrice
  13326. /*
  13327. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13330. */
  13331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13332. // CustomDisplayCostAndPrice
  13333. /*
  13334. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13337. */
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13339. // CustomIdleFeeAfterStop
  13340. /*
  13341. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13344. */
  13345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13346. // TimeOffset
  13347. /*
  13348. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13351. */
  13352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13353. // NextTimeOffsetTransitionDateTime
  13354. /*
  13355. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13358. */
  13359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13360. // TimeOffsetNextTransition
  13361. /*
  13362. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13365. */
  13366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13367. // ConfigurationVersion
  13368. /*
  13369. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13372. */
  13373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13374. //* Local Auth List Management Profile*/
  13375. //LocalAuthListEnabled
  13376. /*
  13377. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13380. */
  13381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13382. //LocalAuthListMaxLength
  13383. /*
  13384. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13387. */
  13388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13389. //SendLocalListMaxLength
  13390. /*
  13391. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13394. */
  13395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13396. //ReserveConnectorZeroSupported
  13397. /*
  13398. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13401. */
  13402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13403. //* Smart Charging Profile */
  13404. //ChargeProfileMaxStackLevel
  13405. /*
  13406. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13409. */
  13410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13411. // ChargingScheduleAllowedChargingRateUnit
  13412. /*
  13413. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13416. */
  13417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13418. // ChargingScheduleMaxPeriods
  13419. /*
  13420. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13423. */
  13424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13425. // ConnectorSwitch3to1PhaseSupported
  13426. /*
  13427. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13430. */
  13431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13432. // MaxChargingProfilesInstalled
  13433. /*
  13434. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13437. */
  13438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13439. fclose(outfile);
  13440. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13441. }
  13442. void getKeyValue(char *keyReq)
  13443. {
  13444. int isEmpty = FALSE;
  13445. int isKnowKey = FALSE;
  13446. DEBUG_INFO("keyReq = %s\n", keyReq);
  13447. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13448. isEmpty = TRUE;
  13449. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13450. {
  13451. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13454. {
  13455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13456. }
  13457. else
  13458. {
  13459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13460. }
  13461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13462. isKnowKey = TRUE;
  13463. }
  13464. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13465. {
  13466. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13469. {
  13470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13471. }
  13472. else
  13473. {
  13474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13475. }
  13476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13477. isKnowKey = TRUE;
  13478. }
  13479. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13480. {
  13481. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13484. {
  13485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13486. }
  13487. else
  13488. {
  13489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13490. }
  13491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13492. isKnowKey = TRUE;
  13493. }
  13494. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13495. {
  13496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13499. {
  13500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13501. }
  13502. else
  13503. {
  13504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13505. }
  13506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13507. isKnowKey = TRUE;
  13508. }
  13509. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13510. {
  13511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13514. {
  13515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13516. }
  13517. else
  13518. {
  13519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13520. }
  13521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13522. isKnowKey = TRUE;
  13523. }
  13524. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13525. {
  13526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13529. {
  13530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13531. }
  13532. else
  13533. {
  13534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13535. }
  13536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13537. isKnowKey = TRUE;
  13538. }
  13539. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13540. {
  13541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13544. {
  13545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13546. }
  13547. else
  13548. {
  13549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13550. }
  13551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13552. isKnowKey = TRUE;
  13553. }
  13554. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13555. {
  13556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13559. {
  13560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13561. }
  13562. else
  13563. {
  13564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13565. }
  13566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13567. isKnowKey = TRUE;
  13568. }
  13569. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13570. {
  13571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13574. {
  13575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13576. }
  13577. else
  13578. {
  13579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13580. }
  13581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13582. isKnowKey = TRUE;
  13583. }
  13584. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13585. {
  13586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13589. {
  13590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13591. }
  13592. else
  13593. {
  13594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13595. }
  13596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13597. isKnowKey = TRUE;
  13598. }
  13599. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13600. {
  13601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13604. {
  13605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13606. }
  13607. else
  13608. {
  13609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13610. }
  13611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13612. isKnowKey = TRUE;
  13613. }
  13614. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13615. {
  13616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13619. {
  13620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13621. }
  13622. else
  13623. {
  13624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13625. }
  13626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13627. isKnowKey = TRUE;
  13628. }
  13629. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13630. {
  13631. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13634. {
  13635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13636. }
  13637. else
  13638. {
  13639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13640. }
  13641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13642. isKnowKey = TRUE;
  13643. }
  13644. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13645. {
  13646. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13649. {
  13650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13651. }
  13652. else
  13653. {
  13654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13655. }
  13656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13657. isKnowKey = TRUE;
  13658. }
  13659. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13660. {
  13661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13664. {
  13665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13666. }
  13667. else
  13668. {
  13669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13670. }
  13671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13672. isKnowKey = TRUE;
  13673. }
  13674. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13675. {
  13676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13679. {
  13680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13681. }
  13682. else
  13683. {
  13684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13685. }
  13686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13687. isKnowKey = TRUE;
  13688. }
  13689. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13690. {
  13691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13694. {
  13695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13696. }
  13697. else
  13698. {
  13699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13700. }
  13701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13702. isKnowKey = TRUE;
  13703. }
  13704. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13705. {
  13706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13709. {
  13710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13711. }
  13712. else
  13713. {
  13714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13715. }
  13716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13717. isKnowKey = TRUE;
  13718. }
  13719. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13720. {
  13721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13724. {
  13725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13726. }
  13727. else
  13728. {
  13729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13730. }
  13731. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13733. isKnowKey = TRUE;
  13734. }
  13735. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13736. {
  13737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13740. {
  13741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13742. }
  13743. else
  13744. {
  13745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13746. }
  13747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13748. isKnowKey = TRUE;
  13749. }
  13750. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13751. {
  13752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13755. {
  13756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13757. }
  13758. else
  13759. {
  13760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13761. }
  13762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13763. isKnowKey = TRUE;
  13764. }
  13765. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13766. {
  13767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13770. {
  13771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13772. }
  13773. else
  13774. {
  13775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13776. }
  13777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13778. isKnowKey = TRUE;
  13779. }
  13780. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13781. {
  13782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13785. {
  13786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13787. }
  13788. else
  13789. {
  13790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13791. }
  13792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13793. isKnowKey = TRUE;
  13794. }
  13795. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13796. {
  13797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13800. {
  13801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13802. }
  13803. else
  13804. {
  13805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13806. }
  13807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13808. isKnowKey = TRUE;
  13809. }
  13810. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13811. {
  13812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13815. {
  13816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13817. }
  13818. else
  13819. {
  13820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13821. }
  13822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13823. isKnowKey = TRUE;
  13824. }
  13825. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13826. {
  13827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13830. {
  13831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13832. }
  13833. else
  13834. {
  13835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13836. }
  13837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13838. isKnowKey = TRUE;
  13839. }
  13840. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13841. {
  13842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13845. {
  13846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13847. }
  13848. else
  13849. {
  13850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13851. }
  13852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13853. isKnowKey = TRUE;
  13854. }
  13855. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13856. {
  13857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13860. {
  13861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13862. }
  13863. else
  13864. {
  13865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13866. }
  13867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13868. isKnowKey = TRUE;
  13869. }
  13870. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13871. {
  13872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13875. {
  13876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13877. }
  13878. else
  13879. {
  13880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13881. }
  13882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13883. isKnowKey = TRUE;
  13884. }
  13885. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13886. {
  13887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13890. {
  13891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13892. }
  13893. else
  13894. {
  13895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13896. }
  13897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13898. isKnowKey = TRUE;
  13899. }
  13900. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13901. {
  13902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13905. {
  13906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13907. }
  13908. else
  13909. {
  13910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13911. }
  13912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13913. isKnowKey = TRUE;
  13914. }
  13915. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13916. {
  13917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13920. {
  13921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13922. }
  13923. else
  13924. {
  13925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13926. }
  13927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13928. isKnowKey = TRUE;
  13929. }
  13930. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13931. {
  13932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13935. {
  13936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13937. }
  13938. else
  13939. {
  13940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13941. }
  13942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13943. isKnowKey = TRUE;
  13944. }
  13945. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13946. {
  13947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13950. {
  13951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13952. }
  13953. else
  13954. {
  13955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13956. }
  13957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13958. isKnowKey = TRUE;
  13959. }
  13960. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13961. {
  13962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13965. {
  13966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13967. }
  13968. else
  13969. {
  13970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13971. }
  13972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13973. isKnowKey = TRUE;
  13974. }
  13975. /*
  13976. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13977. {
  13978. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13981. {
  13982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13983. }
  13984. else
  13985. {
  13986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13987. }
  13988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13989. isKnowKey = TRUE;
  13990. }*/
  13991. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13992. {
  13993. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13996. {
  13997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13998. }
  13999. else
  14000. {
  14001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14002. }
  14003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14004. isKnowKey = TRUE;
  14005. }
  14006. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14007. {
  14008. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14011. {
  14012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14013. }
  14014. else
  14015. {
  14016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14017. }
  14018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14019. isKnowKey = TRUE;
  14020. }
  14021. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14022. {
  14023. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14026. {
  14027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14028. }
  14029. else
  14030. {
  14031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14032. }
  14033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14034. isKnowKey = TRUE;
  14035. }
  14036. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14037. {
  14038. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14041. {
  14042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14043. }
  14044. else
  14045. {
  14046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14047. }
  14048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14049. isKnowKey = TRUE;
  14050. }
  14051. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14052. {
  14053. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14056. {
  14057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14058. }
  14059. else
  14060. {
  14061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14062. }
  14063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14064. isKnowKey = TRUE;
  14065. }
  14066. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14067. {
  14068. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14071. {
  14072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14073. }
  14074. else
  14075. {
  14076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14077. }
  14078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14079. isKnowKey = TRUE;
  14080. }
  14081. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14082. {
  14083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14086. {
  14087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14088. }
  14089. else
  14090. {
  14091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14092. }
  14093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14094. isKnowKey = TRUE;
  14095. }
  14096. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14097. {
  14098. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14101. {
  14102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14103. }
  14104. else
  14105. {
  14106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14107. }
  14108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14109. isKnowKey = TRUE;
  14110. }
  14111. #if 1
  14112. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14113. {
  14114. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14116. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14117. {
  14118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14119. }
  14120. else
  14121. {
  14122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14123. }
  14124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14125. isKnowKey = TRUE;
  14126. }
  14127. #endif
  14128. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14129. {
  14130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14132. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14133. {
  14134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14135. }
  14136. else
  14137. {
  14138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14139. }
  14140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14141. isKnowKey = TRUE;
  14142. }
  14143. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14144. {
  14145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14147. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14148. {
  14149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14150. }
  14151. else
  14152. {
  14153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14154. }
  14155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14156. isKnowKey = TRUE;
  14157. }
  14158. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14159. {
  14160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14162. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14163. {
  14164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14165. }
  14166. else
  14167. {
  14168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14169. }
  14170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14171. isKnowKey = TRUE;
  14172. }
  14173. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14174. {
  14175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14177. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14178. {
  14179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14180. }
  14181. else
  14182. {
  14183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14184. }
  14185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14186. isKnowKey = TRUE;
  14187. }
  14188. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14189. {
  14190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14192. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14193. {
  14194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14195. }
  14196. else
  14197. {
  14198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14199. }
  14200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14201. isKnowKey = TRUE;
  14202. }
  14203. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14204. {
  14205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14207. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14208. {
  14209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14210. }
  14211. else
  14212. {
  14213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14214. }
  14215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14216. isKnowKey = TRUE;
  14217. }
  14218. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14219. {
  14220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14222. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14223. {
  14224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14225. }
  14226. else
  14227. {
  14228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14229. }
  14230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14231. isKnowKey = TRUE;
  14232. }
  14233. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14234. {
  14235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14237. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14238. {
  14239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14240. }
  14241. else
  14242. {
  14243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14244. }
  14245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14246. isKnowKey = TRUE;
  14247. }
  14248. //=========================================================
  14249. if(!isEmpty && !isKnowKey)
  14250. {
  14251. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14252. strcpy(unknownkey[UnknownKeynum], keyReq);
  14253. UnknownKeynum = UnknownKeynum + 1;
  14254. }
  14255. }
  14256. void processUnkownKey(void)
  14257. {
  14258. DEBUG_INFO("processUnkownKey...\n");
  14259. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14260. for(int index=0; index < UnknownKeynum; index++)
  14261. {
  14262. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14263. {
  14264. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14265. }
  14266. }
  14267. }
  14268. int setKeyValue(char *key, char *value)
  14269. {
  14270. int isSuccess = NotSupported;
  14271. int check_ascii=0;
  14272. char str[256]={0};
  14273. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14274. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14275. {
  14276. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14278. {
  14279. strcpy(str, (const char*)value);
  14280. for(int i = 0; str[i]; i++){
  14281. str[i] = tolower(str[i]);
  14282. }
  14283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14284. isSuccess = ConfigurationStatus_Accepted;
  14285. }
  14286. else
  14287. {
  14288. isSuccess = ConfigurationStatus_Rejected;
  14289. }
  14290. }
  14291. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14292. {
  14293. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14295. {
  14296. strcpy(str, (const char*)value);
  14297. for(int i = 0; str[i]; i++){
  14298. str[i] = tolower(str[i]);
  14299. }
  14300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14301. isSuccess = ConfigurationStatus_Accepted;
  14302. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14303. }
  14304. else
  14305. {
  14306. isSuccess = ConfigurationStatus_Rejected;
  14307. }
  14308. }
  14309. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14310. {
  14311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14312. {
  14313. strcpy(str, (const char*)value);
  14314. for(int i = 0; str[i]; i++)
  14315. {
  14316. str[i] = tolower(str[i]);
  14317. }
  14318. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14320. isSuccess = ConfigurationStatus_Accepted;
  14321. }
  14322. else
  14323. {
  14324. isSuccess = ConfigurationStatus_Rejected;
  14325. }
  14326. }
  14327. if(strcmp(key, "BlinkRepeat") == 0)
  14328. {
  14329. //Charger.BlinkRepeat = Integer.parseInt(value);
  14330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14331. {
  14332. check_ascii = value[0];
  14333. if( (check_ascii < 48) || (check_ascii > 57) )
  14334. {
  14335. isSuccess = ConfigurationStatus_Rejected;
  14336. }
  14337. else
  14338. {
  14339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14340. isSuccess = ConfigurationStatus_Accepted;
  14341. }
  14342. }
  14343. else
  14344. {
  14345. isSuccess = ConfigurationStatus_Rejected;
  14346. }
  14347. }
  14348. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14349. {
  14350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14351. {
  14352. check_ascii = value[0];
  14353. if( (check_ascii < 48) || (check_ascii > 57) )
  14354. {
  14355. isSuccess = ConfigurationStatus_Rejected;
  14356. }
  14357. else
  14358. {
  14359. if((atoi(value) == 0) || (atoi(value) >= 10))
  14360. {
  14361. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14363. isSuccess = ConfigurationStatus_Accepted;
  14364. }
  14365. else
  14366. isSuccess = ConfigurationStatus_Rejected;
  14367. }
  14368. }
  14369. else
  14370. {
  14371. isSuccess = ConfigurationStatus_Rejected;
  14372. }
  14373. }
  14374. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14375. {
  14376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14377. {
  14378. check_ascii = value[0];
  14379. if( (check_ascii < 48) || (check_ascii > 57) )
  14380. {
  14381. isSuccess = ConfigurationStatus_Rejected;
  14382. }
  14383. else
  14384. {
  14385. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14387. isSuccess = ConfigurationStatus_Accepted;
  14388. }
  14389. }
  14390. else
  14391. {
  14392. isSuccess = ConfigurationStatus_Rejected;
  14393. }
  14394. }
  14395. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14396. {
  14397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14398. {
  14399. check_ascii = value[0];
  14400. if( (check_ascii < 48) || (check_ascii > 57) )
  14401. {
  14402. isSuccess = ConfigurationStatus_Rejected;
  14403. }
  14404. else
  14405. {
  14406. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14408. isSuccess = ConfigurationStatus_Accepted;
  14409. }
  14410. }
  14411. else
  14412. {
  14413. isSuccess = ConfigurationStatus_Rejected;
  14414. }
  14415. }
  14416. if(strcmp(key, "HeartbeatInterval") == 0)
  14417. {
  14418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14419. {
  14420. check_ascii = value[0];
  14421. if( (check_ascii < 48) || (check_ascii > 57) )
  14422. {
  14423. isSuccess = ConfigurationStatus_Rejected;
  14424. }
  14425. else
  14426. {
  14427. if((atoi(value) == 0) || (atoi(value) >= 10))
  14428. {
  14429. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14431. HeartBeatWaitTime = atoi(value);
  14432. isSuccess = ConfigurationStatus_Accepted;
  14433. }
  14434. else
  14435. {
  14436. isSuccess = ConfigurationStatus_Rejected;
  14437. }
  14438. }
  14439. }
  14440. else
  14441. {
  14442. isSuccess = ConfigurationStatus_Rejected;
  14443. }
  14444. }
  14445. if(strcmp(key, "LightIntensity") == 0)
  14446. {
  14447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14448. {
  14449. check_ascii = value[0];
  14450. if( (check_ascii < 48) || (check_ascii > 57) )
  14451. {
  14452. isSuccess = ConfigurationStatus_Rejected;
  14453. }
  14454. else
  14455. {
  14456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14457. isSuccess = ConfigurationStatus_Accepted;
  14458. }
  14459. }
  14460. else
  14461. {
  14462. isSuccess = ConfigurationStatus_Rejected;
  14463. }
  14464. }
  14465. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14466. {
  14467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14468. {
  14469. strcpy(str, (const char*)value);
  14470. for(int i = 0; str[i]; i++)
  14471. {
  14472. str[i] = tolower(str[i]);
  14473. }
  14474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14475. isSuccess = ConfigurationStatus_Accepted;
  14476. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14477. }
  14478. else
  14479. {
  14480. isSuccess = ConfigurationStatus_Rejected;
  14481. }
  14482. }
  14483. if(strcmp(key, "LocalPreAuthorize") == 0)
  14484. {
  14485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14486. {
  14487. strcpy(str, (const char*)value);
  14488. for(int i = 0; str[i]; i++)
  14489. {
  14490. str[i] = tolower(str[i]);
  14491. }
  14492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14493. isSuccess = ConfigurationStatus_Accepted;
  14494. }
  14495. else
  14496. {
  14497. isSuccess = ConfigurationStatus_Rejected;
  14498. }
  14499. }
  14500. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14501. {
  14502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14503. {
  14504. check_ascii = value[0];
  14505. if( (check_ascii < 48) || (check_ascii > 57) )
  14506. {
  14507. isSuccess = ConfigurationStatus_Rejected;
  14508. }
  14509. else
  14510. {
  14511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14512. isSuccess = ConfigurationStatus_Accepted;
  14513. }
  14514. }
  14515. else
  14516. {
  14517. isSuccess = ConfigurationStatus_Rejected;
  14518. }
  14519. }
  14520. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14521. {
  14522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14523. {
  14524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14525. isSuccess = ConfigurationStatus_Accepted;
  14526. }
  14527. else
  14528. {
  14529. isSuccess = ConfigurationStatus_Rejected;
  14530. }
  14531. }
  14532. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14533. {
  14534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14535. {
  14536. check_ascii = value[0];
  14537. if( (check_ascii < 48) || (check_ascii > 57) )
  14538. {
  14539. isSuccess = ConfigurationStatus_Rejected;
  14540. }
  14541. else
  14542. {
  14543. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14545. isSuccess = ConfigurationStatus_Accepted;
  14546. }
  14547. }
  14548. else
  14549. {
  14550. isSuccess = ConfigurationStatus_Rejected;
  14551. }
  14552. }
  14553. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14554. {
  14555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14556. {
  14557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14558. isSuccess = ConfigurationStatus_Accepted;
  14559. }
  14560. else
  14561. {
  14562. isSuccess = ConfigurationStatus_Rejected;
  14563. }
  14564. }
  14565. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14566. {
  14567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14568. {
  14569. check_ascii = value[0];
  14570. if( (check_ascii < 48) || (check_ascii > 57) )
  14571. {
  14572. isSuccess = ConfigurationStatus_Rejected;
  14573. }
  14574. else
  14575. {
  14576. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14578. isSuccess = ConfigurationStatus_Accepted;
  14579. }
  14580. }
  14581. else
  14582. {
  14583. isSuccess = ConfigurationStatus_Rejected;
  14584. }
  14585. }
  14586. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14587. {
  14588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14589. {
  14590. check_ascii = value[0];
  14591. if( (check_ascii < 48) || (check_ascii > 57) )
  14592. {
  14593. isSuccess = ConfigurationStatus_Rejected;
  14594. }
  14595. else
  14596. {
  14597. if((atoi(value) == 0) || (atoi(value) >= 10))
  14598. {
  14599. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14601. isSuccess = ConfigurationStatus_Accepted;
  14602. }
  14603. else
  14604. {
  14605. isSuccess = ConfigurationStatus_Rejected;
  14606. }
  14607. }
  14608. }
  14609. else
  14610. {
  14611. isSuccess = ConfigurationStatus_Rejected;
  14612. }
  14613. }
  14614. if(strcmp(key, "MinimumStatusDuration") == 0)
  14615. {
  14616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14617. {
  14618. check_ascii = value[0];
  14619. if( (check_ascii < 48) || (check_ascii > 57) )
  14620. {
  14621. isSuccess = ConfigurationStatus_Rejected;
  14622. }
  14623. else
  14624. {
  14625. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14626. {
  14627. isSuccess = ConfigurationStatus_Rejected;
  14628. }
  14629. else
  14630. {
  14631. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14633. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14634. isSuccess = ConfigurationStatus_Accepted;
  14635. }
  14636. }
  14637. }
  14638. else
  14639. {
  14640. isSuccess = ConfigurationStatus_Rejected;
  14641. }
  14642. }
  14643. if(strcmp(key, "NumberOfConnectors") == 0)
  14644. {
  14645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14646. {
  14647. check_ascii = value[0];
  14648. if( (check_ascii < 48) || (check_ascii > 57) )
  14649. {
  14650. isSuccess = ConfigurationStatus_Rejected;
  14651. }
  14652. else
  14653. {
  14654. //Charger.ResetRetries = Integer.parseInt(value);
  14655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14656. isSuccess = ConfigurationStatus_Accepted;
  14657. }
  14658. }
  14659. else
  14660. {
  14661. isSuccess = ConfigurationStatus_Rejected;
  14662. }
  14663. }
  14664. if(strcmp(key, "ResetRetries") == 0)
  14665. {
  14666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14667. {
  14668. check_ascii = value[0];
  14669. if( (check_ascii < 48) || (check_ascii > 57) )
  14670. {
  14671. isSuccess = ConfigurationStatus_Rejected;
  14672. }
  14673. else
  14674. {
  14675. //Charger.ResetRetries = Integer.parseInt(value);
  14676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14677. isSuccess = ConfigurationStatus_Accepted;
  14678. }
  14679. }
  14680. else
  14681. {
  14682. isSuccess = ConfigurationStatus_Rejected;
  14683. }
  14684. }
  14685. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14686. {
  14687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14688. {
  14689. strcpy(str, (const char*)value);
  14690. for(int i = 0; str[i]; i++)
  14691. {
  14692. str[i] = tolower(str[i]);
  14693. }
  14694. if(strcmp(str, "notapplicable")== 0)
  14695. {
  14696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14697. isSuccess = ConfigurationStatus_Accepted;
  14698. }
  14699. else if(strcmp(str, "unknown")== 0)
  14700. {
  14701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14702. isSuccess = ConfigurationStatus_Accepted;
  14703. }
  14704. else if(strcmp(str, "rst")== 0)
  14705. {
  14706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14707. isSuccess = ConfigurationStatus_Accepted;
  14708. }
  14709. else if(strcmp(str, "rts")== 0)
  14710. {
  14711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14712. isSuccess = ConfigurationStatus_Accepted;
  14713. }
  14714. else if(strcmp(str, "srt")== 0)
  14715. {
  14716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14717. isSuccess = ConfigurationStatus_Accepted;
  14718. }
  14719. else if(strcmp(str, "str")== 0)
  14720. {
  14721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14722. isSuccess = ConfigurationStatus_Accepted;
  14723. }
  14724. else if(strcmp(str, "trs")== 0)
  14725. {
  14726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14727. isSuccess = ConfigurationStatus_Accepted;
  14728. }
  14729. else if(strcmp(str, "tsr")== 0)
  14730. {
  14731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14732. isSuccess = ConfigurationStatus_Accepted;
  14733. }
  14734. else
  14735. {
  14736. isSuccess = ConfigurationStatus_Rejected;
  14737. }
  14738. }
  14739. else
  14740. {
  14741. isSuccess = ConfigurationStatus_Rejected;
  14742. }
  14743. }
  14744. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14745. {
  14746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14747. {
  14748. check_ascii = value[0];
  14749. if( (check_ascii < 48) || (check_ascii > 57) )
  14750. {
  14751. isSuccess = ConfigurationStatus_Rejected;
  14752. }
  14753. else
  14754. {
  14755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14756. isSuccess = ConfigurationStatus_Accepted;
  14757. }
  14758. }
  14759. else
  14760. {
  14761. isSuccess = ConfigurationStatus_Rejected;
  14762. }
  14763. }
  14764. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14765. {
  14766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14767. {
  14768. strcpy(str, (const char*)value);
  14769. for(int i = 0; str[i]; i++)
  14770. {
  14771. str[i] = tolower(str[i]);
  14772. }
  14773. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14775. isSuccess = ConfigurationStatus_Accepted;
  14776. }
  14777. else
  14778. {
  14779. isSuccess = ConfigurationStatus_Rejected;
  14780. }
  14781. }
  14782. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14783. {
  14784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14785. {
  14786. strcpy(str, (const char*)value);
  14787. for(int i = 0; str[i]; i++)
  14788. {
  14789. str[i] = tolower(str[i]);
  14790. }
  14791. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14793. isSuccess = ConfigurationStatus_Accepted;
  14794. }
  14795. else
  14796. {
  14797. isSuccess = ConfigurationStatus_Rejected;
  14798. }
  14799. }
  14800. if(strcmp(key, "StopTxnAlignedData") == 0)
  14801. {
  14802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14803. {
  14804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14805. isSuccess = ConfigurationStatus_Accepted;
  14806. }
  14807. else
  14808. {
  14809. isSuccess = ConfigurationStatus_Rejected;
  14810. }
  14811. }
  14812. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14813. {
  14814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14815. {
  14816. check_ascii = value[0];
  14817. if( (check_ascii < 48) || (check_ascii > 57) )
  14818. {
  14819. isSuccess = ConfigurationStatus_Rejected;
  14820. }
  14821. else
  14822. {
  14823. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14824. isSuccess = ConfigurationStatus_Accepted;
  14825. }
  14826. }
  14827. else
  14828. {
  14829. isSuccess = ConfigurationStatus_Rejected;
  14830. }
  14831. }
  14832. if(strcmp(key, "StopTxnSampledData") == 0)
  14833. {
  14834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14835. {
  14836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14837. isSuccess = ConfigurationStatus_Accepted;
  14838. }
  14839. else
  14840. {
  14841. isSuccess = ConfigurationStatus_Rejected;
  14842. }
  14843. }
  14844. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14845. {
  14846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14847. {
  14848. check_ascii = value[0];
  14849. if( (check_ascii < 48) || (check_ascii > 57) )
  14850. {
  14851. isSuccess = ConfigurationStatus_Rejected;
  14852. }
  14853. else
  14854. {
  14855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14856. isSuccess = ConfigurationStatus_Accepted;
  14857. }
  14858. }
  14859. else
  14860. {
  14861. isSuccess = ConfigurationStatus_Rejected;
  14862. }
  14863. }
  14864. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14865. {
  14866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14867. {
  14868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14869. isSuccess = ConfigurationStatus_Accepted;
  14870. }
  14871. else
  14872. {
  14873. isSuccess = ConfigurationStatus_Rejected;
  14874. }
  14875. }
  14876. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14877. {
  14878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14879. {
  14880. check_ascii = value[0];
  14881. if( (check_ascii < 48) || (check_ascii > 57) )
  14882. {
  14883. isSuccess = ConfigurationStatus_Rejected;
  14884. }
  14885. else
  14886. {
  14887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14888. isSuccess = ConfigurationStatus_Accepted;
  14889. }
  14890. }
  14891. else
  14892. {
  14893. isSuccess = ConfigurationStatus_Rejected;
  14894. }
  14895. }
  14896. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14897. {
  14898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14899. {
  14900. check_ascii = value[0];
  14901. if( (check_ascii < 48) || (check_ascii > 57) )
  14902. {
  14903. isSuccess = ConfigurationStatus_Rejected;
  14904. }
  14905. else
  14906. {
  14907. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14909. TransactionMessageAttemptsValue = atoi(value);
  14910. isSuccess = ConfigurationStatus_Accepted;
  14911. }
  14912. }
  14913. else
  14914. {
  14915. isSuccess = ConfigurationStatus_Rejected;
  14916. }
  14917. }
  14918. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14919. {
  14920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14921. {
  14922. check_ascii = value[0];
  14923. if( (check_ascii < 48) || (check_ascii > 57) )
  14924. {
  14925. isSuccess = ConfigurationStatus_Rejected;
  14926. }
  14927. else
  14928. {
  14929. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14931. TransactionMessageRetryIntervalValue = atoi(value);
  14932. isSuccess = ConfigurationStatus_Accepted;
  14933. }
  14934. }
  14935. else
  14936. {
  14937. isSuccess = ConfigurationStatus_Rejected;
  14938. }
  14939. }
  14940. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14941. {
  14942. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14943. {
  14944. strcpy(str, (const char*)value);
  14945. for(int i = 0; str[i]; i++)
  14946. {
  14947. str[i] = tolower(str[i]);
  14948. }
  14949. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14951. isSuccess = ConfigurationStatus_Accepted;
  14952. }
  14953. else
  14954. {
  14955. isSuccess = ConfigurationStatus_Rejected;
  14956. }
  14957. }
  14958. if(strcmp(key, "WebSocketPingInterval") == 0)
  14959. {
  14960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14961. {
  14962. check_ascii = value[0];
  14963. if( (check_ascii < 48) || (check_ascii > 57) )
  14964. {
  14965. isSuccess = ConfigurationStatus_Rejected;
  14966. }
  14967. else
  14968. {
  14969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14970. isSuccess = ConfigurationStatus_Accepted;
  14971. }
  14972. }
  14973. else
  14974. {
  14975. isSuccess = ConfigurationStatus_Rejected;
  14976. }
  14977. }
  14978. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14979. {
  14980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14981. {
  14982. strcpy(str, (const char*)value);
  14983. for(int i = 0; str[i]; i++)
  14984. {
  14985. str[i] = tolower(str[i]);
  14986. }
  14987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14988. isSuccess = ConfigurationStatus_Accepted;
  14989. }
  14990. else
  14991. {
  14992. isSuccess = ConfigurationStatus_Rejected;
  14993. }
  14994. }
  14995. if(strcmp(key, "AuthorizationKey") == 0)
  14996. {
  14997. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14998. {
  14999. strcpy(str, (const char*)value);
  15000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15001. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15002. isSuccess = ConfigurationStatus_Accepted;
  15003. }
  15004. else
  15005. {
  15006. isSuccess = ConfigurationStatus_Rejected;
  15007. }
  15008. }
  15009. if(strcmp(key, "SecurityProfile") == 0)
  15010. {
  15011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15012. {
  15013. check_ascii = value[0];
  15014. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15015. {
  15016. isSuccess = ConfigurationStatus_Rejected;
  15017. }
  15018. else if(check_ascii == 0x33)
  15019. {
  15020. isSuccess = NotSupported;
  15021. }
  15022. else
  15023. {
  15024. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15025. {
  15026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15027. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15028. isSuccess = ConfigurationStatus_Accepted;
  15029. }
  15030. else
  15031. isSuccess = ConfigurationStatus_Rejected;
  15032. }
  15033. }
  15034. else
  15035. {
  15036. isSuccess = ConfigurationStatus_Rejected;
  15037. }
  15038. }
  15039. if(strcmp(key, "DefaultPrice") == 0)
  15040. {
  15041. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15042. {
  15043. strcpy(str, (const char*)value);
  15044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15045. isSuccess = ConfigurationStatus_Accepted;
  15046. }
  15047. else
  15048. {
  15049. isSuccess = ConfigurationStatus_Rejected;
  15050. }
  15051. }
  15052. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15053. {
  15054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15055. {
  15056. strcpy(str, (const char*)value);
  15057. for(int i = 0; str[i]; i++)
  15058. {
  15059. str[i] = tolower(str[i]);
  15060. }
  15061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15062. isSuccess = ConfigurationStatus_Accepted;
  15063. }
  15064. else
  15065. {
  15066. isSuccess = ConfigurationStatus_Rejected;
  15067. }
  15068. }
  15069. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15070. {
  15071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15072. {
  15073. strcpy(str, (const char*)value);
  15074. for(int i = 0; str[i]; i++)
  15075. {
  15076. str[i] = tolower(str[i]);
  15077. }
  15078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15079. isSuccess = ConfigurationStatus_Accepted;
  15080. }
  15081. else
  15082. {
  15083. isSuccess = ConfigurationStatus_Rejected;
  15084. }
  15085. }
  15086. if(strcmp(key, "TimeOffset") == 0)
  15087. {
  15088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15089. {
  15090. strcpy(str, (const char*)value);
  15091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15092. isSuccess = ConfigurationStatus_Accepted;
  15093. }
  15094. else
  15095. {
  15096. isSuccess = ConfigurationStatus_Rejected;
  15097. }
  15098. }
  15099. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15100. {
  15101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15102. {
  15103. strcpy(str, (const char*)value);
  15104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15105. isSuccess = ConfigurationStatus_Accepted;
  15106. }
  15107. else
  15108. {
  15109. isSuccess = ConfigurationStatus_Rejected;
  15110. }
  15111. }
  15112. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15113. {
  15114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15115. {
  15116. strcpy(str, (const char*)value);
  15117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15118. isSuccess = ConfigurationStatus_Accepted;
  15119. }
  15120. else
  15121. {
  15122. isSuccess = ConfigurationStatus_Rejected;
  15123. }
  15124. }
  15125. #if 0
  15126. //For OCPP Test Case
  15127. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15128. {
  15129. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15130. {
  15131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  15132. isSuccess = ConfigurationStatus_Accepted;
  15133. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15134. }
  15135. else
  15136. {
  15137. isSuccess = ConfigurationStatus_Rejected;
  15138. }
  15139. }
  15140. #endif
  15141. #if 1
  15142. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15143. {
  15144. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15145. {
  15146. strcpy(str, (const char*)value);
  15147. for(int i = 0; str[i]; i++)
  15148. {
  15149. str[i] = tolower(str[i]);
  15150. }
  15151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15152. isSuccess = ConfigurationStatus_Accepted;
  15153. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15154. }
  15155. else
  15156. {
  15157. isSuccess = ConfigurationStatus_Rejected;
  15158. }
  15159. }
  15160. #endif
  15161. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15162. {
  15163. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15164. {
  15165. check_ascii = value[0];
  15166. if( (check_ascii < 48) || (check_ascii > 57) )
  15167. {
  15168. isSuccess = ConfigurationStatus_Rejected;
  15169. }
  15170. else
  15171. {
  15172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15173. isSuccess = ConfigurationStatus_Accepted;
  15174. }
  15175. }
  15176. else
  15177. {
  15178. isSuccess = ConfigurationStatus_Rejected;
  15179. }
  15180. }
  15181. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15182. {
  15183. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15184. {
  15185. check_ascii = value[0];
  15186. if( (check_ascii < 48) || (check_ascii > 57) )
  15187. {
  15188. isSuccess = ConfigurationStatus_Rejected;
  15189. }
  15190. else
  15191. {
  15192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15193. isSuccess = ConfigurationStatus_Accepted;
  15194. }
  15195. }
  15196. else
  15197. {
  15198. isSuccess = ConfigurationStatus_Rejected;
  15199. }
  15200. }
  15201. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15202. {
  15203. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15204. {
  15205. strcpy(str, (const char*)value);
  15206. for(int i = 0; str[i]; i++)
  15207. {
  15208. str[i] = tolower(str[i]);
  15209. }
  15210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15211. isSuccess = ConfigurationStatus_Accepted;
  15212. }
  15213. else
  15214. {
  15215. isSuccess = ConfigurationStatus_Rejected;
  15216. }
  15217. }
  15218. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15219. {
  15220. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15221. {
  15222. check_ascii = value[0];
  15223. if( (check_ascii < 48) || (check_ascii > 57) )
  15224. {
  15225. isSuccess = ConfigurationStatus_Rejected;
  15226. }
  15227. else
  15228. {
  15229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15230. isSuccess = ConfigurationStatus_Accepted;
  15231. }
  15232. }
  15233. else
  15234. {
  15235. isSuccess = ConfigurationStatus_Rejected;
  15236. }
  15237. }
  15238. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15239. {
  15240. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15241. {
  15242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15243. isSuccess = ConfigurationStatus_Accepted;
  15244. }
  15245. else
  15246. {
  15247. isSuccess = ConfigurationStatus_Rejected;
  15248. }
  15249. }
  15250. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15251. {
  15252. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15253. {
  15254. check_ascii = value[0];
  15255. if( (check_ascii < 48) || (check_ascii > 57) )
  15256. {
  15257. isSuccess = ConfigurationStatus_Rejected;
  15258. }
  15259. else
  15260. {
  15261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15262. isSuccess = ConfigurationStatus_Accepted;
  15263. }
  15264. }
  15265. else
  15266. {
  15267. isSuccess = ConfigurationStatus_Rejected;
  15268. }
  15269. }
  15270. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15271. {
  15272. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15273. {
  15274. strcpy(str, (const char*)value);
  15275. for(int i = 0; str[i]; i++)
  15276. {
  15277. str[i] = tolower(str[i]);
  15278. }
  15279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15280. isSuccess = ConfigurationStatus_Accepted;
  15281. }
  15282. else
  15283. {
  15284. isSuccess = ConfigurationStatus_Rejected;
  15285. }
  15286. }
  15287. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15288. {
  15289. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15290. {
  15291. check_ascii = value[0];
  15292. if( (check_ascii < 48) || (check_ascii > 57) )
  15293. {
  15294. isSuccess = ConfigurationStatus_Rejected;
  15295. }
  15296. else
  15297. {
  15298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15299. isSuccess = ConfigurationStatus_Accepted;
  15300. }
  15301. }
  15302. else
  15303. {
  15304. isSuccess = ConfigurationStatus_Rejected;
  15305. }
  15306. }
  15307. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15308. return isSuccess;
  15309. }
  15310. int TransactionMessageAttemptsGet(void)
  15311. {
  15312. return TransactionMessageAttemptsValue;
  15313. }
  15314. int FirstHeartBeatResponse(void)
  15315. {
  15316. return FirstHeartBeat;
  15317. }
  15318. int TransactionMessageRetryIntervalGet(void)
  15319. {
  15320. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15321. }
  15322. int ReadHttpStatus(int sock)
  15323. {
  15324. //char c;
  15325. char buff[1024]="",*ptr=buff+1;
  15326. int bytes_received, status;
  15327. DEBUG_INFO("Begin Response ..\n");
  15328. while((bytes_received = recv(sock, ptr, 1, 0))){
  15329. if(bytes_received==-1){
  15330. perror("ReadHttpStatus");
  15331. exit(1);
  15332. }
  15333. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15334. ptr++;
  15335. }
  15336. *ptr=0;
  15337. ptr=buff+1;
  15338. sscanf(ptr,"%*s %d ", &status);
  15339. DEBUG_INFO("%s\n",ptr);
  15340. DEBUG_INFO("status=%d\n",status);
  15341. DEBUG_INFO("End Response ..\n");
  15342. return (bytes_received>0)?status:0;
  15343. }
  15344. //the only filed that it parsed is 'Content-Length'
  15345. int ParseHeader(int sock)
  15346. {
  15347. //char c;
  15348. char buff[1024]="",*ptr=buff+4;
  15349. int bytes_received;
  15350. DEBUG_INFO("Begin HEADER ..\n");
  15351. while((bytes_received = recv(sock, ptr, 1, 0))){
  15352. if(bytes_received==-1){
  15353. perror("Parse Header");
  15354. exit(1);
  15355. }
  15356. if(
  15357. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15358. (ptr[-1]=='\r') && (*ptr=='\n' )
  15359. ) break;
  15360. ptr++;
  15361. }
  15362. *ptr=0;
  15363. ptr=buff+4;
  15364. //printf("%s",ptr);
  15365. if(bytes_received){
  15366. ptr=strstr(ptr,"Content-Length:");
  15367. if(ptr){
  15368. sscanf(ptr,"%*s %d",&bytes_received);
  15369. }else
  15370. bytes_received=-1; //unknown size
  15371. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15372. }
  15373. DEBUG_INFO("End HEADER ..\n");
  15374. return bytes_received ;
  15375. }
  15376. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15377. {
  15378. int result = TRUE;
  15379. char rmFileCmd[100]={0};
  15380. char FilePath[100]={0};
  15381. char ftpbuf[200];
  15382. int systemresult;
  15383. sprintf(FilePath,"/mnt/%s",filename);
  15384. system("ping 8.8.8.8 &");
  15385. if((access(FilePath,F_OK))!=-1)
  15386. {
  15387. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15388. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15389. system(rmFileCmd);
  15390. }
  15391. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15392. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15393. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15394. systemresult = system(ftpbuf);
  15395. if(systemresult != 0)
  15396. {
  15397. DEBUG_INFO("http DownLoad error!\n");
  15398. result = FALSE;
  15399. }
  15400. system("pkill ping");
  15401. return result;
  15402. }
  15403. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15404. {
  15405. int result = TRUE;
  15406. char rmFileCmd[100]={0};
  15407. char FilePath[100]={0};
  15408. char ftpbuf[200];
  15409. int systemresult;
  15410. sprintf(FilePath,"/mnt/%s",filename);
  15411. system("ping 8.8.8.8 &");
  15412. if((access(FilePath,F_OK))!=-1)
  15413. {
  15414. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15415. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15416. system(rmFileCmd);
  15417. }
  15418. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15419. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15420. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15421. systemresult = system(ftpbuf);
  15422. if(systemresult != 0)
  15423. {
  15424. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15425. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15426. systemresult = system(ftpbuf);
  15427. if(systemresult != 0)
  15428. {
  15429. DEBUG_WARN("wget error!\n");
  15430. result = FALSE;
  15431. }
  15432. }
  15433. system("pkill ping");
  15434. return result;
  15435. }
  15436. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15437. {
  15438. char rmFileCmd[100]={0};
  15439. char FilePath[100]={0};
  15440. char buf[512];
  15441. int systemresult = 0;
  15442. //DEBUG_INFO("filename=%s\n",filename);
  15443. //DEBUG_INFO("url=%s\n",url);
  15444. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15445. if((access(FilePath,F_OK))!=-1)
  15446. {
  15447. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15448. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15449. system(rmFileCmd);
  15450. }
  15451. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15452. if(fp == NULL)
  15453. {
  15454. DEBUG_INFO("log is NULL\n");
  15455. return FALSE;
  15456. }
  15457. else
  15458. {
  15459. fprintf(fp, "%s\n", url);
  15460. fprintf(fp, "%s\n", filename);
  15461. fclose(fp);
  15462. }
  15463. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15464. if(phpFP == NULL)
  15465. {
  15466. DEBUG_INFO("PHP upload fail.\n");
  15467. return FALSE;
  15468. }
  15469. else
  15470. {
  15471. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15472. {
  15473. if(strstr(buf, "result") != NULL)
  15474. {
  15475. sscanf(buf, "result: %d", &systemresult);
  15476. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15477. }
  15478. }
  15479. pclose(phpFP);
  15480. }
  15481. if(systemresult != 1)
  15482. {
  15483. DEBUG_INFO("HTTP upload error!\n");
  15484. return FALSE;
  15485. }
  15486. return TRUE;
  15487. }
  15488. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15489. {
  15490. struct hostent* server;
  15491. char *IPbuffer;
  15492. char ftpbuf[200];
  15493. int systemresult;
  15494. // To retrieve host information
  15495. server = gethostbyname(location);
  15496. // To convert an Internet network
  15497. // address into ASCII string
  15498. IPbuffer = inet_ntoa(*((struct in_addr*)
  15499. server->h_addr_list[0]));
  15500. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15501. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15502. /* format : ftpput -u username -p passwd IP target source*/
  15503. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15504. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15505. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15506. systemresult = system(ftpbuf);
  15507. DEBUG_INFO("systemresult=%d\n",systemresult);
  15508. if(systemresult != 0)
  15509. {
  15510. DEBUG_INFO("ftpput error!\n");
  15511. return FALSE;
  15512. }
  15513. return TRUE;
  15514. }
  15515. int GetOcppServerURL()
  15516. {
  15517. int result = FALSE;
  15518. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15519. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15520. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15521. struct yuarel url;
  15522. char urlStr[512];
  15523. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15524. {
  15525. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15526. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15527. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15528. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15529. if(yuarel_parse(&url, urlStr) != -1)
  15530. {
  15531. sprintf(OcppProtocol, "%s", url.scheme);
  15532. sprintf(OcppHost, "%s", url.host);
  15533. if(url.path == NULL)
  15534. OcppTempPath[0] = '\0';
  15535. else
  15536. {
  15537. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15538. {
  15539. sprintf(OcppTempPath, "%s/", url.path);
  15540. }
  15541. else
  15542. {
  15543. sprintf(OcppTempPath, "%s", url.path);
  15544. }
  15545. }
  15546. if(url.port == 0)
  15547. {
  15548. if(strcmp(OcppProtocol, "wss") == 0)
  15549. OcppPort = 443;
  15550. else
  15551. OcppPort = 80;
  15552. }
  15553. else
  15554. OcppPort = url.port;
  15555. result = TRUE;
  15556. }
  15557. }
  15558. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15559. {
  15560. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15561. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15562. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15563. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15564. if(yuarel_parse(&url, urlStr) != -1)
  15565. {
  15566. sprintf(OcppProtocol, "%s", url.scheme);
  15567. sprintf(OcppHost, "%s", url.host);
  15568. if(url.path == NULL)
  15569. OcppTempPath[0] = '\0';
  15570. else
  15571. sprintf(OcppTempPath, "%s", url.path);
  15572. if(url.port == 0)
  15573. {
  15574. if(strcmp(OcppProtocol, "wss") == 0)
  15575. OcppPort = 443;
  15576. else
  15577. OcppPort = 80;
  15578. }
  15579. else
  15580. OcppPort = url.port;
  15581. result = TRUE;
  15582. }
  15583. }
  15584. else
  15585. {
  15586. strcpy(OcppHost,"");
  15587. }
  15588. return result;
  15589. }
  15590. int GetOcppPath()
  15591. {
  15592. int result = FALSE;
  15593. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15594. {
  15595. if(OcppTempPath == NULL)
  15596. {
  15597. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15598. }
  15599. else
  15600. {
  15601. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15602. }
  15603. result = TRUE;
  15604. goto End;
  15605. }
  15606. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15607. {
  15608. if(OcppTempPath == NULL)
  15609. {
  15610. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15611. }
  15612. else
  15613. {
  15614. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15615. }
  15616. result = TRUE;
  15617. goto End;
  15618. }
  15619. else
  15620. {
  15621. strcpy(OcppPath,"");
  15622. }
  15623. End:
  15624. return result;
  15625. }
  15626. int GetOcppPort()
  15627. {
  15628. return OcppPort;
  15629. }
  15630. int GetOcppConnStatus(void)
  15631. {
  15632. return ShmOCPP16Data->OcppConnStatus;
  15633. }
  15634. void SetOcppConnStatus(uint8_t status)
  15635. {
  15636. ShmOCPP16Data->OcppConnStatus = status;
  15637. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15638. }
  15639. int GetHeartBeatWithNOResponse(void)
  15640. {
  15641. return HeartBeatWithNOResponse;
  15642. }
  15643. void SetHeartBeatWithNOResponse(void)
  15644. {
  15645. HeartBeatWithNOResponse = 0;
  15646. }
  15647. void GetStartTransactionIdTag(int gun_index)
  15648. {
  15649. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15650. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15651. }
  15652. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15653. {
  15654. char ch;
  15655. FILE *fptr1;
  15656. int temptransactionId;
  15657. char str[100]={0};
  15658. temptransactionId = 0;
  15659. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15660. {
  15661. DEBUG_INFO("IdTag is empty.\n");
  15662. return temptransactionId;
  15663. }
  15664. /*------ Read the file ----------------*/
  15665. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15666. if (!fptr1)
  15667. {
  15668. DEBUG_INFO("QueueTransactionId file open error.\n");
  15669. //printf(" File not found or unable to open the input file!!\n");
  15670. return temptransactionId;
  15671. }
  15672. ch=fgetc(fptr1);
  15673. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15674. rewind(fptr1);
  15675. if(ch!=EOF)
  15676. {
  15677. // printf("%c",ch);
  15678. while (fgets(str, 100, fptr1) != NULL)
  15679. {
  15680. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15681. if(str[0]=='\0')
  15682. {
  15683. break;
  15684. }
  15685. char *revbuf[8] = {0}; // Variable store string split
  15686. int num = 0;// Quantity after string split
  15687. DEBUG_INFO("Transaction queue data= %s\n", str);
  15688. splitstring(str,",",revbuf,&num); // String split
  15689. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15690. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15691. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15692. DEBUG_INFO("------------------------------\n");
  15693. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15694. {
  15695. if(isStopTransaction)
  15696. {
  15697. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15698. {
  15699. temptransactionId = atoi(revbuf[2]);
  15700. //break;
  15701. }
  15702. }
  15703. else
  15704. {
  15705. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15706. {
  15707. temptransactionId = atoi(revbuf[2]);
  15708. //break;
  15709. }
  15710. }
  15711. }
  15712. }
  15713. }
  15714. else
  15715. DEBUG_INFO("EOF\n");
  15716. fclose(fptr1);
  15717. /*------- End of reading ---------------*/
  15718. return temptransactionId;
  15719. }
  15720. void SetTransactionIdZero(int transactionId)
  15721. {
  15722. char ch;
  15723. FILE *fptr1, *fptr2;
  15724. int temptransactionId = 0;
  15725. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15726. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15727. if (!fptr1)
  15728. {
  15729. //printf(" File not found or unable to open the input file!!\n");
  15730. return ;
  15731. }
  15732. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15733. if (!fptr2)
  15734. {
  15735. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15736. fclose(fptr1);
  15737. return ;
  15738. }
  15739. ch=fgetc(fptr1);
  15740. rewind(fptr1);
  15741. if(ch!=EOF)
  15742. {
  15743. // copy all contents to the temporary file except the specific line
  15744. while (fgets(str, 100, fptr1) != NULL)
  15745. {
  15746. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15747. if(str[0]=='\0')
  15748. {
  15749. break;
  15750. }
  15751. char *revbuf[8] = {0};
  15752. int num = 0;
  15753. strcpy(strtemp, str);
  15754. splitstring(str,",",revbuf,&num);
  15755. if(revbuf[2][0] != '\0')
  15756. {
  15757. temptransactionId = atoi(revbuf[2]);
  15758. if(transactionId != temptransactionId)
  15759. {
  15760. fprintf(fptr2, "%s\n", strtemp);
  15761. }
  15762. }
  15763. }
  15764. }
  15765. fclose(fptr1);
  15766. fclose(fptr2);
  15767. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15768. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15769. /*------ Read the file ----------------*/
  15770. }
  15771. int InternetDisconnect(void)
  15772. {
  15773. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15774. }
  15775. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15776. void storeTempStopTransaction(int gun_index)
  15777. {
  15778. char guid[37]={0};
  15779. int tempIndex = 0;
  15780. char TempStopTransaction[256];
  15781. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15782. DEBUG_INFO("storeTempStopTransaction...\n");
  15783. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15784. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15785. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15786. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15787. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15788. {
  15789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15790. {
  15791. tempIndex = ((gun_index==2) ? 1: 0);
  15792. }
  15793. else
  15794. {
  15795. tempIndex = gun_index;
  15796. }
  15797. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15798. {
  15799. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15800. {
  15801. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15802. }
  15803. }// END OF CHAdeMO_QUANTITY
  15804. }
  15805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15806. {
  15807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15808. {
  15809. tempIndex = ((gun_index==2) ? 1: 0);
  15810. }
  15811. else
  15812. {
  15813. tempIndex = gun_index;
  15814. }
  15815. for (int index = 0; index < CCS_QUANTITY; index++)
  15816. {
  15817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15818. {
  15819. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15820. }
  15821. }// END OF CCS_QUANTITY
  15822. }
  15823. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15824. {
  15825. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15826. {
  15827. tempIndex = ((gun_index==2) ? 1: 0);
  15828. }
  15829. else
  15830. {
  15831. tempIndex = gun_index;
  15832. }
  15833. for (int index = 0; index < GB_QUANTITY; index++)
  15834. {
  15835. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15836. {
  15837. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15838. }
  15839. }// END OF GB_QUANTITY
  15840. }
  15841. else if(gunType[gun_index] == GUN_TYPE_DO)
  15842. {
  15843. tempIndex = gun_index;
  15844. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15845. {
  15846. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15847. {
  15848. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15849. }
  15850. }
  15851. }
  15852. else
  15853. {
  15854. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15855. {
  15856. tempIndex = 2;
  15857. }
  15858. else
  15859. {
  15860. tempIndex = gun_index;
  15861. }
  15862. for (int index = 0; index < AC_QUANTITY; index++)
  15863. {
  15864. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15865. {
  15866. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15867. }
  15868. }// END OF AC_QUANTITY
  15869. }
  15870. //Stop Transaction Time
  15871. struct timeval tmnow;
  15872. struct tm *tm;
  15873. char buf[28];//, usec_buf[6];
  15874. gettimeofday(&tmnow, NULL);
  15875. time_t t;
  15876. t = time(NULL);
  15877. /*UTC time and date*/
  15878. tm = gmtime(&t);
  15879. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15881. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15883. random_uuid(guid);
  15884. /***********************************transactionData******************************************************/
  15885. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15887. //=================================
  15888. //1. Transaction_Begin
  15889. //=================================
  15890. //============================== Energy.Active.Import.Interval ===========================================
  15891. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15892. {
  15893. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15896. 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*/]);
  15897. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15898. 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))
  15899. {
  15900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15901. }
  15902. else
  15903. {
  15904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15905. }
  15906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15908. }
  15909. //=================================
  15910. //2. Transaction_End
  15911. //=================================
  15912. //2.1====================================== Current.Import L1 ==============================================
  15913. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15914. {
  15915. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15916. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15917. {
  15918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15919. {
  15920. tempIndex = ((gun_index==2) ? 1: 0);
  15921. }
  15922. else
  15923. {
  15924. tempIndex = gun_index;
  15925. }
  15926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15927. {
  15928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15929. {
  15930. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15931. }
  15932. }// End of for CHAdeMO_QUANTITY
  15933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15934. }
  15935. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15936. {
  15937. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15938. {
  15939. tempIndex = ((gun_index==2) ? 1: 0);
  15940. }
  15941. else
  15942. {
  15943. tempIndex = gun_index;
  15944. }
  15945. for (int index = 0; index < CCS_QUANTITY; index++)
  15946. {
  15947. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15948. {
  15949. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15950. }
  15951. }// End of for CCS_QUANTITY
  15952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15953. }
  15954. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15955. {
  15956. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15957. {
  15958. tempIndex = ((gun_index==2) ? 1: 0);
  15959. }
  15960. else
  15961. {
  15962. tempIndex = gun_index;
  15963. }
  15964. for (int index = 0; index < GB_QUANTITY; index++)
  15965. {
  15966. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15967. {
  15968. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15969. }
  15970. }// End of for GB_QUANTITY
  15971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15972. }
  15973. else if(gunType[gun_index] == GUN_TYPE_DO)
  15974. {
  15975. tempIndex = gun_index;
  15976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15977. {
  15978. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15979. {
  15980. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15981. }
  15982. }
  15983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15984. }
  15985. else
  15986. {
  15987. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15988. {
  15989. tempIndex = 2;
  15990. }
  15991. else
  15992. {
  15993. tempIndex = gun_index;
  15994. }
  15995. for (int index = 0; index < AC_QUANTITY; index++)
  15996. {
  15997. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15998. {
  15999. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16000. }
  16001. }// End of for AC_QUANTITY
  16002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16003. }
  16004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16007. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16010. }
  16011. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16012. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16013. {
  16014. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16015. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16016. {
  16017. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16018. {
  16019. tempIndex = ((gun_index==2) ? 1: 0);
  16020. }
  16021. else
  16022. {
  16023. tempIndex = gun_index;
  16024. }
  16025. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16026. {
  16027. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16028. {
  16029. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16030. }
  16031. }// END OF CHAdeMO_QUANTITY
  16032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16033. }
  16034. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16035. {
  16036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16037. {
  16038. tempIndex = ((gun_index==2) ? 1: 0);
  16039. }
  16040. else
  16041. {
  16042. tempIndex = gun_index;
  16043. }
  16044. for (int index = 0; index < CCS_QUANTITY; index++)
  16045. {
  16046. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16047. {
  16048. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16049. }
  16050. }// END OF CCS_QUANTITY
  16051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16052. }
  16053. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16054. {
  16055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16056. {
  16057. tempIndex = ((gun_index==2) ? 1: 0);
  16058. }
  16059. else
  16060. {
  16061. tempIndex = gun_index;
  16062. }
  16063. for (int index = 0; index < GB_QUANTITY; index++)
  16064. {
  16065. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16066. {
  16067. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16068. }
  16069. }// END OF GB_QUANTITY
  16070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16071. }
  16072. else if(gunType[gun_index] == GUN_TYPE_DO)
  16073. {
  16074. tempIndex = gun_index;
  16075. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16076. {
  16077. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16078. {
  16079. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16080. }
  16081. }
  16082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16083. }
  16084. else
  16085. {
  16086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16087. {
  16088. tempIndex = 2;
  16089. }
  16090. else
  16091. {
  16092. tempIndex = gun_index;
  16093. }
  16094. for (int index = 0; index < AC_QUANTITY; index++)
  16095. {
  16096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16097. {
  16098. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16099. }
  16100. }// END OF AC_QUANTITY
  16101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16102. }
  16103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16106. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16109. }
  16110. //2.3====================================== Power.Active.Import =========================================
  16111. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16112. {
  16113. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16114. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16115. {
  16116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16117. {
  16118. tempIndex = ((gun_index==2) ? 1: 0);
  16119. }
  16120. else
  16121. {
  16122. tempIndex = gun_index;
  16123. }
  16124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16125. {
  16126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16127. {
  16128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16129. }
  16130. } // End for CHAdeMO_QUANTITY
  16131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16132. }
  16133. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16134. {
  16135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16136. {
  16137. tempIndex = ((gun_index==2) ? 1: 0);
  16138. }
  16139. else
  16140. {
  16141. tempIndex = gun_index;
  16142. }
  16143. for (int index = 0; index < CCS_QUANTITY; index++)
  16144. {
  16145. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16146. {
  16147. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16148. }
  16149. } // END for CCS_QUANTITY
  16150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16151. }
  16152. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16153. {
  16154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16155. {
  16156. tempIndex = ((gun_index==2) ? 1: 0);
  16157. }
  16158. else
  16159. {
  16160. tempIndex = gun_index;
  16161. }
  16162. for (int index = 0; index < GB_QUANTITY; index++)
  16163. {
  16164. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16165. {
  16166. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16167. }
  16168. }// END for GB_QUANTITY
  16169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16170. }
  16171. else if(gunType[gun_index] == GUN_TYPE_DO)
  16172. {
  16173. tempIndex = gun_index;
  16174. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16175. {
  16176. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16177. {
  16178. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16179. }
  16180. }
  16181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16182. }
  16183. else
  16184. {
  16185. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16186. {
  16187. tempIndex = 2;
  16188. }
  16189. else
  16190. {
  16191. tempIndex = gun_index;
  16192. }
  16193. for (int index = 0; index < AC_QUANTITY; index++)
  16194. {
  16195. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16196. {
  16197. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16198. }
  16199. } // END for AC_QUANTITY
  16200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16201. }
  16202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16205. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16208. }
  16209. //2.4====================================== Voltage L1 ====================================================
  16210. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16211. {
  16212. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16213. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16214. {
  16215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16216. {
  16217. tempIndex = ((gun_index==2) ? 1: 0);
  16218. }
  16219. else
  16220. {
  16221. tempIndex = gun_index;
  16222. }
  16223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16224. {
  16225. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16226. {
  16227. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16228. }
  16229. } // END OF FOR CHAdeMO_QUANTITY
  16230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16231. }
  16232. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16233. {
  16234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16235. {
  16236. tempIndex = ((gun_index==2) ? 1: 0);
  16237. }
  16238. else
  16239. {
  16240. tempIndex = gun_index;
  16241. }
  16242. for (int index = 0; index < CCS_QUANTITY; index++)
  16243. {
  16244. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16245. {
  16246. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16247. }
  16248. } // END OF FOR CCS_QUANTITY
  16249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16250. }
  16251. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16252. {
  16253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16254. {
  16255. tempIndex = ((gun_index==2) ? 1: 0);
  16256. }
  16257. else
  16258. {
  16259. tempIndex = gun_index;
  16260. }
  16261. for (int index = 0; index < GB_QUANTITY; index++)
  16262. {
  16263. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16264. {
  16265. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16266. }
  16267. } // END OF FOR GB_QUANTITY
  16268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16269. }
  16270. else if(gunType[gun_index] == GUN_TYPE_DO)
  16271. {
  16272. tempIndex = gun_index;
  16273. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16274. {
  16275. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16276. {
  16277. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16278. }
  16279. }
  16280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16281. }
  16282. else
  16283. {
  16284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16285. {
  16286. tempIndex = 2;
  16287. }
  16288. else
  16289. {
  16290. tempIndex = gun_index;
  16291. }
  16292. for (int index = 0; index < AC_QUANTITY; index++)
  16293. {
  16294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16295. {
  16296. 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
  16297. }
  16298. } // END OF FOR AC_QUANTITY
  16299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16300. }
  16301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16304. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16307. }
  16308. //2.5============================================== End SoC =========================================================
  16309. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16310. {
  16311. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16312. 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))
  16313. {
  16314. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16315. {
  16316. tempIndex = ((gun_index==2) ? 1: 0);
  16317. }
  16318. else
  16319. {
  16320. tempIndex = gun_index;
  16321. }
  16322. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16323. {
  16324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16325. {
  16326. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16327. {
  16328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16329. }
  16330. }
  16331. }
  16332. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16333. {
  16334. for (int index = 0; index < CCS_QUANTITY; index++)
  16335. {
  16336. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16337. {
  16338. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16339. }
  16340. }
  16341. }
  16342. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16343. {
  16344. for (int index = 0; index < GB_QUANTITY; index++)
  16345. {
  16346. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16347. {
  16348. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16349. }
  16350. }
  16351. }
  16352. else if(gunType[gun_index] == GUN_TYPE_DO)
  16353. {
  16354. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16355. {
  16356. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16357. {
  16358. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16359. }
  16360. }
  16361. }
  16362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16368. } // END FOR DC CASE
  16369. }
  16370. //2.6====================================== Current.Import L2 ==============================================
  16371. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16372. {
  16373. // AC 3 phase L2 current
  16374. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16375. {
  16376. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16377. {
  16378. tempIndex = 2;
  16379. }
  16380. else
  16381. {
  16382. tempIndex = gun_index;
  16383. }
  16384. for (int index = 0; index < AC_QUANTITY; index++)
  16385. {
  16386. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16387. {
  16388. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16389. }
  16390. }// End of for AC_QUANTITY
  16391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16392. }
  16393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16398. }
  16399. //2.7====================================== Current.Import L3 ==============================================
  16400. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16401. {
  16402. // AC 3 phase L3 current
  16403. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16404. {
  16405. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16406. {
  16407. tempIndex = 2;
  16408. }
  16409. else
  16410. {
  16411. tempIndex = gun_index;
  16412. }
  16413. for (int index = 0; index < AC_QUANTITY; index++)
  16414. {
  16415. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16416. {
  16417. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16418. }
  16419. }// End of for AC_QUANTITY
  16420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16421. }
  16422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16427. }
  16428. //2.9====================================== Voltage L2 ====================================================
  16429. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16430. {
  16431. // AC 3 phase L2 volatge
  16432. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16433. {
  16434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16435. {
  16436. tempIndex = 2;
  16437. }
  16438. else
  16439. {
  16440. tempIndex = gun_index;
  16441. }
  16442. for (int index = 0; index < AC_QUANTITY; index++)
  16443. {
  16444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16445. {
  16446. 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
  16447. }
  16448. } // END OF FOR AC_QUANTITY
  16449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16450. }
  16451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16456. }
  16457. //2.10====================================== Voltage L3 ====================================================
  16458. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16459. {
  16460. // AC 3 phase L3 volatge
  16461. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16462. {
  16463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16464. {
  16465. tempIndex = 2;
  16466. }
  16467. else
  16468. {
  16469. tempIndex = gun_index;
  16470. }
  16471. for (int index = 0; index < AC_QUANTITY; index++)
  16472. {
  16473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16474. {
  16475. 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
  16476. }
  16477. } // END OF FOR AC_QUANTITY
  16478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16479. }
  16480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16485. }
  16486. //====================== Start SoC ================================
  16487. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16488. {
  16489. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16490. 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))
  16491. {
  16492. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16493. {
  16494. tempIndex = ((gun_index==2) ? 1: 0);
  16495. }
  16496. else
  16497. {
  16498. tempIndex = gun_index;
  16499. }
  16500. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16501. {
  16502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16503. {
  16504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16505. {
  16506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16507. }
  16508. }
  16509. }
  16510. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16511. {
  16512. for (int index = 0; index < CCS_QUANTITY; index++)
  16513. {
  16514. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16515. {
  16516. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16517. }
  16518. }
  16519. }
  16520. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16521. {
  16522. for (int index = 0; index < GB_QUANTITY; index++)
  16523. {
  16524. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16525. {
  16526. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16527. }
  16528. }
  16529. }
  16530. else if(gunType[gun_index] == GUN_TYPE_DO)
  16531. {
  16532. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16533. {
  16534. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16535. {
  16536. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16537. }
  16538. }
  16539. }
  16540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16546. } // END FOR DC CASE
  16547. }
  16548. //======================================== Message create ==============================================
  16549. json_object *StopTransaction = json_object_new_object();
  16550. json_object *transactionDatas = json_object_new_array();
  16551. json_object *sampledValues = json_object_new_array();
  16552. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16553. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16554. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16555. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16556. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16557. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16558. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16559. {
  16560. json_object *transactionData = json_object_new_object();
  16561. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16562. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16563. {
  16564. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16565. {
  16566. json_object *sampledValue = json_object_new_object();
  16567. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16568. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16569. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16570. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16571. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16572. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16573. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16574. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16575. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16576. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16577. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16578. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16579. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16580. json_object_array_add(sampledValues, sampledValue);
  16581. }
  16582. }
  16583. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16584. json_object_array_add(transactionDatas, transactionData);
  16585. }
  16586. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16587. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16588. ,MESSAGE_TYPE_CALL
  16589. ,guid
  16590. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16591. json_object_put(StopTransaction);
  16592. // Check File "TempStopTransaction" Exist
  16593. if((access(TempStopTransaction,F_OK))!=-1)
  16594. {
  16595. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16596. fclose(fopen(TempStopTransaction, "w"));
  16597. }
  16598. else
  16599. {
  16600. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16601. FILE *log = fopen(TempStopTransaction, "w+");
  16602. if(log == NULL)
  16603. {
  16604. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16605. return ;
  16606. }
  16607. else
  16608. {
  16609. fclose(log);
  16610. }
  16611. }
  16612. //Add TempStopTransaction | Update TempStopTransaction
  16613. // open file for writing
  16614. FILE *outfile;
  16615. outfile = fopen (TempStopTransaction, "a");
  16616. //DEBUG_INFO("data = %s\n", queuedata);
  16617. fputs(queuedata, outfile);
  16618. fputs("\n", outfile);
  16619. fclose (outfile);
  16620. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16621. }
  16622. void checkTempStopTransaction(int gun_index)
  16623. {
  16624. FILE *fptr1;
  16625. char ch;
  16626. char str[QUEUE_MESSAGE_LENGTH]={0};
  16627. char guid[37]={0};
  16628. char tempdata[65]={0};
  16629. char connectorStr[2]={0};
  16630. char TempStopTransaction[256];
  16631. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16632. fptr1 = fopen(TempStopTransaction, "r");
  16633. //TempStopTransaction格式: 槍號,StopTransaction封包
  16634. if (!fptr1)
  16635. {
  16636. //printf(" File not found or unable to open the input file!!\n");
  16637. return ;
  16638. }
  16639. ch=fgetc(fptr1);
  16640. //printf(" Now the content of the file %s is : \n",fname);
  16641. rewind(fptr1);
  16642. if(ch!=EOF)
  16643. {
  16644. // copy all contents to the temporary file except the specific line
  16645. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16646. {
  16647. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16648. if(str[0]=='\0')
  16649. {
  16650. break;
  16651. }
  16652. //TempStopTransaction格式: 槍號,StopTransaction封包
  16653. strncpy(connectorStr, str, 1);
  16654. if(atoi(connectorStr) != (gun_index+1))
  16655. {
  16656. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16657. fclose(fptr1);
  16658. return ;
  16659. }
  16660. //random_uuid(guid);
  16661. strncpy(guid, str+6, 36); //copy guid
  16662. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16663. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16664. {
  16665. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16666. }
  16667. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16668. OCPP_insert_transaction_msg(NO, str);
  16669. memset(str,0,ARRAY_SIZE(str));
  16670. }
  16671. }
  16672. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16673. fclose(fptr1);
  16674. remove(TempStopTransaction); // remove the original file
  16675. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16676. }
  16677. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16678. {
  16679. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16680. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16681. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16682. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16683. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16684. }
  16685. int GetWebSocketPingInterval(void)
  16686. {
  16687. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16688. }
  16689. int GetServerSign(void)
  16690. {
  16691. return server_sign;
  16692. }
  16693. uint8_t GetOcppSecurityProfile()
  16694. {
  16695. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16696. }
  16697. void GetOcppChargerBoxId(uint8_t *data)
  16698. {
  16699. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16700. }
  16701. void GetOcppSecurityPassword(uint8_t *data)
  16702. {
  16703. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16704. }
  16705. void SetOcppVersion(uint8_t *version)
  16706. {
  16707. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16708. DEBUG_INFO("ocpp version: %s\n", version);
  16709. if(strstr((char*)version, "ocpp1.6") != NULL)
  16710. {
  16711. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16712. }
  16713. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16714. {
  16715. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16716. system("pkill OcppBackend");
  16717. }
  16718. }
  16719. void SetServerSign(int value)
  16720. {
  16721. server_sign = value;
  16722. }
  16723. int GetBootNotificationInterval(void)
  16724. {
  16725. return BootNotificationInterval;
  16726. }
  16727. int GetInternetConn(void)
  16728. {
  16729. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16730. }
  16731. int GetBackendConnectionTimeout(void)
  16732. {
  16733. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16734. }
  16735. int isConnectorInitMode(int gun_index)
  16736. {
  16737. int tempIndex = 0;
  16738. int result = TRUE;
  16739. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16740. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16741. {
  16742. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16743. {
  16744. tempIndex = ((gun_index==2) ? 1: 0);
  16745. }
  16746. else
  16747. {
  16748. tempIndex = gun_index;
  16749. }
  16750. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16751. {
  16752. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16753. {
  16754. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16755. } //end of the same index
  16756. }//end of for CHAdeMO_QUANTITY
  16757. }
  16758. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16759. {
  16760. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16761. {
  16762. tempIndex = ((gun_index==2) ? 1: 0);
  16763. }
  16764. else
  16765. {
  16766. tempIndex = gun_index;
  16767. }
  16768. for (int index = 0; index < CCS_QUANTITY; index++)
  16769. {
  16770. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16771. {
  16772. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16773. } //end of the same index
  16774. } // end of for CCS_QUANTITY
  16775. }
  16776. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16777. {
  16778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16779. {
  16780. tempIndex = ((gun_index==2) ? 1: 0);
  16781. }
  16782. else
  16783. {
  16784. tempIndex = gun_index;
  16785. }
  16786. for (int index = 0; index < GB_QUANTITY; index++)
  16787. {
  16788. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16789. {
  16790. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16791. } //end of the same index
  16792. } // end of for GB_QUANTITY
  16793. }
  16794. else if(gunType[gun_index] == GUN_TYPE_DO)
  16795. {
  16796. tempIndex = gun_index;
  16797. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16798. {
  16799. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16800. {
  16801. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16802. } //end of the same index
  16803. }
  16804. }
  16805. else
  16806. {
  16807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16808. {
  16809. tempIndex = 2;
  16810. }
  16811. else
  16812. {
  16813. tempIndex = gun_index;
  16814. }
  16815. for (int index = 0; index < AC_QUANTITY; index++)
  16816. {
  16817. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16818. {
  16819. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16820. }//end of the same index
  16821. }//end of for AC_QUANTITY
  16822. }
  16823. return result;
  16824. }
  16825. void refreshProcDogTimer()
  16826. {
  16827. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16828. }
  16829. void InitialSystemValue(void)
  16830. {
  16831. int connectorIndex = 0;
  16832. //int valueASCII = 0;
  16833. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16834. gunTotalNumber=0;
  16835. SystemInitial = 0;
  16836. locallistVersion=0;
  16837. BootNotificationInterval = 0;
  16838. authorizeRetryTimes = 0;
  16839. GunStatusInterval = 10;
  16840. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16841. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16842. //Hear Beat
  16843. HeartBeatWithNOResponse = 0;
  16844. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16845. FirstHeartBeat = 0;
  16846. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16847. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16848. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16849. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16850. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16851. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16852. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16853. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16854. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16855. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16856. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16857. memset(gunType, 0, ARRAY_SIZE(gunType));
  16858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16859. {
  16860. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16861. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16862. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16863. {
  16864. // DO series
  16865. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16866. {
  16867. SystemInitial = SystemInitial + 1;
  16868. gunTotalNumber = gunTotalNumber + 1;
  16869. gunType[connectorIndex] = GUN_TYPE_DO;
  16870. connectorIndex = connectorIndex + 1;
  16871. }
  16872. }
  16873. else
  16874. {
  16875. // DM, DW, DS series
  16876. //check connector / socket type (index: 8, 9, 10)
  16877. for(int index=7; index <10 ; index++)
  16878. {
  16879. if(index != 8)
  16880. {
  16881. // DC Connector
  16882. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16883. {
  16884. SystemInitial = SystemInitial + 1;
  16885. gunTotalNumber = gunTotalNumber + 1;
  16886. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16887. connectorIndex = connectorIndex + 1;
  16888. }
  16889. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16890. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16891. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16892. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16893. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16894. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16895. {
  16896. SystemInitial = SystemInitial + 1;
  16897. gunTotalNumber = gunTotalNumber + 1;
  16898. gunType[connectorIndex] = GUN_TYPE_CCS;
  16899. connectorIndex = connectorIndex + 1;
  16900. }
  16901. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16902. {
  16903. SystemInitial = SystemInitial + 1;
  16904. gunTotalNumber = gunTotalNumber + 1;
  16905. gunType[connectorIndex] = GUN_TYPE_GBT;
  16906. connectorIndex = connectorIndex + 1;
  16907. }
  16908. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16909. {
  16910. SystemInitial = SystemInitial + 1;
  16911. gunTotalNumber = gunTotalNumber + 1;
  16912. gunType[connectorIndex] = GUN_TYPE_DO;
  16913. connectorIndex = connectorIndex + 1;
  16914. }
  16915. }
  16916. else
  16917. {
  16918. // AC Connector
  16919. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16920. {
  16921. SystemInitial = SystemInitial + 1;
  16922. gunTotalNumber = gunTotalNumber + 1;
  16923. gunType[connectorIndex] = GUN_TYPE_AC;
  16924. connectorIndex = connectorIndex + 1;
  16925. }
  16926. }
  16927. }
  16928. }
  16929. //DEBUG_INFO("DC ...\n");
  16930. }
  16931. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16932. {
  16933. //check connector / socket type (index: 8, 9, 10)
  16934. for(int index=7; index <10 ; index++)
  16935. {
  16936. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16937. {
  16938. SystemInitial = SystemInitial + 1;
  16939. gunTotalNumber = gunTotalNumber + 1;
  16940. gunType[connectorIndex] = GUN_TYPE_AC;
  16941. connectorIndex = connectorIndex + 1;
  16942. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16943. }
  16944. }
  16945. }
  16946. //Status && ConnectorPlugIn Setting
  16947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16948. {
  16949. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16950. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16951. }
  16952. for (int index = 0; index < CCS_QUANTITY; index++)
  16953. {
  16954. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16955. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16956. }
  16957. for (int index = 0; index < GB_QUANTITY; index++)
  16958. {
  16959. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16960. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16961. }
  16962. for (int index = 0; index < AC_QUANTITY; index++)
  16963. {
  16964. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16965. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16966. }
  16967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16968. {
  16969. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16970. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16971. }
  16972. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16973. {
  16974. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16975. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16976. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16977. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16978. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16979. }
  16980. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16981. clientTime.Heartbeat=time((time_t*)NULL);
  16982. sleep(1);
  16983. }
  16984. void LWS_Send(char *str)
  16985. {
  16986. //=====================================================
  16987. // Check InternetConn 0: disconnected, 1: connected
  16988. //====================================================
  16989. if(GetOcppConnStatus() == 0)
  16990. {
  16991. DEBUG_INFO("offline now !!!\n");
  16992. return;
  16993. }
  16994. // Only disable isWebsocketSendable operation initiated by charger
  16995. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16996. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16997. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16998. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16999. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17000. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17001. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17002. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17003. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17004. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17005. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17006. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17007. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17008. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17009. {
  17010. isWebsocketSendable = 0;
  17011. }
  17012. pthread_mutex_lock(&lock_send);
  17013. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17014. sprintf((char *)SendBuffer, "%s", str);
  17015. SendBufLen = strlen(str);
  17016. pthread_mutex_unlock(&lock_send);
  17017. lws_callback_on_writable(wsi_client);
  17018. //lws_service(context, 0);
  17019. //sleep(1);
  17020. }
  17021. void LWS_SendNow(char *str)
  17022. {
  17023. //=====================================================
  17024. // Check InternetConn 0: disconnected, 1: connected
  17025. //====================================================
  17026. if(GetOcppConnStatus() == 0)
  17027. {
  17028. DEBUG_INFO("offline now !!!\n");
  17029. return;
  17030. }
  17031. // Only disable isWebsocketSendable operation initiated by charger
  17032. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17033. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17034. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17035. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17036. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17037. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17038. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17039. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17040. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17041. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17042. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17043. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17044. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17045. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17046. {
  17047. isWebsocketSendable = 0;
  17048. }
  17049. pthread_mutex_lock(&lock_send);
  17050. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17051. sprintf((char *)SendBuffer, "%s", str);
  17052. SendBufLen = strlen(str);
  17053. pthread_mutex_unlock(&lock_send);
  17054. lws_callback_on_writable(wsi_client);
  17055. lws_service(context, 0);
  17056. //sleep(1);
  17057. }